上一篇博文主要講述了如何使用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/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 stuffcron.* /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.loglocal7.* /var/log/boot.log
看到最後一句:
local7.* /var/log/boot.log
同樣我們可以在這個檔案中添加
local0.* /var/log/keepalived.log
這樣我們就可以修改日誌路徑。