圖片.png
一、haproxy介紹
HAProxy提供高可用性、負(fù)載均衡以及基于TCP和HTTP應(yīng)用的代 理,支持虛擬主機(jī),它是免費(fèi)、快速并且可靠的一種解決方案。HAProxy特別適用于那些負(fù)載特大的web站點(diǎn),這些站點(diǎn)通常又需要會(huì)話保持或七層處理。HAProxy運(yùn)行在當(dāng)前的硬件上,完全可以支持?jǐn)?shù)以萬(wàn)計(jì)的并發(fā)連接。并且它的運(yùn)行模式使得它可以很簡(jiǎn)單安全的整合進(jìn)您當(dāng)前的架構(gòu)中, 同時(shí)可以保護(hù)你的web服務(wù)器不被暴露到網(wǎng)絡(luò)上。
二、haproxy安裝
1、下載地址 http://pkgs.fedoraproject.org/repo/pkgs/haproxy/
2、編譯安裝
圖片.png
make install PREFIX=/usr/local/haproxy
圖片.png
三、啟動(dòng)與管理haproxy
1、啟動(dòng) /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg
2、重啟服務(wù) /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg -st cat /usr/local/haproxy/log/haproxy.pid
3、停止服務(wù) killall haproxy
監(jiān)控界面.png
四、負(fù)載均衡配置
192.168.126.141 web1
192.168.126.142 web2
192.168.126.145 haproxy
haproxy.cfg配置
global
log 127.0.0.1 local2
maxconn 1000
daemon
defaults
log global
mode http
option httplog
option dontlognull
retries 3
timeout connect 5000
timeout client 50000
timeout server 50000
listen stats
bind 0.0.0.0:1080
mode http
option httplog
maxconn 10
stats refresh 30s
stats uri /stats
stats realm XingCloud\ Haproxy
stats auth admin:admin
stats auth Frank:Frank
stats hide-version
stats admin if TRUE
frontend http-in
bind *:80
mode http
log global
option httpclose
option logasap
option dontlognull
capture request header Host len 20
capture request header Referer len 60
default_backend servers
backend servers
balance roundrobin
server server1 192.168.126.141:80 check maxconn 2000
server server2 192.168.126.142:80 check maxconn 2000