下文给大家带来如何掌握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.测试状态页面:
看了以上关于如何掌握Haporxy负载均衡配置方法,如果大家还有什么地方需要了解的可以在亿速云行业资讯里查找自己感兴趣的或者找我们的专业技术工程师解答的,亿速云技术工程师在行业内拥有十几年的经验了。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。