复制代码代码如下:vi /etc/logrotate.d/admin # This configuration is from VBird 2005/10/24 /var/log/admin.log { monthly size=10M rotate 5 nocompress sharedscripts prerotate /usr/bin/chattr -a /var/log/admin.log endscript sharedscripts postrotate /usr/bin/killall -HUP syslogd /usr/bin/chattr +a /var/log/admin.log endscript } 步骤3:测试
复制代码代码如下:# logrotate -v /etc/logrotate.conf .....(前面省略)..... rotating pattern: /var/log/admin.log10485760 bytes (5 rotations) empty log files are rotated, old logs are removed considering log /var/log/admin.log log does not need rotating not running shared prerotate script, since no logs will be rotated ............ # logrotate -vf /etc/logrotate.d/admin reading config file /etc/logrotate.d/admin reading config info for /var/log/admin.log 也就是说: /etc/syslog.conf 与/etc/logrotate.d/* 对应文档搭配起来使用;先由syslogd 按照syslog.conf指定的方法处理消息, 然后送给 logrotat来按照/etc/logrotate.d/*文档要求来轮替日志。 五、常见指令:
复制代码代码如下:# dmesg | more 读/var/log/boot.log
复制代码代码如下:dmesg | grep "eth"
复制代码代码如下:# last -n number [root@linux ~]# last -f filename -n :number -f :last 预设值为读 /var/log/wtmp 文档,而 -f 读取不同的文档
复制代码代码如下:# last -n 5 -f /var/log/wtmp.1 dmtsai2pts/2 Mon Oct 24 14:18 - 14:18(00:00) dmtsai2work:0 work Mon Oct 24 14:18gone - no logout dmtsai2work:0 work Mon Oct 24 14:18 - 14:18(00:00) dmtsai2pts/2 Mon Oct 24 14:18 - 14:18(00:00) dmtsai2work:0 work Mon Oct 24 14:18 - 14:18(00:00)</p><p># lastlog 只读取/var/log/lastlog 内容,只包括当前系统上面所有的帐号最近一次LOGIN的时间。