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.在任意工作目录下,配置如下文件

Haproxy.conf代码

  1. global   
  2.     log 127.0.0.1 local0 info   
  3.     maxconn 10000  
  4.     ulimit-n 30000  
  5.   
  6. defaults   
  7.     log global   
  8.     mode http   
  9.   
  10. frontend pub-srv 0.0.0.0:8080  
  11.     maxconn 10000  
  12.     timeout client 40s   
  13.     use_backend websocket if { hdr(Upgrade) -i WebSocket }   
  14.     default_backend http   
  15.   
  16. backend websocket   
  17.     timeout connect 100s   
  18.     timeout server 600s   
  19.     server ws1 localhost:8084 weight 1 maxconn 5000 check   
  20.     server ws2 localhost:8085 weight 1 maxconn 5000 check   
  21.   
  22. backend http   
  23.     timeout connect 40s   
  24.     timeout server 30s   
  25.     server www1 localhost:8084 weight 1 maxconn 5000 check   
  26.     server www2 localhost:8085 weight 1 maxconn 5000 check  
  27. 5. 如果是public 80端口需要root权限执行,这里简单测试使用8080
  28. haproxy -f ./haproxy.conf
  29. 6. 日志输出在/var/log/haproxy.log下

    在另一台linux26机器上配置log如下,使用的是syslog

    vim /etc/sysconfig/syslog

    SYSLOGD_OPTIONS="-m 0 -r"

     

     

    添加-r参数

    -r:enables logging from remote machines

    vim /etc/syslog.conf

    添加如下内容:

    local0.* /var/log/haproxy.log

    /sbin/service syslog restart

    其他的配置内容步骤是一样的。