keepalived 安裝:
cd <keepalived_sourcecode_path>
./configure --prefix=/usr/local/keepalived
make && make install
mkdir /etc/keepalived
mkdir /etc/keepalived/scripts
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /root/keepalived-2.0.6/keepalived/etc/init.d/keepalived /etc/init.d/
cp /usr/local/keepalived/sbin/keepalived /sbin/keepalived
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
chmod +x /etc/init.d/keepalived
由于在默認(rèn)狀態(tài)下keepalived的日志會(huì)寫入到/var/log/message中,我們需要將此剝離出來。
在centos 6下可以:
(1)首先修改/etc/sysconfig/keepalived文件,注釋掉如下,添加如下:
#KEEPALIVED_OPTIONS="-D"
KEEPALIVED_OPTIONS="-D -d -S 0"
(2)其次修改 /etc/rsyslog.conf 文件,添加如下:
local0.* /var/log/keepalived.log
在centos 7 下,還需要修改/lib/systemd/system/keepalived.service 文件:
centos 7使用。因?yàn)閏entos 7使用systemctl,通過systemctl調(diào)用service,所以需要修改/lib/systemd/system/keepalived.service文件。
將里面的:
EnvironmentFile=-/usr/local/keepalived/etc/sysconfig/keepalived
ExecStart=/usr/local/keepalived/sbin/keepalived $KEEPALIVED_OPTIONS
修改成:
EnvironmentFile=/etc/sysconfig/keepalived
ExecStart=/sbin/keepalived $KEEPALIVED_OPTIONS
然后重新加載service:
整體的思路就是,
1. 通過systemctl start keepalived去啟動(dòng);
2. 啟動(dòng)keepalived的時(shí)候,會(huì)去讀service的配置文件:/lib/systemd/system/keepalived.service;
3. 在service的配置文件時(shí):
3.1 啟動(dòng)文件路徑ExecStart=/sbin/keepalived $KEEPALIVED_OPTIONS,即啟動(dòng)方式是帶環(huán)境變量文件中參數(shù)來啟動(dòng);
3.2 讀取環(huán)境變量參數(shù)EnvironmentFile=/etc/sysconfig/keepalived。
4. $KEEPALIVED_OPTIONS參數(shù)是在/etc/sysconfig/keepalived的配置;我們配置的是KEEPALIVED_OPTIONS="-D -d -S 0";而-S是syslog的facility,0表示放在local0,在/etc/rsyslog.conf 中配置local0.* /var/log/keepalived.log
5. 所以,寫日志就去/var/log/keepalived.log了。
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。