系统版本:centos6.5_x64
软件版本:haproxy-1.5.9.tar.gz
后端服务器IP:10.10.10.5、10.10.10.6
这里提供haproxy的本站下载地址:wget -c http://www.rootop.org/rs/haproxy-1.5.9.tar.gz
安装:
[root@rootop-haproxy haproxy-1.5.9]# make TARGET=linux26 PREFIX=/usr/local/haproxy install
这里为什么是linux26,可以去看下README文档。
创建配置文件:
[root@rootop-haproxy ~]# mkdir /usr/local/haproxy/conf
[root@rootop-haproxy ~]# vi /usr/local/haproxy/conf/haproxy.cfg
global
log 127.0.0.1 local0 info
maxconn 1000
chroot /usr/local/haproxy
uid nobody
gid nobody
daemon
nbproc 1
pidfile /tmp/haproxy.pid
defaults
log global
mode http
option httplog
retries 3
option httpclose
option dontlognull
option forwardfor
option redispatch
log 127.0.0.1 local3
balance roundrobin
maxconn 20480
timeout connect 5000
timeout client 50000
timeout server 50000
timeout check 2000
stats enable
stats refresh 30s
stats uri /ha_check
stats hide-version
stats auth admin:admin
frontend http-in
bind *:80
mode http
option httplog
log global
default_backend http_pool
backend http_pool
balance roundrobin
option httpchk HEAD /index.html HTTP/1.0
cookie SERVERID insert indirect
server WEBSRV1 10.10.10.5:80 maxconn 1500 cookie SRV1 check inter 2000 rise 2 fall 3 weight 1
server WEBSRV2 10.10.10.6:80 maxconn 1500 cookie SRV2 check inter 2000 rise 2 fall 3 weight 1
启动服务:
[root@rootop-haproxy ~]# /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg
stats uri /status #监控页面
stats auth admin:admin #监控页身份认证
提供一个管理脚本:
#!/bin/bash
PROXY_CONF=/usr/local/haproxy/conf/haproxy.cfg
PROXY_BIN=/usr/local/haproxy/sbin/haproxy
CHECK_PROXY=$(ps aux | grep "haproxy -f" | grep -v grep | wc -l)
case $1 in
start)
if [ $CHECK_PROXY -ge 1 ]; then
echo "already running , exit"
exit
else
$PROXY_BIN -f $PROXY_CONF
if [ $? == 0 ]; then
echo "start ok"
else
echo "start failed"
fi
fi
;;
stop)
kill -9 $(cat /tmp/haproxy.pid)
if [ $? == 0 ]; then
rm -f /tmp/haproxy.pid && echo "stop ok"
else
echo "stop failed"
fi
;;
restart)
kill -9 $(cat /tmp/haproxy.pid)
if [ $? == 0 ]; then
rm -f /tmp/haproxy.pid && echo "stop ok"
else
echo "stop failed"
fi
$PROXY_BIN -f $PROXY_CONF
if [ $? == 0 ]; then
echo "start ok"
else
echo "start failed"
fi
;;
*)
echo "only start/stop/restart"
esac
exit
然后通过多个客户端访问haproxy的ip地址可以看到后端不同服务器提供的内容。
cookie SERVERID insert indirect 其中这句设置了会话保持,通过插入cookie方式,测试效果。
访问到服务器1:
访问到服务器2:
浏览器关闭后,会话断开。
荒野乱斗国际版 (BrawlStars)最新版本v56.274
下载一波超人内置修改器菜单版 安卓版v1.0.2
下载敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载继承了一座戏园子无限声望铜钱版 内置菜单最新版v1.7
继承了一座戏园子折相思版是游戏的破解版本,在该版本中为玩家提
山河半世橙光清软金手指版 无限鲜花v3.24
山河半世是一款超级好玩的橙光恋爱游戏,在游戏中玩家们需要扮演
蓬莱手游折相思版 安卓版v1.0.0
蓬莱免广告版是游戏的修改版本,在该版本中为玩家去除了广告,玩
当红影后橙光游戏破解版2025 最新版v1.0
当红影后橙光破解版是一款超级好玩的娱乐圈题材的橙光游戏,在这
忽然成了万人迷清软完结版 无限鲜花版v12.15
忽然成了万人迷破解版是一款非常好玩的男性向橙光游戏,在有一天