實現雙例項(lvs+keepalived)【雙主模型】
阿新 • • 發佈:2018-12-12
基本架構如下圖 分析:DR1,2 為兩個互為主備的排程器,DR1上設定VIP:10.220.5.187為主,DR2上設定VIP:10.220.5.197為主。
第一步: 在DR上安裝lvs和keepalived
# yum install libnl* popt* kernel-devel ipvsadm -y
# yum install keepalived -y
第二步:配置keepalived實現雙例項
1.DR1配置keepalive實現雙例項
[[email protected] ~]# vim /etc/keepalived/keepalived.conf
修改vrrp_instance段如下:
vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 150 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 10.220.5.187 } } vrrp_instance VI_2 { state BACKUP interface eth0 virtual_router_id 52 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 10.220.5.197 } }
注意:配置檔案中global_defs段的router_id 為DR1 即 router_id DR2
2.DR2配置keepalive實現雙例項
[[email protected] ~]# vim /etc/keepalived/keepalived.conf
修改vrrp_instance段如下:
vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 10.220.5.187 } } vrrp_instance VI_2 { state MASTER interface eth0 virtual_router_id 52 priority 150 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 10.220.5.197 } }
注意:配置檔案中global_defs段的router_id 為DR1 即 router_id DR2
配置檔案對比如下圖:
3.修改DR1和DR2的/etc/keepalived/keepalived.conf
檔案的virtual_server段如下
virtual_server 10.220.5.187 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 10.220.5.113 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connet_port 80
}
}
real_server 10.220.5.114 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connet_port 80
}
}
}
virtual_server 10.220.5.197 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 10.220.5.115 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connet_port 80
}
}
real_server 10.220.5.116 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connet_port 80
}
}
}
第三步:配置RS、測試
1.在後端RS節點上安裝httpd
# yum install httpd -y
2.全部啟動
# service httpd restart
3.在DR1和DR2上分別執行# ipvsadm -L -n
DR1和DR2的virtual_server段是相同的,所以# ipvsadm -L -n
得結果也是相同的,如上圖。
但是DR1和DR2正常工作時,vip:10.220.5.187只在DR1上,vip:10.220.5.197只在DR2上,所以在DR1上的的10.220.5.197規則不會起作用,同理DR2上的10.220.5.187規則也不會起作用。
而當DR1宕機後vip:10.220.5.187會漂移到DR2上,此時兩個規則同時在DR2上起作用。
當DR2宕機後vip:10.220.5.197會漂移到DR1上,兩個規則同時在DR1上起作用。