通过以下方式查找问题
- 查看脚本无误
- 查看keepalived配置文件无误
- 重启命令无效
最后发现问题是重启命令无效
编辑systemctl相关的文件:vim /usr/lib/systemd/system/keepalived.service
KillMode=process的大致意思是当停止keepalived的时候只会停掉主进程,而主进程产生的子进程是不会被杀掉的,这里选择把这项注释掉
[Service]
Type=forking
PIDFile=/run/keepalived.pid
#KillMode=process
EnvironmentFile=-/etc/sysconfig/keepalived
ExecStart=/usr/local/keepalived/sbin/keepalived $KEEPALIVED_OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
重启配置: systemctl daemon-reload
杀死keepalived所有进程: killall keepalived
并重新启动keepalived: systemctl start keepalived
发现keepalived配置文件生效了,并且也可以stop和restart了