接上一篇博客:html
http://www.cnblogs.com/xiaoit/p/4499703.html算法
1:按照上篇博客安裝後的配置文件在sql
/usr/local/etc/keepalived/keepalived.conf
默認內容以下:服務器
! 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 192.168.200.1 #郵件服務連接超時的最長時間 smtp_connect_timeout 30 router_id LVS_DEVEL } #前面定義的後備的負載均衡服務器名稱 vrrp_instance VI_1 { #只有MASTER和BACKUP 兩種狀態,都必須大寫。 state MASTER #進行通訊的端口 interface eth0 #同一個vrrp實例的惟一標識。即同一個vrrp_stance,MASTER和BACKUP的virtual_router_id是一致的。在整個vrrp內也惟一。 virtual_router_id 51 #權重,數值越大,權重越大。MASTER大於SLAVE priority 100 #MASTER和SLAVE負載均衡器之間同步檢查的時間間隔。單位是:秒 advert_int 1 #MASTER和SLAVE的認證方式 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.200.16 192.168.200.17 192.168.200.18 } } #virtual_ipaddress,須要添加端口 virtual_server 192.168.200.100 443 { #服務健康檢查週期,6秒 delay_loop 6 #負載均衡調度算法rr|wrr|lc|wlc|sh|dh|lblc lb_algo rr #負載均衡轉發規則NAT|DR|TUN lb_kind NAT nat_mask 255.255.255.0 #回話保持時間,若是是動態服務,建議開啓。默認50秒 persistence_timeout 50 protocol TCP #真是IP 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 } } }
參考:負載均衡