天天看點

Linux下keepalive HA 配置文檔

1.安裝keepalived(主備均安裝)

cd/data/software

wgethttp://www.keepalived.org/software/keepalived-1.2.6.tar.gz

tar -zxvfkeepalived-1.2.6.tar.gz

cdkeepalived-1.2.6

./configure--prefix=/usr/local/keepalived

注:對于新伺服器,在進行二進制安裝時會出現幾個報錯,是因為系統缺少某些軟體導緻的

yum install openssl-*

yum install gcc popt-devel

然後再執行

./configure--prefix=/usr/local/keepalived

make

makeinstall

①建立服務啟動腳本,以便使用service指令控制之

cp /usr/local/keepalived/etc/rc.d/init.d/keepalived  /etc/init.d/keepalived

chmod +x /etc/init.d/keepalived

②修改/etc/init.d/keepalived尋找大約15行左右的./etc/sysconfig/keepalived, 修改為:

./usr/local/keepalived/etc/sysconfig/keepalived 即指向正确的檔案位置

修改環境變量

vi /etc/profile

export PATH="$PATH:/usr/local/keepalived/sbin"

source /etc/profile

③修改/usr/local/keepalived/etc/sysconfig/keepalived檔案,設定正确的服務啟動參數

KEEPALIVED_OPTIONS="-D -f/usr/local/keepalived/etc/keepalived/keepalived.conf"

ln -s /usr/local/keepalived/sbin/keepalived /usr/sbin/

④經過以上修改,keepalived基本安裝即可完成,啟動測試之:

service keepalived start

⑤切勿忘記将此服務設定為開機啟動

chkconfig keepalived on

2.配置主備模式

在這種模式下,虛拟IP在某時刻隻能屬于某一個節點,另一個節點作為備用節點存在。當主節點不可用時,備用節點接管虛拟IP,提供正常服務。

節點A 192.168.251.144 (主節點),

節點B 192.168.251.141 (備節點)

虛拟IP 192.168.251.150

要求預設情況下由節點A提供服務,當節點A不可用時,由節點B提供服務當節點A啟動後,信号自動從節點B切換到節點A,經測試,中間切換時間小于10s

主節點A配置檔案   vi /usr/local/keepalived/etc/keepalived/keepalived.conf

! Configuration File for keepalived

vrrp_script check_keepalived {

     script"/usr/local/keepalived/etc/keepalived/check_keepalived.sh"

     interval 5

     }

global_defs {

   router_idNodeA

}

vrrp_instance VI_1 {

    state MASTER

    interfaceeth0

   virtual_router_id 51

    priority 100

    advert_int 1

   authentication {

       auth_type PASS

       auth_pass 1111

    }

    virtual_ipaddress{

       192.168.251.150/24

        }

    track_script{

       check_keepalived

     }

}

備節點B配置檔案   vi /usr/local/keepalived/etc/keepalived/keepalived.conf

! Configuration File forkeepalived

global_defs {

  router_id NodeB

}

vrrp_instance VI_1 {

   state BACKUP

   interface eth0

   virtual_router_id 51

   priority 99

   advert_int 1

   authentication {

        auth_type PASS

        auth_pass 1111

   }

   virtual_ipaddress {

        192.168.251.150/24

   }

}

編寫程序檢測腳本check_keepalived.sh

#!/bin/bash

if [ "$(ps-ef | grep "java"| grep WowzaStreamingEngine |grep -v grep )" =="" ]

 then

  service keepalived stop

fi

上傳至/usr/local/keepalived/etc/keepalived/下,隻需要在主伺服器上添加。

六、啟動:

啟動wowza

servicekeepalived start/stop/status

繼續閱讀