Enable logging in Haproxy.
HAProxy Log Setup
“log <address> <facility> [max level [min level]]”
Note:- Adds a global syslog server. Up to two global servers can be defined. They will receive logs for startups and exits, as well as all logs from proxies configured with "log global”.
<address> can be one of:
- An IPv4 address optionally followed by a colon and a UDP port. If no port is specified, 514 is used by default (the standard syslog port).
- A filesystem path to a UNIX domain socket, keeping in mind considerations for chroot (be sure the path is accessible inside the chroot) and uid/gid (be sure the path is appropriately writeable).
<facility> must be one of the 24 standard syslog facilities :
kern user mail daemon auth syslog lpr news
uucp cron auth2 ftp ntp audit alert cron2 local0 local1 local2 local3 local4 local5 local6 local7
An optional level can be specified to filter outgoing messages. Eight levels are known :
emerg alert crit err warning notice info debug
Example:-
log global
log 127.0.0.1:514(default port) local0 notice # only send important events
log 127.0.0.1:514(default port) local0 notice notice # same but limit output level
Note:- For performance & maintenance reasons HAProxy doesn't log directly to files. Instead it wants to log against a syslog server. This is a separate Linux daemon that most servers are equiped with already, but HAProxy requires it to listen on UDP port 514 (Default Port), and usually that's not enabled.
HAProxy Log Enable for Centos/RHEL machine:-
vim /etc/rsyslog/haproxy.conf
add these lines #Basically this enable all type of logs .
# Enable UDP port 514 to listen to incoming log messages from haproxy
$ModLoad imudp
$UDPServerRun 514
$template Haproxy,"%msg%\n"
local0.crit -/var/log/haproxy.log;Haproxy #For Critical log only
#local0.=info -/var/log/haproxy/haproxy.log;Haproxy # this line enable log everything.
local0.notice -/var/log/haproxy/admin.log;Haproxy
# don't log anywhere else
local0.* ~
Restart rsyslog service.
#For Logrotation.
Add these lines in /etc/logrotaion.d/haproxy
2. /var/log/haproxy.log {3
daily
rotate 10
missingok
notifempty
compress
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
/bin/kill -HUP `cat /var/run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true
endscript
}
Reference:-
Note:-
Observation :-
var/log/haproxy.log
{
missingok
daily
rotate 10
copytruncate
compress
dateext
dateformat %Y%m%d%s
}
|
Comments
Post a Comment