After installing keepalived, set it to start the service automatically
Copy the file keepalived whose path is /usr/local/src/keepalived-1.3.4/keepalived/etc/init.d to /etc/init.d
cp /usr/local/src/keepalived-1.3.4/keepalived/etc/init.d/keepalived /etc/init.d/
Copy the file whose path is /usr/local/keepalived-1.3.4/etc/sysconfig/keepalived to /etc/sysconfig/keepalived
cp /usr/local/keepavlied-1.3.4/etc/sysconfig/keepalived /etc/sysconfig/
Add execute permission
chmod +x /etc/init.d/keepalived
Add keepalived to the system service
chkconfig --add keepalived
start up
[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.
[failure]
Report an error, start failure, use status to check the specific reason
[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.
Warning: ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=203/EXEC)
Check that the ll /usr/sbin/keepalived file does not exist, there are two ways to solve it at this time
1. Copy a keepalived to /usr/sbin/
2. Modify the /lib/systemd/system/keepalived.service file, and change the /usr/sbin/ path to the path where we store the keepalived file
[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. Take effect
systemctl daemon-reload
4. Restart
[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.
success