1.系统是默认安装的,查看系统是否安装logrotate

centos

rpm -ql logrotate

/etc/cron.daily/logrotate
/etc/logrotate.conf
/etc/logrotate.d
/etc/rwtab.d/logrotate
/usr/sbin/logrotate
/usr/share/doc/logrotate-3.8.6
/usr/share/doc/logrotate-3.8.6/CHANGES
/usr/share/doc/logrotate-3.8.6/COPYING
/usr/share/man/man5/logrotate.conf.5.gz
/usr/share/man/man8/logrotate.8.gz
/var/lib/logrotate
/var/lib/logrotate/logrotate.status

ubuntu

logrotate --version

logrotate 3.14.0
Default mail command: /usr/bin/mail
Default compress command: /bin/gzip
Default uncompress command: /bin/gunzip
Default compress extension: .gz
Default state file path: /var/lib/logrotate/status
ACL support: yes
SELinux support: yes

2.docker配置日志截取

创建文件

/etc/docker/daemon.json

内容

{

"log-driver": "json-file",

"log-opts": {

"max-size": "500m",

"max-file": "3"

}

}

max-size 指定日志文件大小上限

max-file 指定日志文件个数

systemctl daemon-reload

systemctl restart docker.service

3.创建logrotate 配置文件,系统会自动创建 crontab 任务自动执行

/etc/logrotate.d/nginx

/work/nginx/logs/*log {
su root root
create 0644 root root
daily #每天执行一次
rotate 365 #保留365个日志文件
missingok #如果日志丢失,不报错继续滚动下一个日志
notifempty #当日志文件为空时不生成新的文件
compress #压缩
sharedscripts #统一执行一次脚本postrotate
postrotate #运行脚本
docker exec nginx nginx -s reload;
endscript
}

手动测试logrotate

 logrotate -d -f /etc/logrotate.d/nginx

 -d, --debug :debug模式,测试配置文件是否有错误。
-f, --force :强制转储文件。

4.推荐博客:

https://www.cnblogs.com/kevingrace/p/6307298.html

最新文章

  1. 修改js confirm alert 提示框文字的简单实例
  2. Prime Time使用
  3. SQL基础--索引
  4. 手动关闭searchDisplayControlelr
  5. POJ 1986 Distance Queries(Tarjan离线法求LCA)
  6. Benefits of Cold Showers: 7 Reasons Why Taking Cool Showers Is Good For Your Health
  7. 序列化和持久化 merge方法和saveOrUpdate方法
  8. 百度Echarts使用心得
  9. 用于Lucene的各中文分词比较
  10. .net Windows服务程序和安装程序制作图解
  11. python_原始_web框架
  12. [学习OpenCV攻略][011][显示图片]
  13. 简易仿ios菊花加载loading图
  14. 《生命》第五集:Birds (鸟类)
  15. php 获取 两个时间戳之间 相隔 【多少年】 【 多少个月】 【多少天】 【 多少个小时】 【多少分】【 多少秒 】
  16. 实现本地svn目录同步时,服务器的相应目录保持自动同步
  17. 03 字符串常用操作方法及For 循环
  18. web新手——新闻列表这样写不容易出错
  19. 【黑客免杀攻防】读书笔记5 - PE格式讲解
  20. [数据]matplotlib总结

热门文章

  1. SQLSERVER 的主键索引真的是物理有序吗?
  2. 【rabbitmq】单独配置某一个消费者手动ack,其他消费者自动ack
  3. 基于Linux下的Ubuntu操作系统常用命令
  4. Ubuntu 22.04 安装 utools 时的疑难杂症
  5. 算法竞赛向 C++ Standard Library 使用速查
  6. BUG日记---运行Tomcat报406错误:根据请求中接收到的主动协商头字段,目标资源没有用户代理可以接受的当前表示,而且服务器不愿意提供缺省表示。
  7. MySQL 如何实现数据插入
  8. SpringBoot 学习 step.3数据库
  9. Linux云服务器安装jdk、Tomcat、MySQL5.7
  10. Portainer功能使用之系统管理