环境:
haproxy:10.80.11.203
web1:10.80.11.206
web2:10.80.11.207
下载最新版本
# wget
http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.20.tar.gz
# tar zcvf haproxy-1.3.20.tar.gz
# cd haproxy-1.3.20
# make TARGET=linux26 PREFIX=/usr/local/haprpxy
# make install PREFIX=/usr/local/haproxy
# cd /usr/local/haproxy
# vim haproxy.cfg
global
log 127.0.0.1 local0
#log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 4096
chroot /usr/local/haproxy
uid 99
gid 99
daemon
nbproc 1
pidfile /usr/local/haproxy/haproxy.pid
#debug
#quiet
defaults
log 127.0.0.1 local3
mode http
option httplog
option httpclose
option dontlognull
option forwardfor
option redispatch
retries 2
maxconn 2000
balance roundrobin
stats uri /haproxy-stats
stats auth hx10:123456
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen web_proxy 0.0.0.0:80
option httpchk GET /check.htm
server s1 10.80.11.206:80 weight 3 check
server s2 10.80.11.207:80 weight 3 check
红色标记的意思是:
uid
gid 99 #日志文件的输出定向
option httplog #
负载均衡算法
stats auth hx10:123456
#
健康检测
重启
停止
状态截图如下:
balance roundrobin #负载均衡算法
stats uri /haproxy-status #haproxy 监控页面的访问地址
stats auth hx10:123456 查看监控页,输入的用户名和密码
listen web_proxy 0.0.0.0:80 #运行的端口及主机名
option httpchk GET /check.htm #健康检测
server s1 10.80.11.206:80 weight 3 check #web1
server s1 10.80.11.207:80 weight 3 check #web2
然后在web1和web2上添加/check.htm页面,内容任意
启动haproxy
# /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg
重启haproxy
# /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg -st `cat /usr/local/haproxy/haproxy.pid`
停止haproxy
# killall haproxy
状态截图如下:
http://10.80.11.203/haproxy-status