Especially, the following section seems interesting for you:
However, you should keep in mind that if you’re going to use a UNIX socket for logging and at the same time you are running HAProxy within a chrooted environment—or you let HAProxy create a chroot directory for you by using the chroot configuration directive—then the UNIX socket must be made available within that chroot directory. This can be done in one of two ways.
First, when rsyslog starts up, it can create a new listening socket within the chroot filesystem. Add the following to your HAProxy rsyslog configuration file:
but i still get same output on my 2 log file which is haproxy-traffic.log and haproxy-admin.log
both logfile same output
nano /var/log/haproxy-traffic.log
May 4 08:12:11 localhost haproxy[6486]: Proxy acpsapps started.
May 4 08:12:11 localhost haproxy[6486]: Proxy chopchopapps started.
May 4 08:12:11 localhost haproxy[6486]: Proxy no_route started.
May 4 08:24:06 localhost haproxy[6537]: Proxy main started.
May 4 08:24:06 localhost haproxy[6537]: Proxy main started.
May 4 08:24:06 localhost haproxy[6537]: Proxy t2apps started.
May 4 08:24:06 localhost haproxy[6537]: Proxy dtrapps started.
May 4 08:24:06 localhost haproxy[6537]: Proxy acpsapps started.
May 4 08:24:06 localhost haproxy[6537]: Proxy chopchopapps started.
May 4 08:24:06 localhost haproxy[6537]: Proxy no_route started.
May 4 08:25:57 localhost haproxy[6551]: Proxy main started.
May 4 08:25:57 localhost haproxy[6551]: Proxy main started.
May 4 08:25:57 localhost haproxy[6551]: Proxy t2apps started.
May 4 08:25:57 localhost haproxy[6551]: Proxy dtrapps started.
May 4 08:25:57 localhost haproxy[6551]: Proxy acpsapps started.
May 4 08:25:57 localhost haproxy[6551]: Proxy chopchopapps started.
nano /var/loghaproxy-admin.log
May 4 08:24:06 localhost haproxy[6537]: Proxy dtrapps started.
May 4 08:24:06 localhost haproxy[6537]: Proxy acpsapps started.
May 4 08:24:06 localhost haproxy[6537]: Proxy chopchopapps started.
May 4 08:24:06 localhost haproxy[6537]: Proxy no_route started.
May 4 08:25:57 localhost haproxy[6551]: Proxy main started.
May 4 08:25:57 localhost haproxy[6551]: Proxy main started.
May 4 08:25:57 localhost haproxy[6551]: Proxy t2apps started.
May 4 08:25:57 localhost haproxy[6551]: Proxy dtrapps started.
May 4 08:25:57 localhost haproxy[6551]: Proxy acpsapps started.
May 4 08:25:57 localhost haproxy[6551]: Proxy chopchopapps started.
i have modified some in my /etc/haproxy/haproxy.cfg and /etc/rsyslog.d/haproxy.conf
for haproxy.cfg
global
log 127.0.0.1:514 local0
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
user haproxy
group haproxy
daemon
stats socket /var/lib/haproxy/stats
master-worker
defaults
log global
mode http
timeout connect 5000
timeout client 50000
timeout server 50000
log-format "%ci:%cp [%tr] %ft %b/%s %Th/%Ti/%TR/%Tw/%Tc/%Tr/%Ta %ST %B %CC %CS %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %{+Q}r %[capture.req.hdr(0)]"
stats enable
stats hide-version
stats realm Haproxy Statistics
stats uri /haproxy_stats
stats auth admin:admin
frontend main
log 127.0.0.1 local0 notice
bind 192.168.50.250:80
use_backend t2apps if { hdr(host) -i t2apps.tailinsubic.server }
use_backend dtrapps if { hdr(host) -i dtr.tailinsubic.server }
use_backend acpsapps if { hdr(host) -i acps.tailinsubic.server }
use_backend chopchopapps if { hdr(host) -i chopchop.tailinsubic.server }
backend t2apps
balance roundrobin
server t2apps1 172.16.31.249:3000 check
server t2apps2 172.16.31.248:3000 check
backend dtrapps
balance roundrobin
server dtr1 172.16.31.241:5083 check
server dtr2 172.16.31.235:5084 check
backend acpsapps
balance roundrobin
server acps1 192.168.50.20:4070 check
backend chopchopapps
balance roundrobin
server chochop1 172.16.31.241:5084 check
server chopchop2 172.16.31.235:5083 check
for haproxy.conf
# Collect log with UDP
$ModLoad imudp
$UDPServerAddress 127.0.0.1
$UDPServerRun 514
# Creating separate log files based on the severity
local0.* /var/log/haproxy-traffic.log
local0.notice /var/log/haproxy-admin.log
then i created folder for admin.sock mkdir -p /run/haproxy/
when i restart two service haproxy.service and rsyslog.service it was successfully restarted with no errors
# 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
:programname, startswith, "haproxy" {
/var/log/haproxy.log
stop
}
I suggest you put all your logging configuration into your global/defaults section, more specifically I suggest you don’t reconfigure logging in your main frontend.
When you log via UDP sockets and you don’t know if haproxy doesn’t send the logs or rsyslog doesn’t put them into the right place, tcdpump it and check:
tcpdump -i lo -vvvvs0 udp port 514
You should put option httplog in your defaults.
If you filter syslog message at a specific level, then less important syslog message will not be send.
E.g. if you sepcify “notice” as your max-level, you will never see “info” level message (which is what connections logs have). You you need to make sure that you don’t filter those message, neither in haproxy and rsyslog.