Keepalived 日志默认只输出到 /var/log/messages 文件中。由于 /var/log/messages 中记录了系统中其他服务的相关日志,日志内容刷新比较快,不便于观察,这里修改日志存储到一个单独文件中。

注意:修改keepalived日志输出路劲涉及到了重启keepalived服务,线上环境建请合理安排重启时间。

1.配置Keepalived日志输出信息

修改 /etc/sysconfig/keepalived 配置文件,把 KEEPALIVED_OPTIONS="-D" 修改为: KEEPALIVED_OPTIONS="-D -d -S 0"

$ cat /etc/sysconfig/keepalived 
# Options for keepalived. See `keepalived --help' output and keepalived(8) and
# keepalived.conf(5) man pages for a list of all options. Here are the most
# common ones :
#
# --vrrp -P Only run with VRRP subsystem.
# --check -C Only run with Health-checker subsystem.
# --dont-release-vrrp -V Dont remove VRRP VIPs & VROUTEs on daemon stop.
# --dont-release-ipvs -I Dont remove IPVS topology on daemon stop.
# --dump-conf -d Dump the configuration data.
# --log-detail -D Detailed log messages.
# --log-facility -S 0-7 Set local syslog facility (default=LOG_DAEMON)
#

#KEEPALIVED_OPTIONS="-D"
KEEPALIVED_OPTIONS="-D -d -S 0"

2.配置Keepalived日志输出位置

修改rsyslog配置文件,添加keepalived日志输出路劲

$ vim /etc/rsyslog.conf
# Save keepalived messaves also to keepalived.log
local0.* /var/log/keepalived.log

3.重启rsyslog、keepalived服务

$ systemctl restart rsyslog.service
$ systemctl restart keepalived.service