Exercise: Logs and time review
Prepare servera for a new application: a journal that survives reboots, a log file of its own that rotates, and a clock set to the right zone with an extra time source.
Logs and time review
- Make the journal persistent with a size limit.
- Create an rsyslog rule and a logrotate rule for an application.
- Set the time zone and add an NTP source.
Before you start: reset the servers and complete this chapter's lessons. You work on servera as root (sudo -i); lab start and lab grade run on workstation.
On servera:
- Make the journal persistent: create
/var/log/journaland a drop-in/etc/systemd/journald.conf.d/10-retention.confwithStorage=persistentandSystemMaxUse=100M. Restartsystemd-journaldand runjournalctl --flush. - Write
/etc/rsyslog.d/10-appserver.confso that facilitylocal6(all priorities) goes to/var/log/appserver.log. Restart rsyslog, then send the messagedrill completeto it withlogger. - Write
/etc/logrotate.d/appserverto rotate that file weekly, keep 6 copies and compress them. - Set the time zone to
Asia/Colombo, addserver 0.pool.ntp.org iburstto/etc/chrony.conf, and restart chronyd. - On workstation, fill in
answers.txt.
Start the exercise
[student@workstation ~]$ lab start sa-logs-review
[student@workstation ~]$ cd ~/sa-logs-review
[student@workstation sa-logs-review]$ ssh student@servera
[student@servera ~]$ sudo -i
[root@servera ~]#Journal and application log
[root@servera ~]# mkdir -p /var/log/journal /etc/systemd/journald.conf.d
[root@servera ~]# printf '[Journal]\nStorage=persistent\nSystemMaxUse=100M\n' > /etc/systemd/journald.conf.d/10-retention.conf
[root@servera ~]# systemctl restart systemd-journald
[root@servera ~]# journalctl --flush
[root@servera ~]# echo 'local6.* /var/log/appserver.log' > /etc/rsyslog.d/10-appserver.conf
[root@servera ~]# systemctl restart rsyslog
[root@servera ~]# logger -p local6.notice "drill complete"
[root@servera ~]# cat /var/log/appserver.log
Oct 3 17:20:11 servera root[2301]: drill completeRotation
[root@servera ~]# cat > /etc/logrotate.d/appserver <<'EOT'
/var/log/appserver.log {
weekly
rotate 6
compress
missingok
notifempty
create 0640 root root
}
EOT
[root@servera ~]# logrotate -d /etc/logrotate.d/appserver 2>&1 | tail -3Do not force a rotation with -f before grading: it would move the drill message out of the live file.
Time zone and time source
[root@servera ~]# timedatectl set-timezone Asia/Colombo
[root@servera ~]# echo 'server 0.pool.ntp.org iburst' >> /etc/chrony.conf
[root@servera ~]# systemctl restart chronyd
[root@servera ~]# sleep 10; chronyc sources | head -6
[root@servera ~]# exit
[student@servera ~]$ exitAnswers and grade
On workstation, fill in answers.txt and grade:
Check your work with lab grade sa-logs-review, then put the exercise away with lab finish sa-logs-review.