HAProxy, "The Reliable, High Performance TCP/HTTP Load Balancer"
使用HAProxy负载若干python websocket实例,安装完HAProxy后,默认情况下,HAProxy为了节省读写IO所消耗的性能,默认情况下没有日志输出,以下是我配置log的过程:
Fedora16 默认使用的是rsyslog管理log
可通过以下shell来检查:
#rpm -q sysklogd syslog-n rsyslog
package sysklogd is not installed
package syslog-n is not installed
rsyslog-5.8.7-1.fc16.i686
#rpm -ql rsyslog | grep conf$
/etc/rsyslog.conf
1.
vim /etc/rsyslog.conf
添加local0.* /var/log/haproxy.log
这里对路径如果修改为/home/xinz/haproxytest/log目录下,由于rsyslog默认情况下,没有访问home目录下的权限,可以参考:
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# grep rsyslogd /var/log/audit/audit.log | audit2allow -M mypol
# semodule -i mypol.pp
2.
rsyslog 默认情况下,需要在514端口监听UDP,所以可以把/etc/rsyslog.conf如下的注释去掉
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
3.重启 rsyslog
service rsyslog restart
service rsyslog status
4.在任意工作目录下,配置如下文件
global
log 127.0.0.1 local0 info
maxconn 10000
ulimit-n 30000
defaults
log global
mode http
frontend pub-srv 0.0.0.0:8080
maxconn 10000
timeout client 40s
use_backend websocket if { hdr(Upgrade) -i WebSocket }
default_backend http
backend websocket
timeout connect 100s
timeout server 600s
server ws1 localhost:8084 weight 1 maxconn 5000 check
server ws2 localhost:8085 weight 1 maxconn 5000 check
backend http
timeout connect 40s
timeout server 30s
server www1 localhost:8084 weight 1 maxconn 5000 check
server www2 localhost:8085 weight 1 maxconn 5000 check
5. 如果是public 80端口需要root权限执行,这里简单测试使用8080
haproxy -f ./haproxy.conf
6. 日志输出在/var/log/haproxy.log下
在另一台linux26机器上配置log如下,使用的是syslog
1.
vim /etc/sysconfig/syslog
SYSLOGD_OPTIONS="-m 0 -r"
添加-r参数
-r:enables logging from remote machines
2.
vim /etc/syslog.conf
添加如下内容:
local0.* /var/log/haproxy.log
3.
/sbin/service syslog restart
其他的配置内容步骤是一样的
reference links:
http://linuxadminzone.com/enable-or-fix-logging-for-haproxy-load-balancer/
http://kevin.vanzonneveld.net/techblog/article/haproxy_logging/
http://code.google.com/p/haproxy-docs/wiki/Logging#Examples_of_logs