do you have any idea about exceeding 10GB "/var/log/syslog.1", "/var/log/kern.log.1",…
- User
do you have any idea about exceeding 10GB "/var/log/syslog.1", "/var/log/kern.log.1", "/var/log/ufw.log.1" files?
show cli command to fix them.
- Assistant
do you have any idea about exceeding 10GB "/var/log/syslog.1", "/var/log/kern.log.1", "/var/log/ufw.log.1" files?
show cli command to fix them.
When system log files such as /var/log/syslog.1, /var/log/kern.log.1, or /var/log/ufw.log.1 exceed 10GB in size, it typically means that logs are not being rotated properly, or there are excessive logging events being generated. This can quickly consume disk space and potentially impact system performance.
Below are steps and associated commands to handle such situations.
Before taking any action, understand what’s contributing to the excessive logging. Use tools such as tail, head, or less.
sudo tail -n 50 /var/log/syslog.1
sudo tail -n 50 /var/log/kern.log.1
sudo tail -n 50 /var/log/ufw.log.1
You can also search for the most frequent log patterns:
sudo cat /var/log/syslog.1 | awk '{print $6}' | sort | uniq -c | sort -rn | head -10
If disk space is critically low, you can truncate the offending log files to free up space:
sudo truncate -s 0 /var/log/syslog.1
sudo truncate -s 0 /var/log/kern.log.1
sudo truncate -s 0 /var/log/ufw.log.1
This will reset the file size to 0 bytes but will not fix the root cause.
Log files are typically managed by logrotate. If logs grow indefinitely, it may indicate an issue with the logrotate configuration.
Check if /etc/logrotate.d/ contains rotation configurations for the files.
cat /etc/logrotate.d/rsyslog
You should see configurations such as:
/var/log/syslog
{
rotate 7
daily
missingok
notifempty
compress
delaycompress
postrotate
/usr/lib/rsyslog/rsyslog-rotate
endscript
}
If missing or improperly configured, edit the file using a text editor (e.g., nano) and fix it.
Run logrotate manually to confirm it's working as expected:
sudo logrotate -vf /etc/logrotate.conf
Excessive log generation is often caused by overly verbose settings in system services such as rsyslog, ufw, etc.
rsyslog Configuration:Check and modify /etc/rsyslog.conf to reduce logging verbosity. For example, change log levels to info or warn instead of debug (depending on your needs).
sudo nano /etc/rsyslog.conf
Restart the rsyslog service after making changes:
sudo systemctl restart rsyslog
If ufw.log is large, check and reduce logging levels for UFW:
sudo ufw logging low
Alternatively, disable UFW logging entirely:
sudo ufw logging off
Some recurring log entries might signify configuration issues or hardware/software failures.
Search for recurring errors:
sudo grep -i "error" /var/log/syslog.1 | less
/etc/<service>/<service>.conf.If you've truncated logs, updated configurations, or made changes, restart the associated services:
sudo systemctl restart rsyslog
sudo systemctl restart ufw
To prevent log files from growing excessively in the future, use monitoring tools like du to check directory sizes regularly or set up alerts with a monitoring system such as Prometheus or Nagios.
sudo du -sh /var/log/*
# Free up space (truncate logs)
sudo truncate -s 0 /var/log/syslog.1
sudo truncate -s 0 /var/log/kern.log.1
sudo truncate -s 0 /var/log/ufw.log.1
# Check and fix logrotate
cat /etc/logrotate.d/rsyslog
sudo logrotate -vf /etc/logrotate.conf
# Adjust logging level
sudo nano /etc/rsyslog.conf
sudo systemctl restart rsyslog
# Reduce UFW logging level
sudo ufw logging low
By performing the above steps, you can address the immediate issue and prevent excessive log sizes in the future.