Red Hat Enterprise Linux Diagnostics and Troubleshooting
Configure system logging to a central log host.
Outcomes
You should be able to centralize remote system logging to a central log host.
As the student user on the workstation machine, use the lab command to prepare your systems for this exercise.
[student@workstation ~]$ lab start baseline-remotelogging
This command confirms that your systems are reachable from the workstation machine.
Instructions
Configure the rsyslog service on servera to serve as a central log host. For more reliable syslog messages delivery, configure the central log host to accept messages from remote hosts using TCP.
Create a rule to organize syslog messages into subdirectories under /var/log/loghost. Create subdirectories by using the originating host name of each syslog message. Within each subdirectory, maintain a separate log file for each syslog facility. Configure log rotation for the new log files.
Configure serverb for remote logging to the central log host. Test the configuration by generating syslog messages from serverb. Verify that the generated messages are routed to the appropriate log file on servera.
Log in to
serveraand switch to therootuser.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#Verify that the
rsyslogservice is running and enabled to start at boot.[root@servera ~]#
systemctl is-active rsyslogactive [root@servera ~]#systemctl is-enabled rsyslogenabledConfigure the
rsyslogservice onserverato accept remote syslog messages with TCP, and that the messages are written to separate files that are named for the originating host and message facility.Enable TCP syslog reception in
/etc/rsyslog.confby uncommenting these lines in/etc/rsyslog.conf.module(load="imtcp") input(type="imtcp" port="514")
In the "#### RULES ####" section, add a
template()statement to organize log messages by host name and syslog facility. Below thetemplate()statement, create a rule to apply the template to all syslog messages.template(name="ExerciseTemplate" type="string" string="/var/log/loghost/%HOSTNAME%/%syslogfacility-text%.log") *.* action(type="omfile" DynaFile="ExerciseTemplate")Note
A
template()statement can span multiple lines for readability, if the statement's parameters are contained within the()parentheses.To apply the configuration changes, restart the
rsyslogservice.[root@servera ~]#
systemctl restart rsyslog
Add this entry to the
/etc/logrotate.d/syslogfile to add the new log files to the log rotation schedule./var/log/loghost/*/*.log
Modify the
serverafirewall to allow receiving incoming syslog messages from remote hosts on TCP port 514.Allow incoming packets on TCP port 514.
[root@servera ~]#
firewall-cmd --add-port=514/tcp --permanentsuccessTo apply the change, reload
firewalld.[root@servera ~]#
firewall-cmd --reload
From
workstation, open a new terminal. Login toserverband switch to therootuser.[student@workstation ~]$
ssh student@serverb...output omitted... [student@serverb ~]$sudo -i[sudo] password for student:student[root@serverb ~]#Configure
serverbto send syslog messages remotely toserverawith the TCP protocol.Create this rule in
/etc/rsyslog.confto send syslog messages toserverawith TCP port 514.*.* action(type="omfwd" target="servera" port="514" protocol="tcp")
To apply the change, restart the
rsyslogservice onserverb.[root@serverb ~]#
systemctl restart rsyslog
Verify that remote logging from
serverbto the central log host onserverais working.On
serverb, generate some syslog messages that use different facilities.[root@serverb ~]#
logger -p user.info "Test user.info message from serverb"[root@serverb ~]#logger -p cron.crit "Test cron.crit message from serverb"On
servera, verify that the syslog messages routed to the correct files in the/var/log/loghost/serverbdirectory.[root@servera ~]#
grep 'user\.info' /var/log/loghost/serverb/user.logDec 11 00:44:09 serverb root: Test user.info message [root@servera ~]#grep 'cron\.crit' /var/log/loghost/serverb/cron.logDec 11 00:44:40 serverb root: Test cron.crit message
Close the additional terminal session to
serverband return toworkstationas thestudentuser.[root@servera ~]#
exit[student@servera ~]$exit[student@workstation ~]$