How to forward keepalived logs to a custom logfile with rsyslog in RHEL?

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux (RHEL)
    • 7
    • 8
  • rsyslog
  • Keepalived

Issue

  • While using the default keepalived configuration, logs are set to LOG_DAEMON which redirects output to /var/log/messages

Resolution

  1. Create a custom syslog facility from one of those reserved for custom use (local0 to local7):

        # echo "local0.*  /var/log/keepalived.log" > /etc/rsyslog.d/keepalived.conf
    
  2. Replace the KEEPALIVED_OPTIONS configuration parameter at /etc/sysconfig/keepalived, adding the -S 0 option 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 
    
  3. Restart rsyslog and Keepalived

        systemctl 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