haproxy配置httpd负载均衡
haproxy配置方法见haproxy配置及使用
环境
系统/主机名 | ip |
redhat 8 /LB | 192.168.100.134 |
redhat 8 /RS1 | 192.168.100.132 |
redhat 8 /RS2 | 192.168.100.133 |
配置
//在两台RS上安装httpd # yum -y install httpd //关闭防火墙和selinux # systemctl stop firewalld # setenforce 0 //修改第二台RS的监听端口 [root@RS2 ~]# vim /etc/httpd/conf/httpd.conf ... Listen 8080 //RS启动并设置开机自启httpd # systemctl enable --now httpd //创建测试页面 [root@RS1 ~]# echo "RS1" > /var/www/html/index.html [root@RS2 ~]# echo "RS2" > /var/www/html/index.html //关闭LB的防火墙和selinux # systemctl stop firewalld # setenforce 0 //修改LB的 haproxy配置文件 ---添加这两个主机IP和端口号 # vim /etc/haproxy/haproxy.cfg ... server web01 192.168.100.132:80 check inter 2000 fall 5 server web02 192.168.100.133:8080 check inter 2000 fall 5 //重启haproxy # pkill haproxy # systemctl start haproxy //访问测试 [root@LB ~]# curl 192.168.100.134 RS1 [root@LB ~]# curl 192.168.100.134 RS1 [root@LB ~]# curl 192.168.100.134 RS2 [root@LB ~]# curl 192.168.100.134 RS2 [root@LB ~]# curl 192.168.100.134 RS1 [root@LB ~]# curl 192.168.100.134 RS2 [root@LB ~]# curl 192.168.100.134 RS1 [root@LB ~]# curl 192.168.100.134 RS2
登录网页haproxy查看负载(登陆方式见haproxy配置及使用)