一.haproxy的基本部署
1.RS上装nginx
[root@webserver1 ~]# dnf install nginx -y
2.再RS上写入测试信息
[root@webserver1 ~]# echo webserver1 - 172.25.254.10 > /usr/share/nginx/html/index.html
[root@webserver1 ~]# systemctl enable --now nginx
[root@webserver2 ~]# echo webserver2 - 172.25.254.20 > /usr/share/nginx/html/index.html
[root@webserver2 ~]# systemctl enable --now nginx
3.测试
[root@haproxy ~]# curl 172.25.254.10
webserver1 - 172.25.254.10
[root@haproxy ~]# curl 172.25.254.20
webserver2 - 172.25.254.20
4.haproxy服务器下载haproxy软件并开启服务
[root@haproxy ~]# dnf install haproxy -y
[root@haproxy ~]# systemctl enable haproxy.service
5.写入代理配置参数
[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
以下两种写法均可
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend webcluster
bind *:80
mode http
use_backend webcluster-host
backend webcluster-host
balance roundrobin
server web1 172.25.254.10:80
server web2 172.25.254.20:80
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
listen webcluster
bind *:80
mode http
balance roundrobin
server web1 172.25.254.10:80
server web2 172.25.254.20:80
6.重启服务
[root@haproxy ~]# systemctl restart haproxy.service
7.测试
webserver1 - 172.25.254.10
[root@client ~]# curl 172.25.254.100
webserver2 - 172.25.254.20
[root@client ~]# curl 172.25.254.100
webserver1 - 172.25.254.10
[root@client ~]# curl 172.25.254.100
webserver2 - 172.25.254.20
[root@client ~]# curl 172.25.254.100
webserver1 - 172.25.254.10
[root@client ~]# curl 172.25.254.100
webserver2 - 172.25.254.20