修改keepalived.service 文件
vim /usr/lib/systemd/system/keepalived.service
修改KillMode=control-group
- KillMode值释义:
- process kill 主进程
- control-group 杀死进程组,不设置时默认值
指定PIDFile=keepalived.pid 的生成路径
,需要注意文件存放目录是否有写入权限
- $MAINPID 为该文件记录的值,需要指定pid才可以正确执行reload 和 stop
指定 ExecReload=/bin/kill -HUP $MAINPID
指定 ExecStop=/bin/kill -TERM $MAINPID
完整配置如下
[Unit]
Description=LVS and VRRP High Availability Monitor
After=syslog.target network-online.target
[Service]
Type=forking
PIDFile=/var/run/keepalived.pid
KillMode=control-group
EnvironmentFile=-/etc/sysconfig/keepalived
ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/bin/kill -TERM $MAINPID
[Install]
WantedBy=multi-user.target
~
之后使用 systemctl stop keepalived
关闭keepalived,
并使用 ps aux | grep keepalived | grep -v grep
查看进程
[root@localhost keepalived]# systemctl stop keepalived
[root@localhost keepalived]# ps aux | grep keepalived | grep -v grep
可以看到 keepalived 进程已关闭
重新启动后再次查看
[root@localhost keepalived]# systemctl start keepalived
[root@localhost keepalived]# 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 一 2020-11-02 17:25:36 CST; 5s ago
Process: 17784 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 17785 (keepalived)
CGroup: /system.slice/keepalived.service
├─17785 /usr/sbin/keepalived -D
├─17786 /usr/sbin/keepalived -D
└─17787 /usr/sbin/keepalived -D
11月 02 17:25:36 localhost.localdomain Keepalived_vrrp[17787]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
11月 02 17:25:39 localhost.localdomain Keepalived_vrrp[17787]: VRRP_Instance(VI_1) Transition to MASTER STATE
11月 02 17:25:40 localhost.localdomain Keepalived_vrrp[17787]: VRRP_Instance(VI_1) Entering MASTER STATE
11月 02 17:25:40 localhost.localdomain Keepalived_vrrp[17787]: VRRP_Instance(VI_1) setting protocol VIPs.
11月 02 17:25:40 localhost.localdomain Keepalived_vrrp[17787]: Sending gratuitous ARP on ens33 for 192.168.61.132
11月 02 17:25:40 localhost.localdomain Keepalived_vrrp[17787]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on ens33 for 192.168.61.132
11月 02 17:25:40 localhost.localdomain Keepalived_vrrp[17787]: Sending gratuitous ARP on ens33 for 192.168.61.132
11月 02 17:25:40 localhost.localdomain Keepalived_vrrp[17787]: Sending gratuitous ARP on ens33 for 192.168.61.132
11月 02 17:25:40 localhost.localdomain Keepalived_vrrp[17787]: Sending gratuitous ARP on ens33 for 192.168.61.132
11月 02 17:25:40 localhost.localdomain Keepalived_vrrp[17787]: Sending gratuitous ARP on ens33 for 192.168.61.132
[root@localhost keepalived]# ps aux | grep keepalived | grep -v grep
root 17785 0.0 0.1 123000 1408 ? Ss 17:25 0:00 /usr/sbin/keepalived -D
root 17786 0.0 0.2 123000 2628 ? S 17:25 0:00 /usr/sbin/keepalived -D
root 17787 0.0 0.1 123000 1896 ? S 17:25 0:00 /usr/sbin/keepalived -D