haproxy socat工具上线和下线后端服务器脚本
Posted y_zilong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了haproxy socat工具上线和下线后端服务器脚本相关的知识,希望对你有一定的参考价值。
基于动态算法,默认调度算法roundrobin
[root@cen7_27 ~]# cat /etc/haproxy/conf.d/test.cfg
listen web_port_80
bind 10.0.0.27:80
mode http
balance roundrobin
server 10.0.0.40 10.0.0.40:80 check inter 3000 fall 2 rise 5
server 10.0.0.50 10.0.0.50:80 check inter 3000 fall 2 rise 5
[root@cen7_27 ~]#
[root@cen7_27 ~]# cat haproxy_host_up_down.sh
#!/bin/bash
. /etc/init.d/functions
case $1 in
up)
echo "set weight web_port_80/$2 1" |socat stdio /var/lib/haproxy/haproxy.sock
[ $? -eq 0 ] && action "$2 is up"
;;
down)
echo "set weight web_port_80/$2 0" |socat stdio /var/lib/haproxy/haproxy.sock
[ $? -eq 0 ] && action "$2 is down"
;;
*)
echo "Usage: `basename $0` up|down IP"
;;
esac
[root@cen7_27 ~]# chmod +x haproxy_host_up_down.sh
[root@cen7_27 ~]# bash haproxy_host_up_down.sh down 10.0.0.40
10.0.0.40 is down [ OK ]
[root@cen7_27 ~]# bash haproxy_host_up_down.sh up 10.0.0.40
10.0.0.40 is up [ OK ]
[root@cen7_27 ~]#
以上是关于haproxy socat工具上线和下线后端服务器脚本的主要内容,如果未能解决你的问题,请参考以下文章