#vi haproxy.cfg
=========================
global
log 127.0.0.1 local3
maxconn 4096 #最大连接数
chroot /path/to/haproxy #安装目录
uid 535 #用户haproxy
gid 520 #组haproxy
daemon #守护进程运行
nbproc 1 #进程数量
pidfile logs/haproxy.pid
defaults
log 127.0.0.1 local3
mode http #layer 7代理
option httplog
option httpclose
option dontlognull
option forwardfor
retries 2
maxconn 2000
balance roundrobin
stats uri /haproxy-stats
contimeout 5000
clitimeout 50000
srvtimeout 50000
frontend http-in
bind *:90 #监听地址
default_backend pool1
backend pool1
option httpchk GET /test.php #用来做健康检查
stats refresh 2
server server1 192.168.1.1:82 weight 3 maxconn 32 check
server server2 192.168.1.2:82 weight 3 maxconn 32 check
===========================================
启动:sudo ./sbin/haproxy -f haproxy.cfg
重启:sudo ./sbin/haproxy -f haproxy.cfg -st `cat logs/haproxy.pid`
日志问题:有日志怎么也写不进去的,在这里分享下解决方案。
vi /etc/syslog.conf
添加 local3.* /var/log/haproxy.log
vi /etc/sysconfig/syslog
把SYSLOGD_OPTIONS="-m 0"
改成 SYSLOGD_OPTIONS="-r -m 0" #enables logging from remote machines
重启syslogd: /etc/init.d/syslog restart
tail -f -n 30 /var/log/haproxy.log 应该可以看到日志输出了。