修改Keepalived設定檔位置以及重新導向Keepalived日誌的輸出路徑

來源:互聯網
上載者:User

上一篇博文主要講述了如何使用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

這樣我們就可以修改日誌路徑。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.