最新消息:

【工作】Keepalived 重定向日志输出位置

工作记录 摘星怪 904浏览 0评论

有时候由于为了排查问题,我们需要查看keepalived的输出日志,而默认keepalived的日志输出到/var/log/messages里面,和系统日志一起,查看起来非常不方便,所以需要将日志路径修改到合适的位置。

Keepalived 默认的配置文件路径在/etc/keepalived/keepalived.conf
Keepalived 默认的日志文件保存在/var/log/messages

1.修改 keepalived 服务配置

# 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”

“-D” 是输出日志的选项,
“-f” 是修改默认配置文件路径的选项,后面跟配置文件路径即可,(可选)
“-S” 是修改日志文件的默认输出路径
举例:KEEPALIVED_OPTIONS=”-f [配置文件路径] -D -S 0″

# vim /etc/sysconfig/keepalived

KEEPALIVED_OPTIONS=”-D -S 0″     #-S后面的是数字0

这里的“-S 0”表示local0.* ,还需要配合rsyslog服务才能达到效果。

2. 修改 rsyslog 服务配置

# vim /etc/rsyslog.conf

# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.*  /dev/console

# Log anything (except mail) of level info or higher.
# Don’t log private authentication messages!
*.info;mail.none;authpriv.none;cron.none /var/log/messages
# The authpriv file has restricted access.
authpriv.*  /var/log/secure
# Log all the mail messages in one place.
mail.*  -/var/log/maillog
# Log cron stuff
cron.*  /var/log/cron
# Everybody gets emergency messages
*.emerg *
# Save news errors of level crit and higher in a special file.
uucp,news.crit  /var/log/spooler
# Save boot messages also to boot.log
local7.*  /var/log/boot.log
local0.*  /var/log/keepalived.log  #添加此行,路径可自行指定

3.重启服务

# /etc/init.d/keepalived restart
# /etc/init.d/rsyslog restart

检查 /var/log/keepalived.log 文件是否存在,如果有就说明以上操作成功。

4.Keepalived相关管理的知识拓展

/usr/local/keepalived/sbin/keepalived –vrrp -P [Only run with VRRP subsystem.]
/usr/local/keepalived/sbin/keepalived –check -C [Only run with Health-checker subsystem.]
/usr/local/keepalived/sbin/keepalived –dont-release-vrrp -V [Dont remove VRRP VIPs & VROUTEs on daemon stop. ]
/usr/local/keepalived/sbin/keepalived –dont-release-ipvs -I [Dont remove IPVS topology on daemon stop. ]
/usr/local/keepalived/sbin/keepalived –dont-fork -n [Dont fork the daemon process. ]
/usr/local/keepalived/sbin/keepalived –use-file -f [Use the specified configuration file. Default is /etc/keepalived/keepalived.conf. ]
/usr/local/keepalived/sbin/keepalived –dump-conf -d [Dump the configuration data. ]
/usr/local/keepalived/sbin/keepalived –log-console -l [Log message to local console. ]
/usr/local/keepalived/sbin/keepalived –log-detail -D [Detailed log messages. ]
/usr/local/keepalived/sbin/keepalived –log-facility -S 0-7 [Set syslog facility to LOG_LOCAL[0-7]. (default=LOG_DAEMON) ]
/usr/local/keepalived/sbin/keepalived –help -h [Display this short inlined help screen. ]
/usr/local/keepalived/sbin/keepalived –version -v [Display the version number ]
/usr/local/keepalived/sbin/keepalived –pid -p [pidfile ]
/usr/local/keepalived/sbin/keepalived –checkers_pid -c [checkers pidfile ]
/usr/local/keepalived/sbin/keepalived –vrrp_pid -r [vrrp pidfile]

转载请注明:架构迷 » 【工作】Keepalived 重定向日志输出位置

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址