Logging for HAProxy on CentOS 5.x

HAProxy requires syslogd/rsyslogd listening for incoming connections for his logging purposes.

Basic configuration looks like this:

# haproxy.conf

global
log 127.0.0.1 local5 debug

# syslog.conf

[...]
local5.* /var/log/haproxy.log

# /etc/sysconfig/syslog

[...]
SYSLOGD_OPTIONS="-m 0 -r"
[...]

It is critical that syslog is accessible by network (udp port 514, you can use 127.0.0.1 as ip address). To check if syslog is listening, use:

# netstat -lp | grep syslog

udp 0 0 0.0.0.0:514 0.0.0.0:* 24001/syslogd

You can bind syslog only to localhost or provide firewall to avoid exposing the daemon to the network.

References:

4 thoughts on “Logging for HAProxy on CentOS 5.x

  1. Thanks a lot, That’s something i needed.

    Now i can see all log in log file.
    # tail -220f /var/log/haproxy.log

    Nov 12 04:35:13 127.0.0.1 haproxy[4143]: Stopping frontend httpid in 0 ms.
    Nov 12 04:35:13 127.0.0.1 haproxy[4143]: Proxy stats stopped (FE: 0 conns, BE: 0 conns).
    Nov 12 04:35:13 127.0.0.1 haproxy[4143]: web-server stopped (FE: 0 conns, BE: 0 conns).
    Nov 12 04:35:13 127.0.0.1 haproxy[4143]: Proxy httpid stopped (FE: 0 conns, BE: 0 conns).

    but i want to configure Haproxy for logs in HTTP log format.But i gone through manual , i did following changes in HAproxy configuration.

    # haproxy.cfg
    ——————————————-
    backend dmb-dmbadminweb-server
    balance roundrobin
    option redispatch
    option httpclose
    option forwardfor
    server server-A : weight 1 maxconn 20000 check inter 4000

    frontend httpid
    bind *:2020
    mode http
    option httplog
    log global
    default_backend web-server
    —————————————————————–

    when I’m hitting web-server via Haproxy , it is only logging only as i shon above.

    I am expecting logs like :

    Feb 6 12:14:14 localhost \
    haproxy[14389]: 10.0.1.2:33317 [06/Feb/2009:12:14:14.655] http-in \
    static/srv1 10/0/30/69/109 200 2750 – – —- 1/1/1/1/0 0/0 {1wt.eu} \
    {} “GET /index.html HTTP/1.1”

    • I’m not sure the default settings will redirect the connections to syslog, try changing “log global” to “log 127.0.0.1 local5 info” (if you set up syslog as in my example) or “log 127.0.0.1 local5 debug”.

      Also, why your backend is named dmb-dmbadminweb-server and referenced as web-server?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s