在linux上如何设置keepalived服务开机自启
时间: 2023-12-10 14:41:33 浏览: 358
要在Linux上设置keepalived服务开机自启动,可以按照以下步骤操作:
1. 打开终端并以管理员身份登录。
2. 编辑keepalived的启动脚本,使用命令:
```
sudo vi /etc/init.d/keepalived
```
3. 在脚本文件中添加以下内容:
```
#! /bin/sh
# chkconfig: 2345 90 60
# description: Keepalived is a routing software written in C.
case "$1" in
start)
/usr/sbin/keepalived
;;
stop)
killall keepalived
;;
restart)
killall keepalived
/usr/sbin/keepalived
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit 0
```
4. 保存并退出文件。
5. 设置文件可执行权限,使用命令:
```
sudo chmod +x /etc/init.d/keepalived
```
6. 将keepalived服务添加到系统服务中,使用命令:
```
sudo chkconfig --add keepalived
```
7. 启用keepalived服务开机自启动,使用命令:
```
sudo chkconfig keepalived on
```
现在,每次系统启动时,keepalived服务都会自动启动。
阅读全文