上一篇博文主要讲述了如何使用Keepalived实现tomcat服务器的双机热备。这篇博文是对上一篇博文的扩展,主要讲述如何修改Keepalived的默认配置文件的路径以及重定向Keepalived日志的输出路径。关于如何安装keepalived以及keepalived的安装路径问题,请参考上一篇博文。
Keepalived默认的配置文件路径在/etc/keepalived/keepalived.conf
Keepalived默认的日志文件保存在/var/log/messages
有时候由于现实的需要,比如项目的路径规划,需要将这些文件路径修改到合适的位置。
首先看一下/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",这个就是修改文件路径的关键。
这里补充下Keeaplived的相关知识
/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]
细心的读者可能注意到“-D” 就是输出日志的选项,而-f就是修改默认配置文件路径的选项。
在/etc/sysconfig/keepalived中的KEEPALIVED_OPTIONS修改为:
KEEPALIVED_OPTIONS="-f [配置文件路径] -D"
这里的[配置文件路径]]就是你所要修改的keepalived的配置文件的路径。
同样注意到要修改日志文件的默认路径就需要“-S”。这里将KEEPALIVED_OPTIONS再做修改,改为:
KEEPALIVED_OPTIONS="-f [配置文件路径] -D -S 0"
这里的“-S 0”表示local0.* 具体的还需要看一下/etc/syslog.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
看到最后一句:
local7.* /var/log/boot.log
同样我们可以在这个文件中添加
local0.* /var/log/keepalived.log
这样我们就可以修改日志路径。