Haporxy 負載均衡配置

vim /etc/haproxy/haproxy.cfg
global
    log         127.0.0.1 local2    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon
    stats socket /var/lib/haproxy/stats

defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3    timeout http-request    10s    timeout queue           1m    timeout connect         10s    timeout client          1m    timeout server          1m    timeout http-keep-alive 10s    timeout check           10s
    maxconn                 3000

frontend  main *:80
    use_backend webserver 

frontend  stats_ser  #定義stats前端
    bind *:8800      #定義stats監聽端口
    use_backend web_stats

backend webserver
    balance    roundrobin 
    cookie WEBSVR insert nocache 
    server  web1 192.168.199.126:80 weight 1 maxconn 500 maxqueue 300 cookie cklser1 check 
    server  web2 192.168.199.194:80 weight 1 maxconn 500 maxqueue 300 cookie cklser2 check 
    server  web3 192.168.199.180:80 weight 1 maxconn 500 maxqueue 300 cookie cklser3 check 

backend web_stats
    server web1 192.168.199.126:80 check
    server web2 192.168.199.194:80 check
    server web3 192.168.199.180:80 check
    stats enable   #開啓stats功能
    stats hide-version #隱藏haproxy版本信息,有益於安全
    #stats scope   .   #做用當前域
    stats uri     /ckl?stats  #stats頁面的uri
    stats realm   Haproxy\ Statistics  #備註信息
    stats auth    ckl:1QAZnji9  #用戶名密碼
    stats auth    zld:4rfvBHU8  #用戶名密碼
    stats auth    admin:7uj4rf99  #用戶名密碼
    stats admin if TRUE #不添加此項,則不開啓管理員功能
    stats refresh 5s #頁面刷新間隔

10.2.從新加載服務前端

systemctl restart haproxy.service

10.3.測試狀態頁面:web

wKioL1ht5_2SmRNGAAA7cir4J6A090.png-wh_50

wKioL1hvP4Cw1MkBAAGAL8i-joU048.png-wh_50

相關文章
相關標籤/搜索