參考博文:html
CentOS6.5 keepalived詳解及實現Nginx服務的高可用性服務器
CentOS6.5 LVS + KeepAlived搭建步驟 網絡
我採用yum 方式 直接安裝 版本爲1.2.13jsp
# yum -y install keepalived
global_defs { #全局定義 notification_email { #定義郵件提醒 一行一個 多我的寫多行 acassen@firewall.loc failover@firewall.loc sysadmin@firewall.loc } notification_email_from Alexandre.Cassen@firewall.loc #以什麼人的身份發郵件,發件人 smtp_server 192.168.200.1 #指定發郵件的服務器 smtp_connect_timeout 30 #鏈接郵件服務器超時時長 router_id LVS_DEVEL #路由ID } vrrp_instance VI_1 { state MASTER #備份服務器上將MASTER改成 BACKUP interface eth0 #HA 檢測網絡接口 virtual_router_id 51 #主、備機的 virtual_router_id 必須相同 priority 100 # 主、備機取不一樣的優先級,主機值較大,備份機值較小 advert_int 1 # VRRP Multicast 廣播週期秒數 authentication { auth_type PASS #VRRP 認證方式 auth_pass 1111 #VRRP 口令字 } virtual_ipaddress { # VRRP HA 虛擬地址 若是有多個VIP,繼續換行填寫 192.168.200.16 192.168.200.17 192.168.200.18 } } virtual_server 192.168.200.100 443 { delay_loop 6 # 每隔 6 秒查詢 realserver 狀態 lb_algo rr #lvs 算法 lb_kind DR # Direct Route nat_mask 255.255.255.0 persistence_timeout 50 # 同一IP 的鏈接50 秒內被分配到同一臺realserver protocol TCP # 用 TCP 協議檢查 realserver 狀態 real_server 192.168.201.100 443 { weight 1 #(權重) SSL_GET { url { path / digest ff20ad2481f97b1754ef3e12ecd3a9cc } url { path /mrtg/ digest 9b3a0c85a887a256d6939da88aabd8cd } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } } virtual_server 10.10.10.2 1358 { delay_loop 6 lb_algo rr lb_kind NAT persistence_timeout 50 protocol TCP sorry_server 192.168.200.200 1358 real_server 192.168.200.2 1358 { weight 1 HTTP_GET { url { path /testurl/test.jsp digest 640205b7b0fc66c1ea91c463fac6334d } url { path /testurl2/test.jsp digest 640205b7b0fc66c1ea91c463fac6334d } url { path /testurl3/test.jsp digest 640205b7b0fc66c1ea91c463fac6334d } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } real_server 192.168.200.3 1358 { weight 1 HTTP_GET { url { path /testurl/test.jsp digest 640205b7b0fc66c1ea91c463fac6334c } url { path /testurl2/test.jsp digest 640205b7b0fc66c1ea91c463fac6334c } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } } virtual_server 10.10.10.3 1358 { delay_loop 3 lb_algo rr lb_kind NAT nat_mask 255.255.255.0 persistence_timeout 50 protocol TCP real_server 192.168.200.4 1358 { weight 1 HTTP_GET { url { path /testurl/test.jsp digest 640205b7b0fc66c1ea91c463fac6334d } url { path /testurl2/test.jsp digest 640205b7b0fc66c1ea91c463fac6334d } url { path /testurl3/test.jsp digest 640205b7b0fc66c1ea91c463fac6334d } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } real_server 192.168.200.5 1358 { weight 1 HTTP_GET { url { path /testurl/test.jsp digest 640205b7b0fc66c1ea91c463fac6334d } url { path /testurl2/test.jsp digest 640205b7b0fc66c1ea91c463fac6334d } url { path /testurl3/test.jsp digest 640205b7b0fc66c1ea91c463fac6334d } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } }