Logrotate to remove logs in Linux

There is a great app in Linux called Logrotate which is used to manage logs in your Linux server. Through below steps, you are expected to save a log of space for your Xen server. Edit once, save space forever! -_-
 
Two files need to be modified according your system requirement. They are /etc/logrotate.conf and /etc/logrotate.d/syslog.
 
Step1. Edit rotate and compress value under /etc/logrtotate.conf. Below is sample of logrotate.conf file.
 
# see "man logrotate" for details
# CA-53139: rotate log files daily
daily
# CA-53139: compress old logfiles.
compress
 
# keep 20MB of logfiles
rotate 1 ----------------------------------Modify rotate value to “1”. the default value of rotate is 20.
 
# create new (empty) log files after rotating old ones
create
 
# uncomment this if you want your log files compressed
Compress------------------------------uncomment “Compress”. That means all rotated log will be compressed.
 
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
 
# no packages own wtmp -- we'll rotate them here
/var/log/wtmp {
    monthly
    minsize 1M
    create 0664 root utmp
    rotate 1
}
 
Step2. Add /var/log/xenstored-access.log before brace{. xenstored-access.log in Xen server produced a log of logs each day. Please see below content:
 
/var/log/crit.log /var/log/kern.log /var/log/daemon.log /var/log/user.log /var/log/messages /var/log/secure /var/log/maillog /var/log/spooler /var/log/boot.log /var/log/cron /var/log/xenstored-access.log {
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
        /bin/kill -HUP `cat /var/run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true
    endscript
}
 
Step3. Execute immediately. Logrotate �Cvf /etc/logrotate.conf.  You would see that log files are correctly rotated in your system.

你可能感兴趣的:(linux,false)