5 HAProxy 调度算法
HAProxy通过固定参数 balance
指明对后端服务器的调度算法,该参数可以配置在listen或backend选 项中。
HAProxy的调度算法分为静态和动态调度算法,但是有些算法可以根据不同的参数实现静态和动态算法 相互转换。
官方文档:http://docs.haproxy.org/3.0/configuration.html#4-balance
5.1 Socat 工具
对服务器动态权重和其它状态可以利用 socat 工具进行调整,Socat 是 Linux 下的一个多功能的网络工 具,名字来由是Socket CAT,相当于netCAT的增强版.Socat 的主要特点就是在两个数据流之间建立双向 通道,且支持众多协议和链接方式。如 IP、TCP、 UDP、IPv6、Socket文件等
范例:利用工具socat对服务器动态权重调整
# 安装socat
root@ubutun2204-1:~# apt update && apt -y install socat
#查看帮助
root@ubutun2204-1:~# echo "help" | socat stdio /var/lib/haproxy/haproxy.sock
The following commands are valid at this level:
abort ssl ca-file <cafile> : abort a transaction for a CA file
abort ssl cert <certfile> : abort a transaction for a certificate file
abort ssl crl-file <crlfile> : abort a transaction for a CRL file
add acl [@<ver>] <acl> <pattern> : add an acl entry
add map [@<ver>] <map> <key> <val> : add a map entry (payload supported instead of key/val)
add server <bk>/<srv> : create a new server
add ssl ca-file <cafile> <payload> : add a certificate into the CA file
add ssl crt-list <list> <cert> [opts]* : add to crt-list file <list> a line <cert> or a payload
clear acl [@<ver>] <acl> : clear the contents of this acl
clear counters [all] : clear max statistics counters (or all counters)
clear map [@<ver>] <map> : clear the contents of this map
clear table <table> [<filter>]* : remove an entry from a table (filter: data/key)
commit acl @<ver> <acl> : commit the ACL at this version
commit map @<ver> <map> : commit the map at this version
commit ssl ca-file <cafile> : commit a CA file
commit ssl cert <certfile> : commit a certificate file
commit ssl crl-file <crlfile> : commit a CRL file
debug dev hash [msg] : return msg hashed if anon is set
del acl <acl> [<key>|#<ref>] : delete acl entries matching <key>
del map <map> [<key>|#<ref>] : delete map entries matching <key>
del server <bk>/<srv> : remove a dynamically added server
del ssl ca-file <cafile> : delete an unused CA file
del ssl cert <certfile> : delete an unused certificate file
del ssl crl-file <crlfile> : delete an unused CRL file
del ssl crt-list <list> <cert[:line]> : delete a line <cert> from crt-list file <list>
disable agent : disable agent checks
disable dynamic-cookie backend <bk> : disable dynamic cookies on a specific backend
disable frontend <frontend> : temporarily disable specific frontend
disable health : disable health checks
disable server (DEPRECATED) : disable a server for maintenance (use 'set server' instead) #禁用服务器
dump stats-file : dump stats for restore
enable agent : enable agent checks
enable dynamic-cookie backend <bk> : enable dynamic cookies on a specific backend
enable frontend <frontend> : re-enable specific frontend
enable health :