1. 下載源碼包
cd /root
wget https://www.keepalived.org/software/keepalived-2.0.20.tar.gz
2. 解壓安裝
[/root#]tar -zxf keepalived-2.0.20.tar.gz
[/root#] cd keepalived-2.0.20
[/root/keepalived-2.0.20#] ./configure --prefix=/usr/local/keepalived
[/root/keepalived-2.0.20#] make && make install
3. 修改配置文件路徑
[/root/keepalived-2.0.20#] mkdir /etc/keepalived
[/root/keepalived-2.0.20#] cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf
[/root/keepalived-2.0.20#] mkdir /etc/sysconfig
[/root/keepalived-2.0.20#] cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/keepalived#
[/root/keepalived-2.0.20#] cp /usr/local/keepalived/sbin/keepalived /usr/sbin/keepalived
[/root/keepalived-2.0.20#] cp /root/keepalived-2.0.20/keepalived/etc/init.d/keepalived /etc/init.d/keepalived
4. 修改配置內(nèi)容
由于 ubuntu下沒有 /etc/rc.d/init.d/functions需要為其建立軟鏈
[/root/keepalived-2.0.20#] mkdir -p /etc/rc.d/init.d
[/root/keepalived-2.0.20#] ln -s /lib/lsb/init-functions /etc/rc.d/init.d/functions
修正相關(guān)配置問題
修改/etc/init.d/keepalived文件
[/root/keepalived-2.0.20#] apt install daemon
修改為daemon -- keepalived ${KEEPALIVED_OPTIONS} # 加了一個(gè)“--”
加載配置,啟動(dòng)keepalived
#systemctl daemon-reload #重新加載服務(wù)
#/etc/init.d/keepalived start #啟動(dòng)keealived服務(wù)
#######service keepalived start #啟動(dòng)keealived服務(wù)
#service keepalived status #可以查看運(yùn)行狀態(tài)
p a #查看是否占用了VIP刮吧,只有主服務(wù)器可以占用,主有問題時(shí)掖蛤,才會(huì)漂移到從服務(wù)器杀捻,并且從服務(wù)器狀態(tài)變?yōu)镸ASTER
如果啟動(dòng)出現(xiàn)問題,除了這里的輸出信息蚓庭,還可以通過 /var/log/syslog來(lái)查看問題
參考文檔: