Haproxy not logging with rsyslog
Asked Answered
R

3

8

I want to setup HTTP logging in HAProxy and am having some trouble getting it to output the requests correctly.

Here is the HAProxy relevent configuration:

global
    log /dev/log    local0
    log /dev/log    local1 notice
    maxconn 200000
    tune.ssl.default-dh-param 2048
    user haproxy
    group haproxy
    daemon
    stats socket /tmp/sock1 user root group root mode 777 level admin

defaults
    log    global
    mode    http
    option    httplog
    option    dontlognull
        option httpclose
    retries    3
    option redispatch
    maxconn    200000
    backlog 20000
    timeout connect    5s
    timeout client    50s
    timeout server    180000
    balance    roundrobin
    cookie    SERVERID rewrite 

Here is the /etc/rsyslog.d/haproxy.conf file:

# Create an additional socket in haproxy's chroot in order to allow logging via
# /dev/log to chroot'ed HAProxy processes
$AddUnixListenSocket /var/lib/haproxy/dev/log

# Send HAProxy messages to a dedicated logfile
if $programname startswith 'haproxy' then /var/log/haproxy.log
&~ 

I've restarted both haproxy and rsyslogd after making the proper changes to make sure that they were picked up. The /var/log/haproxy.log isn't even being created. Any help would be appreciated.

Rolanda answered 28/10, 2014 at 18:42 Comment(2)
if solution worked for you, please mark it answered. It helps.Altricial
Apparently, &~ is deprecated (version 8.24 is what I'm using; likely it was deprecated starting with v7). Replace with &stop and the deprecation messages will cease. See rsyslog.com/doc/v8-stable/compatibility/v7compatibility.htmlCup
F
7

The rsyslog configuration assumes a chroot'd HAProxy, which does not match the haproxy config. Either chroot HAProxy by adding the line

    chroot  /var/lib/haproxy

to the global stanza of the haproxy config, or change the location of the socket rsyslog creates

$AddUnixListenSocket /dev/log
Ferd answered 11/2, 2015 at 18:57 Comment(0)
T
4

I had the exact same issue on Ubuntu 16.04. Tried restarting haproxy and syslog and /var/log/haproxy.log was still not created.

I ended up just restarting the server and /var/log/haproxy.log was created on boot up.

Tuberculous answered 1/8, 2017 at 2:30 Comment(1)
That saved my afternoon. Thanks!Airiness
H
2

Under global change/add:

global
    chroot  /var/lib/haproxy
    log /var/lib/haproxy/dev/log    local0
    log /var/lib/haproxy/dev/log    local1 notice
    ... rest of your file
Hideaway answered 25/11, 2015 at 10:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.