HAProxy負載平衡集群
- 環境準備
- 一、配置后端Web服務器
- 二、部署HAProxy服務器
- 三、測驗
環境準備
使用4臺虛擬機,其中一臺作為Nginx代理服務器,該服務器需要配置兩塊網卡,IP地址分別為192.168.4.5和192.168.2.5,兩臺Web服務器IP地址分別為192.168.2.100和192.168.2.200,客戶端測驗主機IP地址為192.168.4.10,
一、配置后端Web服務器
[root@web1 ~]# yum -y install httpd
[root@web1 ~]# systemctl start httpd
[root@web1 ~]# echo "192.168.2.100" > /var/www/html/index.html
[root@web2 ~]# yum -y install httpd
[root@web2 ~]# systemctl start httpd
[root@web2 ~]# echo "192.168.2.200" > /var/www/html/index.html
二、部署HAProxy服務器
[root@proxy ~]# yum -y install haproxy
[root@proxy ~]# vim /etc/haproxy/haproxy.cfg
打開組態檔在最后面敲
listen websrv-rewrite 0.0.0.0:80
balance roundrobin
server web1 192.168.2.100:80 check inter 2000 rise 2 fall 5
server web2 192.168.2.200:80 check inter 2000 rise 2 fall 5
#定義集群,listen后面的名稱任意,埠為80
#balance指定調度演算法為輪詢(不能用簡寫的rr)
#server指定后端真實服務器,web1和web2的名稱可以任意
#check代表健康檢查,inter設定健康檢查的時間間隔,rise定義成功次數,fall定義失敗次數
三、測驗
[root@client ~]# curl 192.168.4.5
192.168.2.100
[root@client ~]# curl 192.168.4.5
192.168.2.200
[root@client ~]# curl 192.168.4.5
192.168.2.100
[root@client ~]# curl 192.168.4.5
192.168.2.200
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/225941.html
標籤:其他
