一,安裝
yum -y install gcc automake autoconf libtool make
tar -xzf haproxy-1.6.8
cd haproxy-1.6.8
make TARGET=linux2628
make install
二,編輯配置文件
Haproxy配置中分成五部分內容,當然這些組件不是必選的,可以根據需要選擇作為配置。
?global:參數是進程級的,通常和操作系統(OS)相關。這些參數一般只設置一次,如果配置無誤,就不需要再次配置進行修改;
?default:配置默認參數的,這些參數可以被利用配置到frontend,backend,listen組件;
?frontend:接收請求的前端虛擬節點,Frontend可以根據規則直接指定具體使用后端的backend(可動態選擇);
?backend:后端服務集群的配置,是真實的服務器,一個Backend對應一個或者多個實體服務器;
?listen:Frontend和Backend的組合體。
vi /etc/haproxy.cfg
global daemon maxconn 256 defaults mode http timeout connect 5000ms timeout client 5000ms timeout server 5000ms frontend http-in bind *:80 default_backend servers backend servers server server1 127.0.0.1:8000 maxconn 32 listen admin_stats bind 0.0.0.0:8888 #監聽端口 stats refresh 30s #統計頁面自動刷新時間 stats uri /stats #統計頁面url stats realm Haproxy Manager #統計頁面密碼框上提示文本 stats auth admin:admin #統計頁面用戶名和密碼設置 #stats hide-version #隱藏統計頁面上HAProxy的版本信息
三、啟動Haproxy
[root@MyServer haproxy]# haproxy -f /etc/haproxy.cfg
[ALERT] 238/183506 (16730) : Starting frontend http-in: cannot bind socket [0.0.0.0:80] [ALERT] 238/183506 (16730) : Starting proxy admin_stats: cannot bind socket [0.0.0.0:8888]
yum install httpd vi /etc/httpd/conf/httpd.conf listen 8000 service httpd start
四、驗證
http://122.10.117.38/
原創文章,作者:heilinux,如若轉載,請注明出處:http://www.www58058.com/40651