1. 程式人生 > >linux下keepalived安裝教程

linux下keepalived安裝教程

1、安裝環境

yum -y install kernel-devel*
yum -y install openssl-*
yum -y install popt-devel
yum -y install lrzsz
yum -y install openssh-clients
yum -y install libnl libnl-devel popt

 

2、開始安裝

上傳 keepalived-1.2.15.tar.gz 到伺服器  /usr/local/  目錄下。

進入剛剛的目錄: cd /usr/local

解壓剛剛的檔案: tar -zxvf keepalived-1.2.15.tar.gz

進入解壓完的目錄:cd keepalived-1.2.15

可以看見下面有個configure檔案:

執行配置命令:  ./configure --prefix=/usr/local/keepalived

編譯:make 

安裝: make install

到這裡安裝就完成了

1.拷貝執行檔案  cp /usr/local/keepalived/sbin/keepalived /usr/sbin/

2.將init.d檔案拷貝到etc下,加入開機啟動項  cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/keepalived

3.將keepalived檔案拷貝到etc下,加入網絡卡配置  cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

4.建立keepalived資料夾  mkdir -p /etc/keepalived

5.將keepalived配置檔案拷貝到etc下  cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf​​​​​​​

6.新增可執行許可權  chmod +x /etc/init.d/keepalived

3、加入開機自啟

chkconfig --add keepalived     #新增時必須保證/etc/init.d/keepalived存在

chkconfig keepalived on

新增完可查詢系統服務是否存在:chkconfig --list

可以看見 keepalived 已經存在了

4、啟動

啟動:service keepalived start

停止:service keepalived stop

重啟:service keepalived restart

4.1 配置日誌檔案

1.將keepalived日誌輸出到local0:

                   vi /etc/sysconfig/keepalived

                   KEEPALIVED_OPTIONS="-D -d -S 0"

2.在/etc/rsyslog.conf 末尾裡新增:

                     vim /etc/rsyslog.conf

                     local0.*  /var/log/keepalived.log

3.重新啟動keepalived和rsyslog服務:

                     service rsyslog restart

                     service keepalived restart

5. 開啟防火牆的通訊地址

      iptables -A INPUT -d 224.0.0.18 -j ACCEPT

       /etc/rc.d/init.d/iptables save