利用工具socat 对服务器动态权重调
安装socat包
[root@localhost src]# yum install socat.x86_64 -y
查看版本信息
[root@localhost haproxy]# echo "show info" | socat stdio /var/lib/haproxy/haproxy.sock
查看服务器速率
[root@localhost haproxy]# echo "show servers state" | socat stdio /var/lib/haproxy/haproxy.sock
查看权值 默认为1
[root@localhost haproxy]# echo "get weight webs1/web1" | socat stdio /var/lib/haproxy/haproxy.sock
1 (initial 1)
设置权值
[root@localhost haproxy]# echo "set weight webs1/web1 3" | socat stdio /var/lib/haproxy/haproxy.sock
基于cookie的会话保持
配置示例
验证cookie信息
示例
backend webpool1
balance roundrobin
mode http
default-server inter 1000 weight 6
cookie WEBSRV insert nocache indirect
server web1 192.168.184.145:80 check cookie web1
server web2 129.168.184.173:80 check cookie web2
验证
动静分离
# vim /etc/haproxy/conf.d/text.cfg
frontend http
bind :888
option http-keep-alive
timeout http-keep-alive 30s
log global
acl static path_beg -i /static
acl static path_reg -i ^/.+.(js|css|ico|gif|bmp|jpg|jpeg|png|swf|cur|html)$
acl dynamic path_beg -i /dynamic
acl dynamic path_reg -i ^/.+.(php|jsp|html)$
use_backend static_pool if static
use_backend dynamic_pool if static
default_backend dynamic_pool
backend static_pool
server s 192.168.184.173:80 check
backend dynamic_pool
server d 192.168.184.145:80 check
注:启动前需要把刚写的配置文件路径加到系统文件中# vim /usr/lib/systemd/system/haproxy.service