1

Cant understand, how it logging? Now my log is empty and haproxy doesnt write anything to file. Sometimes it logs some info, Logging works with syslog-ng, if i set in haproxy conf timeout client about 1s, then logging works sometimes. Is logging can affect the recording logs? Sorry. Forgot about config. I'm trying to load balance sybase jdbc.

  • defaults
    • mode tcp
    • timeout connect 5s
    • timeout client 50000
    • timeout server 50000
    • option dontlognull
    • option redispatch
    • retries 3
    • maxconn 4096
  • frontend Sybase
    • bind *:2638
    • mode tcp
    • option tcplog
    • log global
    • log-format [%t]\ from\ %ci:%cp\ to\ %fi:%fp\ %si:%sp\ %s\ %ts\ request_size=%U\ response_size=%B
    • default_backend Sybase
    • backend Sybase
    • mode tcp
    • log global
    • option tcplog
  • balance leastconn
  • server base_1 sybase:2638 check
    • server base_2 sybase:2638 check
user3904465
  • 11
  • 1
  • 2
  • 6

1 Answers1

4

To have these messages end up in - for example - /var/log/haproxy.log you will need to do two things:

  • configure your syslog to accept network logs - at least on localhost
  • configure haproxy to send events to 127.0.0.1 on local2/local3 or any such facility

So, your haproxy.cfgs global section would look something like:

global
    log         127.0.0.1 local2 notice
    log         127.0.0.1 local3

While your syslog.conf should look like:

local2.*        /var/log/haproxy
local3.*        /var/log/haproxy-access_log

If you use modern distro with rsyslog, then just create a file called

/etc/rsyslog.d/haproxy.conf

with following contents:

$ModLoad imudp
$UDPServerAddress 127.0.0.1
$UDPServerRun 514

local2.*        /var/log/haproxy
local3.*        /var/log/haproxy-access_log

And after that restart rsyslogd and haproxy.

the-wabbit
  • 40,737
  • 13
  • 111
  • 174
Jakov Sosic
  • 5,267
  • 4
  • 24
  • 35
  • I'm using sles, and syslog-ng, i've setup logging in it. Sometimes, logs not writing, or haproxy write log after client dissconected. I dont need rsyslog :) – user3904465 Nov 11 '14 at 12:57
  • You have to log through syslog instance - wether it's rsyslog, sysklogd or syslog-ng - it's irrelevant. HaProxy will send logs via UDP socket to syslog implementation you use, an you have to set up your syslog to accept and write logs to actual files. If you need help with syslog-ng, I can extend my answer with syslog-ng configuration you need. – Jakov Sosic Nov 11 '14 at 13:01
  • Here is my settings in syslog-ng - source s_udp { udp(ip(127.0.0.1) port(514)); }; destination d_haproxy { file("/var/log/haproxy"); }; filter f_local0 { facility(local0); }; log { source(s_udp); filter(f_local0); destination(d_haproxy); }; – user3904465 Nov 11 '14 at 13:04
  • Change your facility from local0 to the one you use in your haproxy.cfg. Also, check if you have iptables set up blocking traffic on firewall set up. – Jakov Sosic Nov 11 '14 at 13:07
  • Also, it would be good if you can post sanitized configs of both syslog-ng and haproxy in OP. – Jakov Sosic Nov 11 '14 at 13:07
  • Yes i'm using right facility. Not understand what does it mean "in OP"? – user3904465 Nov 11 '14 at 13:16
  • I prefer syslog sockets instead of network connections, but that's the way to go. – Phillipp Mar 05 '16 at 20:35
  • I'm using rsyslog to try to gather haproxy logs, I have edited my conf files like you did, iptables is disabled, the log file is created; but nothing is written inside, even after a restart of both HAProxy and rsyslog ... I also have the good configuration in /etc/logrotate.d. I checked over and over the configuration, i'm in the same channel (local2) and I'm restrincting all this to the local loop (127.0.0.1). Did I miss something ? thx – Alex Apr 11 '17 at 09:54