#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 應該可以看到日志輸出了。