似乎有不少童鞋不知道这个小功能,至少,上周面试了3位,大都是自己写脚本来处理日志的滚动压缩。
因此,分享到这里,熟悉的童鞋请忽略。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
举例说明:
cat
<<_CONF >
/etc/logrotate
.d
/haproxy
/var/log/haproxy/haproxy
.log
{
compress
copytruncate
daily
dateext
missingok
notifempty
rotate 2
}
_CONF
上述将增加一个logrotated的配置文件
/etc/logrotate
.d
/haproxy
然后使用logrotate的默认设置来做日志滚动压缩:
/etc/logrotate
.conf
也可以手动调用:
假设我们的配置文件放在:
/data/log/logrotate
.d
/haproxy
然后,在计划任务中配置:
59 23 * * *
/usr/sbin/logrotate
-f
/data/log/logrotate
.d
/haproxy
|
其实,,如果你愿意深入琢磨一下,你会发现,我写的不咋样,仅是简单的一个示例。
接下来,请看看yum安装haproxy自带的版本是啥样的:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
[root@10-0-201-2 ~]
# cat /etc/logrotate.d/
dracut haproxy haproxy.rpmnew iscsiuiolog syslog yum
[root@10-0-201-2 ~]
# cat /etc/logrotate.d/haproxy
/var/log/haproxy/haproxy
.log
{
compress
copytruncate
daily
dateext
missingok
notifempty
rotate 2
}
[root@10-0-201-2 ~]
# cat /etc/logrotate.d/haproxy.rpmnew
/var/log/haproxy
.log {
daily
rotate 10
missingok
notifempty
compress
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
}
|
本文转自 pcnk 51CTO博客,原文链接:http://blog.51cto.com/nosmoking/1636362,如需转载请自行联系原作者