keepalived雙主模型高可用+lvs-實例

拓撲圖:

image

 

環境準備:
Centos6.5x86_64 關閉防火牆和Selinux

node5: eth0:192.168.1.190/24   VIP:192.168.1.121/24
node1:eth1:192.168.1.191/24   VIP:192.168.1.122/24
node2:RIP:eth0: 192.168.19.2/24
node3:RIP:eth0: 192.168.19.3/24   所有節點網關/DNS都爲:192.168.1.1

每個服務器的hosts文件

# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.19.190 node5.luo.com node5 192.168.19.191 node1.luo.com node1 192.168.19.192 node2.luo.com node2 192.168.19.193 node3.luo.com node3

時間同步(每個節點都需要做)
爲方便實驗使用筆記本作爲時間服務器,參考http://blog.csdn.net/irlover/article/details/7314530
ntpdate 192.168.1.105
如我想每隔10分鐘和win7同步時間可以使用crontab -e 編輯crontab工作內容如下:
*/10 * * * * /usr/sbin/ntpdate 192.168.1.105 &>/dev/null&&/sbin/hwclock-w


配置後端real server :node2與node3

node2與node3都執行下面的配置

echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_ignore ifconfig lo:0 192.168.1.121 netmask 255.255.255.255 broadcast 192.168.1.121 route add -host 192.168.1.121 dev lo:0 ifconfig lo:1 192.168.1.122 netmask 255.255.255.255 broadcast 192.168.1.122 route add -host 192.168.1.122 dev lo:1

分別爲node2與node3安裝httpd並寫好測試頁面
# yum install httpd
node2測試頁面
# echo "<h1>node2.luo.com</h1>" > /var/www/html/index.html
# service httpd restart
# curl http://192.168.1.192

node3測試頁面
#  echo "<h1>node3.luo.com</h1>" > /var/www/html/index.html
# service httpd restart
# curl http://192.168.1.193

二、配置前端的Director
node5與node1安裝配置基本相同
在兩個節點上都安裝keepalived
# yum install -y keepalived ipvsadm

node5的配置與node1的不同之處在與兩個實例中的角色剛好相反,node5爲MASTER時,node1爲BACKUP,其相應的優先級也有所改變,其他配置相同。

node5配置文件

! Configuration File for keepalived global_defs { notification_email { acassen@firewall.loc failover@firewall.loc sysadmin@firewall.loc } notification_email_from Alexandre.Cassen@firewall.loc smtp_server localhost smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 61 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 123456 } virtual_ipaddress { 192.168.1.121 } } vrrp_instance VI_2 { state BACKUP interface eth0 virtual_router_id 71 priority 99 advert_int 1 authentication { auth_type PASS auth_pass 123456 } virtual_ipaddress { 192.168.1.122 } } virtual_server 192.168.1.121 80 { delay_loop 6 lb_algo rr lb_kind DR nat_mask 255.255.255.0 protocol TCP real_server 192.168.1.192 80 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 2 nb_get_retry 3 delay_before_retry 1 } } real_server 192.168.1.193 80 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 2 nb_get_retry 3 delay_before_retry 1 } } } virtual_server 192.168.1.122 80 { delay_loop 6 lb_algo rr lb_kind DR nat_mask 255.255.255.0 protocol TCP real_server 192.168.1.192 80 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 2 nb_get_retry 3 delay_before_retry 1 } } real_server 192.168.1.193 80 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 2 nb_get_retry 3 delay_before_retry 1 } } }

   

node1配置文件

! Configuration File for keepalived global_defs { notification_email { acassen@firewall.loc failover@firewall.loc sysadmin@firewall.loc } notification_email_from Alexandre.Cassen@firewall.loc smtp_server localhost smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_instance VI_1 { state BACKUP interface eth1 virtual_router_id 61 priority 99 advert_int 1 authentication { auth_type PASS auth_pass 123456 } virtual_ipaddress { 192.168.1.121 } } vrrp_instance VI_2 { state MASTER interface eth1 virtual_router_id 71 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 123456 } virtual_ipaddress { 192.168.1.122 } } virtual_server 192.168.1.121 80 { delay_loop 6 lb_algo rr lb_kind DR nat_mask 255.255.255.0 protocol TCP real_server 192.168.1.192 80 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 2 nb_get_retry 3 delay_before_retry 1 } } real_server 192.168.1.193 80 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 2 nb_get_retry 3 delay_before_retry 1 } } } virtual_server 192.168.1.122 80 { delay_loop 6 lb_algo rr lb_kind DR nat_mask 255.255.255.0 protocol TCP real_server 192.168.1.192 80 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 2 nb_get_retry 3 delay_before_retry 1 } } real_server 192.168.1.193 80 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 2 nb_get_retry 3 delay_before_retry 1 } } }


測試
先啓動node5節點的keepalived服務,可以看到兩個VIP地址都配置在了node5的eth0網卡上。
ipvs規則的啓動效果爲,可以看到兩組規則也都啓動在了node5上。

image

啓動node1的keepalived服務,查看相關信息
 image

模擬node5節點服務器故障,此處直接停止node5的keepalived服務,查看node1信息都無誤,兩個VIP都到node1上面了
 image
至此,實驗完畢,如有錯誤之處,請多多指教。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章