keepalived添加服务自启动报错分析

时间:2022-06-02 11:53:56

安装完keepalived后设置为服务自启动

将路径为/usr/local/src/keepalived-1.3.4/keepalived/etc/init.d的文件keepalived拷贝到/etc/init.d下

cp /usr/local/src/keepalived-1.3./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./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 四 -- :: CST; 24s ago
Process: ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=/EXEC) 4月 :: localhost.localdomain systemd[]: Starting LVS and VRRP High Availability Monitor...
4月 :: localhost.localdomain systemd[]: keepalived.service: control process exited, code=ex...
4月 :: localhost.localdomain systemd[]: Failed to start LVS and VRRP High Availability Monitor.
4月 :: localhost.localdomain systemd[]: Unit keepalived.service entered failed state.
4月 :: localhost.localdomain systemd[]: 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.]# systemctl start keepalived
[root@localhost keepalived-1.3.]# 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 四 -- :: CST; 2s ago
Process: ExecStart=/usr/local/bin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=/SUCCESS)
Main PID: (keepalived)
CGroup: /system.slice/keepalived.service
├─ /usr/local/bin/keepalived -D
├─ /usr/local/bin/keepalived -D
└─ /usr/local/bin/keepalived -D 4月 :: localhost.localdomain Keepalived_vrrp[]: VRRP_Instance(VI_1) Changing effective p...
4月 :: localhost.localdomain Keepalived_vrrp[]: VRRP_Instance(VI_1) Entering MASTER STATE
4月 :: localhost.localdomain Keepalived_vrrp[]: VRRP_Instance(VI_1) setting protocol VIPs.
4月 :: localhost.localdomain Keepalived_healthcheckers[]: Netlink reflector reports IP ...d
4月 :: localhost.localdomain Keepalived_vrrp[]: Sending gratuitous ARP on em1 for 172.28...
4月 :: localhost.localdomain Keepalived_vrrp[]: VRRP_Instance(VI_1) Sending/queueing gra...
4月 :: localhost.localdomain Keepalived_vrrp[]: Sending gratuitous ARP on em1 for 172.28...
4月 :: localhost.localdomain Keepalived_vrrp[]: Sending gratuitous ARP on em1 for 172.28...
4月 :: localhost.localdomain Keepalived_vrrp[]: Sending gratuitous ARP on em1 for 172.28...
4月 :: localhost.localdomain Keepalived_vrrp[]: Sending gratuitous ARP on em1 for 172.28...
Hint: Some lines were ellipsized, use -l to show in full.

成功