logrotate 做日志收集处理

logrotate是一款日志管理工具,能自动轮转、压缩和删除旧日志,简化日志维护工作。文章介绍了logrotate的目录结构、配置文件以及常用配置选项,如设置转储间隔、压缩选项和日志文件创建。通过示例展示了Apache日志的配置和手动执行logrotate的方法。
摘要由CSDN通过智能技术生成

logrotate是一个日志文件管理工具。用来把旧文件轮转、压缩、删除,并且创建新的日志文件。

用好logrotate,就不用专门去写切割日志的脚本,去维护一个专门的crontab 了,方便实用。

1.logrotate的目录结构

主目录结构:

[root@test ~]# ll  /etc/|grep logrotate
-rw-r--r--.  1 root root     662 Aug 29  2007 logrotate.conf
drwxr-xr-x.  2 root root    4096 Sep 20 16:09 logrotate.d
[root@test ~]# 

子目录结构:

[root@test ~]# ll /etc/logrotate.d/
total 60
-rw-r--r--. 1 root root   71 Aug 17  2013 cups
-rw-r--r--. 1 root root  103 Dec  8  2011 dracut
-rw-r--r--. 1 root root  468 Aug 20 04:23 fail2ban
-rw-r--r--. 1 root root  307 Jul 10  2013 haproxy
-rw-r--r--. 1 root root  224 Sep 20 16:08 httpd
-rw-r--r--. 1 root root  871 Feb 13  2014 mysqld
-rw-r-----. 1 root named 170 Jan 21  2014 named
-rw-r--r--. 1 root root  256 Jun 10 05:08 puppet
-rw-r--r--. 1 root root  159 Mar 22  2013 puppet-dashboard
-rw-r--r--. 1 root root  131 Apr  1  2012 redis
-rwxr-xr-x. 1 root root  452 Jul 11 06:57 salt
-rw-r--r--. 1 root root   98 Apr 23  2007 supervisor
-rw-r--r--. 1 root root  210 Aug  3  2011 syslog
-rw-r--r--. 1 root root  100 Dec  9  2011 yum
-rw-r--r--. 1 root root  107 Jun 21 00:23 zabbix-server

logrotate.conf  通用的配置

1.rotate log files的时间间隔

2.backlogs 的保存时间

3.是否压缩文件等

等等

具体如下:

[root@test ~]# cat /etc/logrotate.conf 
# see "man logrotate" for details
# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# use date as a suffix of the rotated file
dateext

# uncomment this if you want your log files compressed
#compress

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# n
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值