haproxy安装


一台haproxy服务器  192.168.80.183

两台Web服务器  192.168.80.182   192.168.80.181


两台Web服务器部署:

        关闭防火墙及selinux

        yum install -y httpd

        vi /etc/httpd/conf/httpd.conf

        把ServerName 前面的注释符号去掉

        image.pngimage.png

启动httpd服务

            systemctl start httpd 


 浏览器测试:

image.png

image.png

到此 web服务器部署完成


haproxy服务器:

vi /etc/haproxy/haproxy.cfg到配置文件修改内容

最下面添加web设置

listen webcluster
        bind 0.0.0.0:80
        mode http
        option httpchk GET /index.html
        log global
        maxconn 3000
        balance roundrobin
server web01 192.168.80.181:80 check inter 2000 fall 5
server web02 192.168.80.182:80 check inter 2000 fall 5

重启haproxy服务 查看端口

        service haproxy restart


image.png


在浏览器测试 192.168.80.183:8089/stats

image.png


查看轮询:

image.png

点击浏览器的刷新或者F5刷新

image.png


到此haproxy负载均衡完成。