Haproxy
Haproxy安裝
yum -y install haproxy
配置負載均衡
frontend ds *:80 #定義前端服務器名爲ds 監聽地址爲所有ip的80端口
default_backend webservers #默認請求轉發到後端服務器組webservers
backend webservers #定義後端服務器組webservers
balance roundrobin #算法爲輪詢算法
server web1 192.168.189.162:80 check #添加後端服務器名爲web1,並啓用健康檢查
server web2 192.168.189.163:80 check #添加後端服務器名爲web2,並啓用健康檢查
配置動靜分離負載均衡
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend ds *:80
acl tp path_beg -i /static /wg /images /javascript /stylesheets \\定義URL過濾規則tp,過濾URL以指定路徑開頭的
acl tp path_end -i .jpg .gif .png .css .js \\定義URL過濾規則tp,過濾URL以指定資源結尾的
use_backend static if tp \\如果URL過濾規則tp生效,則將URL請求轉發至後端服務器組 static
default_backend webservers \\默認請求轉發到後端服務器組webservers
#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend webservers \\定義後端服務器組webservers
balance roundrobin
server web1 192.168.189.162:80 check
server web2 192.168.189.163:80 check
backend static \\定義後端服務器組static
balance roundrobin
server jp1 192.168.189.164:80 check
server jp2 192.168.189.165:80 check