################################################################# keepalived master eth0: 192.168.108.18 keepalived slave eth0: 192.168.108.19 real server 1 eth0: 192.168.108.10 real server 1 eth0: 192.168.108.21 vip: 192.168.108.17 real server 1 & 2: 安裝nginx 開啓80端口 test server eth0: 192.168.108.25 ################################################################# ##################### keepalived master ########################## global_defs { notification_email { ****@****.com } notification_email_from keepalived@localhost.com smtp_server ******** smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_instance VI_1 { state BACKUP nopreempt interface eth0 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.108.17 } } virtual_server 192.168.108.17 80 { delay_loop 6 lb_algo wrr lb_kind DR persistence_timeout 0 protocol TCP real_server 192.168.108.10 80 { weight 100 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.108.21 80 { weight 100 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } } ##################### keepalived master ########################## ##################### keepalived slave ########################## global_defs { notification_email { ****@****.com } notification_email_from keepalived@localhost.com smtp_server ******** smtp_connect_timeout 30 router_id LVS_DEVEL } 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.108.17 } } virtual_server 192.168.108.17 80 { delay_loop 6 lb_algo wrr lb_kind DR persistence_timeout 0 protocol TCP real_server 192.168.108.10 80 { weight 100 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.108.21 80 { weight 100 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } } ##################### keepalived slave ########################## ###################### real server 1 & 2 ######################## #!/bin/bash #/usr/local/sbin/lvs_rs.sh vip=192.168.108.17 ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up route add -host $vip lo:0 echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce ###################### real server 1 & 2 ######################## ################## real server 1 & 2 setting ################### ifconfig lo:0 down systemctl start nginx sh /usr/local/sbin/lvs_dr.sh ################## real server 1 & 2 setting ################### ################## keepalived master & slave setting ########### #服務器上開啓路由轉發功能: echo 1 > /proc/sys/net/ipv4/ip_forward ipvsadm -C systemctl start keepalived ################## keepalived master & slave setting ########### ######################## test server ########################### curl 192.168.108.17 #分別關閉重啓 keepalived master & salve 的keepalvied systemctl stop keepalvide systemctl restart keepalvide #分別關閉 real server 1 & 2 nginx systemctl stop nginx ######################## test server ###########################