一個簡單的負載均衡集群:以web服務為例
實驗環境:三臺主機(CentOS 7.3)
主機1:IP地址 172.18.0.88(Haproxy代理服務器)
主機2:IP地址 172.18.0.89(后端服務器1)
主機3:IP地址 172.18.0.90(后端服務器2)
注意:時間一定要同步
第一步:安裝程序,并啟動服務
主機1:
#yum -y install haproxy
#systemctl start haproxy
主機2:
#yum -y install httpd
#systemctl start httpd.service
主機3:
#yum -y install httpd
#systemctl start httpd.service
第二步:
在兩個后端服務器上自定義測試頁:
主機2:
#vim /var/www/html/index.html
<h1>Backend Server 1 </h1>
主機3:
#vim /var/www/html/index.html
<h1>Backend Server 2 </h1>
第三步:
修改代理服務器配置文件:
把默認的配置注釋掉或刪除;
#vim /etc/haproxy/haproxy.cfg
# main frontend which proxys to the backends
frontend eshop
bind *.80
default_backend websrvs
# static backend for serving up images, stylesheets and such
backend websrvs
balance roundrobin
server web1 172.18.0.89 check
server web2 172.18.0.90 check
重啟下服務:#systemctl restart haproxy.service
原創文章,作者:yunweijiaozhenxing,如若轉載,請注明出處:http://www.www58058.com/76057