在haproxy node5中添加兩塊網卡,將新添加的網卡定義在vmnet2中
將兩個後端的動靜節點也設置到vmnet2中
[root@node5 ~]# yum install -y haproxy [root@node5 ~]# ifconfig eth1 192.168.1.10/24 up [root@node5 ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:BA:4E:78 inet addr:192.168.8.43 Bcast:192.168.8.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:feba:4e78/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1418 errors:0 dropped:0 overruns:0 frame:0 TX packets:185 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:103198 (100.7 KiB) TX bytes:19819 (19.3 KiB) eth1 Link encap:Ethernet HWaddr 00:0C:29:BA:4E:82 inet addr:192.168.1.10 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:feba:4e82/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:63 errors:0 dropped:0 overruns:0 frame:0 TX packets:6 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:3780 (3.6 KiB) TX bytes:468 (468.0 b) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:12 errors:0 dropped:0 overruns:0 frame:0 TX packets:12 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1244 (1.2 KiB) TX bytes:1244 (1.2 KiB)
# yum install -y php httpd # ifconfig eth0 192.168.1.20/24 up # route add defaulte gw 192.168.1.10 # 網關指向haproxy主機的eth1地址 # ping 192.168.1.10 # ping一下haproxy的節點看是否ping通 # vim /var/www/html/index.html
# yum install -y php httpd # ifconfig eth0 192.168.1.30/24 up # route add defaulte gw 192.168.1.10 # 網關指向haproxy主機的eth1地址 # ping 192.168.1.10 # ping一下haproxy的節點看是否ping通 # vim /var/www/html/index.html
[root@node5 ~]# curl -I http://192.168.1.20 HTTP/1.1 200 OK Date: Mon, 09 May 2016 12:00:53 GMT Server: Apache/2.2.15 (CentOS) X-Powered-By: PHP/5.3.3 Connection: close Content-Type: text/html; charset=UTF-8 [root@node5 ~]# curl -I http://192.168.1.30 HTTP/1.1 200 OK Date: Fri, 29 Apr 2016 02:55:57 GMT Server: Apache/2.2.15 (CentOS) X-Powered-By: PHP/5.3.3 Connection: close Content-Type: text/html; charset=UTF-8
############## 以上的使用默認配置就可以了 ####################### frontend web *:80 # *表示haproxy監聽所有地址,監聽的端口為80 # 定義訪問控制,表示以url以.css .js .html .php結尾的分別調度到哪台服務器上訪問 acl url_static path_end -i .css .js .html acl url_dynamic path_end -i .php # usr_backend表示使用backend服務,if表示如果滿足url_static這個條件就調度到這台服務器上 use_backend static if url_static default_backend dynamic backend static # 定義調用後端的靜態頁面的服務器上 server node1 192.168.1.20:80 check inter 3000 rise 2 fall 2 maxconn 5000 backend dynamic # 定義調用後端的動態頁面的服務器上 server node2 192.168.1.30:80 check inter 3000 rise 2 fall 2 maxconn 5000 listen statspage # 定義監控管理接口的界面 bind *:8888 # 定義訪問頁面端口 stats enable # 啟用管理界面 stats hide-version # 隱藏版本 stats uri /admin?stats # 訪問路徑 stats auth admin:centos # 訪問時需要驗證登錄 stats admin if TRUE # 如果登錄成功就可以管理在線服務器
訪問管理頁面: