基于动态算法,默认调度算法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 ~]#