logratate日志切割的使用

本文详细介绍了如何在Linux系统中配置logrotate,包括查看默认配置、创建和编辑日志旋转规则,以及如何在crontab中添加定时任务以确保日志管理自动化。重点讲解了/home/tomcat/tomcat-dev/logs/catalina.out的日志管理实例。
摘要由CSDN通过智能技术生成

Linux的logrotate使用

1.进入/etc/logrotate.conf查看配置文件,下面包含了lograte.d文件,具体步骤参照第二步

# 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

# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
    monthly
    create 0664 root utmp
        minsize 1M
    rotate 1
}

/var/log/btmp {
    missingok
    monthly
    create 0600 root utmp
    rotate 1
}


2.进入/etc/logrotate.d/目录下创建配置文件,格式参照如下(也可在logrotate.conf文件中直接添加)

/home/tomcat/tomcat-dev/logs/catalina.out {
    missingok
    notifempty
    size 20000k
    copytruncate
    compress
    rotate 7
    daily
    dateext 
}

3.进入vim /etc/crontab,新增定时任务的cron表达式

0 0 * * * root run-parts /etc/cron.daily

3.重启项目服务器,定时任务生效

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值