安装完keepalived后设置为服务自启动
将路径为/usr/local/src/keepalived-1.3.4/keepalived/etc/init.d的文件keepalived拷贝到/etc/init.d下
cp /usr/local/src/keepalived-1.3.4/keepalived/etc/init.d/keepalived /etc/init.d/
将路径为/usr/local/keepalived-1.3.4/etc/sysconfig/keepalived的文件拷贝到 /etc/sysconfig/keepalived
cp /usr/local/keepavlied-1.3.4/etc/sysconfig/keepalived /etc/sysconfig/
添加执行权限
chmod +x /etc/init.d/keepalived
添加keepalived到系统服务
chkconfig --add keepalived
启动
[root@localhost ~]# service keepalived start Starting keepalived (via systemctl): Job for keepalived.service failed because the control process exited with error code. See "systemctl status keepalived.service" and "journalctl -xe" for details. [失败]
报错,启动失败,用status查看具体原因
[root@localhost ~]# systemctl status keepalived ● keepalived.service - LVS and VRRP High Availability Monitor Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled) Active: failed (Result: exit-code) since 四 2019-04-25 14:25:01 CST; 24s ago Process: 17642 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=203/EXEC) 4月 25 14:25:01 localhost.localdomain systemd[1]: Starting LVS and VRRP High Availability Monitor... 4月 25 14:25:01 localhost.localdomain systemd[1]: keepalived.service: control process exited, code=ex...203 4月 25 14:25:01 localhost.localdomain systemd[1]: Failed to start LVS and VRRP High Availability Monitor. 4月 25 14:25:01 localhost.localdomain systemd[1]: Unit keepalived.service entered failed state. 4月 25 14:25:01 localhost.localdomain systemd[1]: keepalived.service failed. Hint: Some lines were ellipsized, use -l to show in full.
提示:ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=203/EXEC)
查看ll /usr/sbin/keepalived 文件不存在,此时有两种方法解决
1、复制一个keepalived到/usr/sbin/ 下
2、修改 /lib/systemd/system/keepalived.service文件,将 /usr/sbin/路径改成我们存放keepalived文件的路径
[root@localhost ~]# vi /lib/systemd/system/keepalived.service [Unit] Description=LVS and VRRP High Availability Monitor After=syslog.target network-online.target [Service] Type=forking PIDFile=/var/run/keepalived.pid KillMode=process EnvironmentFile=-/etc/sysconfig/keepalived ExecStart=/usr/local/bin/keepalived $KEEPALIVED_OPTIONS ExecReload=/bin/kill -HUP $MAINPID [Install]
3、生效
systemctl daemon-reload
4、再启动
[root@localhost keepalived-1.3.4]# systemctl start keepalived [root@localhost keepalived-1.3.4]# systemctl status keepalived ● keepalived.service - LVS and VRRP High Availability Monitor Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled) Active: active (running) since 四 2019-04-25 14:30:01 CST; 2s ago Process: 17691 ExecStart=/usr/local/bin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS) Main PID: 17692 (keepalived) CGroup: /system.slice/keepalived.service ├─17692 /usr/local/bin/keepalived -D ├─17693 /usr/local/bin/keepalived -D └─17694 /usr/local/bin/keepalived -D 4月 25 14:30:02 localhost.localdomain Keepalived_vrrp[17694]: VRRP_Instance(VI_1) Changing effective p...52 4月 25 14:30:03 localhost.localdomain Keepalived_vrrp[17694]: VRRP_Instance(VI_1) Entering MASTER STATE 4月 25 14:30:03 localhost.localdomain Keepalived_vrrp[17694]: VRRP_Instance(VI_1) setting protocol VIPs. 4月 25 14:30:03 localhost.localdomain Keepalived_healthcheckers[17693]: Netlink reflector reports IP 17...d 4月 25 14:30:03 localhost.localdomain Keepalived_vrrp[17694]: Sending gratuitous ARP on em1 for 172.28...09 4月 25 14:30:03 localhost.localdomain Keepalived_vrrp[17694]: VRRP_Instance(VI_1) Sending/queueing gra...09 4月 25 14:30:03 localhost.localdomain Keepalived_vrrp[17694]: Sending gratuitous ARP on em1 for 172.28...09 4月 25 14:30:03 localhost.localdomain Keepalived_vrrp[17694]: Sending gratuitous ARP on em1 for 172.28...09 4月 25 14:30:03 localhost.localdomain Keepalived_vrrp[17694]: Sending gratuitous ARP on em1 for 172.28...09 4月 25 14:30:03 localhost.localdomain Keepalived_vrrp[17694]: Sending gratuitous ARP on em1 for 172.28...09 Hint: Some lines were ellipsized, use -l to show in full.
成功