那你可以怎么样设定呢?呵呵~很简单啊!看看底下的动作吧!
# 1.
先½立
+a
这个属
性啊!
[root@study ~]#
chattr +a /var/log/admin.log
[root@study ~]#
lsattr /var/log/admin.log
-----
a
----------
/var/log/admin.log
[root@study ~]#
mv /var/log/admin.log /var/log/admin.log.1
mv: cannot move
`/var/log/admin.log' to `/var/log/admin.log.1': Operation not permitted
#
里确定了加入
a
性!所以
root
法移
此登
录档
# 2.
始½立
logrotate
的配置文件,增加一
文件
/etc/logrotate.d
了!
[root@study ~]#
vim /etc/logrotate.d/admin
# This configuration is from VBird 2015/08/19
/var/log/admin.log {
monthly
<==
½
行一次
size=10M
<==
文件
容量大于
10M
则开
rotate 5
<==
保留五
compress
<==
½
压缩
工作!
sharedscripts
prerotate
/usr/bin/chattr
-
a /var/log/admin.log
endscript
sharedscripts
postrotate
/bin/kill
-
HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
/usr/bin/chattr +a /var/log/admin.log
endscript
}
# 3.
测试
一下
logrotate
功能的信息
示:
[root@study ~]#
logrotate
-
v /etc/logrotate.conf
....(
前面省略
)....
rotating pattern: /var/log/admin.log 10485760 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 prerotate
script, since no logs will be rotated
not running postrotate script, since no logs were rotated
....(
底下省略
)....
#
为还
不足一
月,
文件
有大于
10M
,所以不需
½
替!
# 4.
测试
一下
logrotate
与相
功能的信息
示:
[root@study ~]#
logrotate
-
vf /etc/logrotate.d/admin
reading config file
/etc/logrotate.d/admin