去年看見淘寶章博士的PPT里面講過淘寶的CDN架構(gòu),覺得簡單使用。
我也一直覺得haproxy比較簡潔的,另外畫了一個圖,可以給應用做好負載均衡。不過我這個圖里兩個LVS只是一主一倍,也可以作為相互備份,這樣更能提高利用率。
這個基本是照著淘寶的這個架構(gòu)搞的。但是其實里面有些細節(jié)地方可以仔細說一下。這個實現(xiàn)過程是
最最外面做LVS的機器上綁定一堆公網(wǎng)的IP。假如是10.10.114.2 .....10.10.114.254 (這個只是作為解說)。
做LVS負載均衡的機器上另外一個網(wǎng)卡綁定一個內(nèi)部的IP,假如分別為192.168.1.2和192.168.1.3.
- virtual_server 10.10.114.2 80 {
- delay_loop 3
- lb_algo wlc
- lb_kind DR
- nat_mask 255.255.255.0
- persistence_timeout 50
- protocol TCP
- real_server 192.168.1.4 80 {
- weight 100
- TCP_CHECK {
- connect_port 80
- connect_timeout 3
- nb_get_retry 3
- delay_before_retry 10
- }
- }
- real_server 192.168.1.5 80 {
- weight 100
- TCP_CHECK {
- connect_port 80
- connect_timeout 3
- nb_get_retry 3
- delay_before_retry 10
- }
-
-
-
- }
-
- virtual_server 10.10.114.3 80 {
- delay_loop 3
- lb_algo wlc
- lb_kind DR
- nat_mask 255.255.255.0
- persistence_timeout 50
- protocol TCP
- real_server 192.168.1.4 80 {
- weight 100
- TCP_CHECK {
- connect_port 80
- connect_timeout 3
- nb_get_retry 3
- delay_before_retry 10
- }
- }
- real_server 192.168.1.5 80 {
- weight 100
- TCP_CHECK {
- connect_port 80
- connect_timeout 3
- nb_get_retry 3
- delay_before_retry 10
- }
-
-
-
- }
那么配置 haproxy的幾個機器上每個機器有一個192.168.1.X的IP外,還需要在每個機器的回環(huán)地址上綁定所有VIP(10.10.114.x)的。這樣可以直接使用DR模式來對haproxy做第一級的負載均衡,而且對于安裝haproxy的服務(wù)器上,因為在回環(huán)地址上綁定了這么多的ip(設(shè)置好arp抑制后其實只有這些機器自己知道自己有這些VIP),所以在配置haproxy時也非常方便了。
當外部請求進來時,LVS把請求轉(zhuǎn)發(fā)給Haproxy。由于haproxy上監(jiān)聽的是綁在lo上的VIP,所以可以根據(jù)對方的目標IP來選擇后端的機器。
- frontend server1
- mode tcp
- bind 10.10.114.2:80
- default_backend real_server1
- backend real_server1
- mode tcp
- balance roundrobin
- server A 192.168.x.2:80 weight 1
- server B 192.168.x.3:80 weight 1
- frontend server2
- mode http
- bind 10.10.114.3:80
- default_backend real_server2
- backend real_server2
- mode http
- balance roundrobin
- server A 192.168.x.4:80 weight 1
- server B 192.168.x.5:80 weight 1
- frontend server3
- mode http
- bind 10.10.114.4:80
- default_backend real_server3
- backend real_server3
- mode http
- balance roundrobin
- server A 192.168.x.6:80 weight 1
- server B 192.168.x.7:80 weight 1
這樣的話所有的haproxy都可以同時工作,lvs對他們也可以做好健康檢測。對于后端應用,我們也可以充分利用haproxy來做好健康檢測。
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點擊舉報。