
环境
Client:192.168.19.104/24
HAproxy:192.168.19.103/24
web1:192.168.19.100/24
web2:192.168.19.102/24
1.HTML A & HTML B 创建测试页面
做好域名解析
systemctl stop firewalld && setenforce 0
ntpdate 时间服务器ip(略)
yum install httpd
echo web1 > /var/www/html/index.html
echo web2 > /var/www/html/index.html2.安装HAproxy
# yum install epel-release -y 
# yum install haproxy -y3.配置HAproxy
# vim /etc/haproxy/haproxy.cfg 
global
    log 127.0.0.1 local3 info
    maxconn 4096
        uid nobody
        gid nobody
    daemon
    nbproc 1
    pidfile /run/haproxy.pid
defaults
    log        global
    mode       http
    maxconn 2048
    retries     3
    option  redispatch
    contimeout  5000
    clitimeout      50000
    srvtimeout      50000
    option abortonclose
    stats uri /admin?stats
    stats realm Private lands
    stats auth admin:password
    stats hide-version
 
    
    
frontend http-in
    bind 0.0.0.0:80
    mode http
    log global
    option httplog
    option httpclose
     acl html url_reg  -i  \.html$
     use_backend html-server if  html
     default_backend html-server
backend html-server
    mode http
    balance roundrobin
    option httpchk GET /index.html
    cookie SERVERID insert indirect nocache
    server html-A web1:80 weight 1 cookie 3 check inter 2000 rise 2 fall 5
    server html-B web2:80 weight 1 cookie 4 check inter 2000 rise 2 fall 5解析:https://blog.51cto.com/u_15630500/5381905
systemctl start haproxy.service
4.测试结果
linux客户端

5.测试HAproxy状态
根据配置定义的地址
stats uri /admin?stats
stats realm Private lands
stats auth admin:passwordhttp://192.168.19.103/admin?status











