How to forward keepalived logs to a custom logfile with rsyslog in RHEL?
Environment
- Red Hat Enterprise Linux (RHEL)
- 7
- 8
rsyslog- Keepalived
Issue
- While using the default keepalived configuration, logs are set to
LOG_DAEMONwhich redirects output to/var/log/messages
Resolution
-
Create a custom syslog facility from one of those reserved for custom use (
local0tolocal7):# echo "local0.* /var/log/keepalived.log" > /etc/rsyslog.d/keepalived.conf -
Replace the
KEEPALIVED_OPTIONSconfiguration parameter at/etc/sysconfig/keepalived, adding the-S 0option to redirect
Keepalived log files to log facility 0:# sed -i 's|KEEPALIVED_OPTIONS="-D"|KEEPALIVED_OPTIONS="-D -d -S 0"|g' /etc/sysconfig/keepalived -
Restart
rsyslogand Keepalivedsystemctl restart rsyslog systemctl restart keepalived
Root Cause
Keepalived works using the default log levels, that will redirect information to /var/log/messages instead of a custom logfile or directory. With this configuration a custom local0 syslog facility is being set for Keepalived to write to.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments