歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux教程

KeepAlived防止單點故障

負載均衡器裡面,HAProxy比較出名了,但是如果只用一台HAProxy,則會出現單點故障。

這個時候,該KeepAlived出馬了。


環境介紹

OS: Ubuntu 12.04

虛擬IP: 192.168.56.2

KeepAlived + HaProxy : 192.168.56.101 (master)

KeepAlived + HaProxy : 192.168.56.102 (backup)

本來應該用HaProxy測試,為了簡便,直接用兩個redis測試。

後端對應著兩個redis 分別安裝在192.168.56.101,192.168.56.102上。

----------------------------------------------------------------------

然後101(master)上的配置為
! Configuration File for keepalived
global_defs {
   notification_email {
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server smtp.qq.com
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {
    state MASTER
    interface eth5
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.56.2
    }
}
102(backup)的配置為
! Configuration File for keepalived
global_defs {
   notification_email {
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server smtp.qq.com
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {
    state BACKUP
    interface eth5
    virtual_router_id 51
    priority 99
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.56.2
    }
}
PS:因為我只需要VIP浮動,負載均衡交給了HAProxy,所以KeepAlived的負載均衡功能沒有使用。

分別在101和102上啟動KeepAlived  ---  

啟動之前,看看如下:

daemon_mode默認值為0,而賦值的語句如下:

因為我們不需要 start_check_child(); 所以啟動參數加上-P即可,前台打日志,則加上 -ln

./bin/keepalived    -f   ./keepalived/etc/keepalived/keepalived.conf -P  -ln
然後看VIP是否可以ping

 估計是iptables未容許vrrp協議.

iptables -A INPUT -p vrrp -j ACCEPT
需要保存?
iptables -L 是列舉出當前的規則 ( )

再嘗試看看,還是不行,百度了半天,原來配置文件需要絕對路徑。

./bin/keepalived -f /root/keepalived-1.2.8/keepalived/etc/keepalived/keepalived.conf -P -ln

這下可以了

 ping的結果:

接下來啟動2個redis.

啟動101->啟動102->啟動測試程序->掛掉101->啟動101

結果:

Copyright © Linux教程網 All Rights Reserved