logrotate没有rotate的排查过程
前言
方式一、Crontab模式
systemctl status cron.service
#cat /etc/crontab
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
Dec 8 06:25:01 (root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ))
#!/bin/sh # skip in favour of systemd timer
if [ -d /run/systemd/system ]; then
exit 0
fi # this cronjob persists removals (but not purges)
if [ ! -x /usr/sbin/logrotate ]; then
exit 0
fi /usr/sbin/logrotate /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit $EXITVALUE
因为我的squid的定时切割是每天,所以需要/etc/cron.daily;同样可以手动执行(bash -x logrotate)一次这个脚本,看是否能成功,在这里,发现我的脚本在执行第一个检查的时候这一步退出了;然后花了大量的时候查找为什么会做这一步检查,后来经过网上的搜索发现/run/systemd/system这个目录下放着与时间相关的Systemd任务,所以这一步的判断是为了检测是否用了方式二Systemd timer做了定时任务,如果有这个目录,则不再做Crontab的定时任务;
# bash -x /etc/cron.daily/logrotate
if [ -d /run/systemd/system ]; then
exit 0
fi
● logrotate.service - Rotate log files
Loaded: loaded (/lib/systemd/system/logrotate.service; static; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2021-12-08 00:00:03 +08; 16h ago
TriggeredBy: ● logrotate.timer
Docs: man:logrotate(8)
man:logrotate.conf(5)
Main PID: 2811680 (code=exited, status=1/FAILURE) Dec 08 00:00:01 systemd[1]: Starting Rotate log files...
Dec 08 00:00:03 logrotate[2811680]: error: failed to rename /usr/squid/logs/access.log to /usr/squid/logs/access.log-20211208: Read-only file system
方式二:Systemd模式
● logrotate.service - Rotate log files
Loaded: loaded (/lib/systemd/system/logrotate.service; static; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2021-12-08 00:00:03 +08; 16h ago
TriggeredBy: ● logrotate.timer
Docs: man:logrotate(8)
man:logrotate.conf(5)
Main PID: 2811680 (code=exited, status=1/FAILURE) Dec 08 00:00:01 systemd[1]: Starting Rotate log files...
Dec 08 00:00:03 logrotate[2811680]: error: failed to rename /usr/squid/logs/access.log to /usr/squid/logs/access.log-20211208: Read-only file system
[Unit]
Description=Rotate log files
Documentation=man:logrotate(8) man:logrotate.conf(5)
ConditionACPower=true [Service]
Type=oneshot
ExecStart=/usr/sbin/logrotate /etc/logrotate.conf # performance options
Nice=19
IOSchedulingClass=best-effort
IOSchedulingPriority=7 # hardening options
# details: https://www.freedesktop.org/software/systemd/man/systemd.exec.html
# no ProtectHome for userdir logs
# no PrivateNetwork for mail deliviery
# no ProtectKernelTunables for working SELinux with systemd older than 235
# no MemoryDenyWriteExecute for gzip on i686
PrivateDevices=true
PrivateTmp=true
ProtectControlGroups=true
ProtectKernelModules=true
ProtectSystem=full
RestrictRealtime=true
ReadWritePaths=/usr/squid/logs
● logrotate.timer - Daily rotation of log files
Loaded: loaded (/lib/systemd/system/logrotate.timer; enabled; vendor preset: enabled)
Active: active (waiting) since Thu 2021-08-05 11:08:00 +08; 4 months 3 days ago
Trigger: Thu 2021-12-09 00:00:00 +08; 7h left
Triggers: ● logrotate.service
Docs: man:logrotate(8)
man:logrotate.conf(5)
[Unit]
Description=Daily rotation of log files
Documentation=man:logrotate(8) man:logrotate.conf(5) [Timer]
OnCalendar=daily
AccuracySec=12h
Persistent=true
#Unit:真正要执行的任务,默认是同名的带有.service后缀的单元 [Install]
WantedBy=timers.target
待加强的知识点
1)anacron与cron的区别?
2)systemd创建定时任务与Cron创建定时任务的区别,优缺点?
3)systemd的配置以及整个systemd需要加强理解,系统学习
4)crontab定时任务的系统学习
5)logrotate系统的学习,配置等
6)看logrotate源码,用Python或Go模拟
最后
欢迎大家关注我的公众号,一起交流、学习。

logrotate没有rotate的排查过程的更多相关文章
- 一次kibana服务失败的排查过程
公司在kubernetes集群上稳定运行数月的kibana服务于昨天下午突然无法正常提供服务,访问kibana地址后提示如下信息: 排查过程: 看到提示后,第一反应肯定是检查elasticsearch ...
- 记一次生产环境Nginx日志骤增的问题排查过程
摘要:众所周知,Nginx是目前最流行的Web Server之一,也广泛应用于负载均衡.反向代理等服务,但使用过程中可能因为对Nginx工作原理.变量含义理解错误,或是参数配置不当导致Nginx工作异 ...
- 干货!一次kafka卡顿事故排查过程
由于一次功能上线后,导致某数据量急剧下滑,给我们紧张的呢!排查过程也是个学习过程(这其中有大部分是领导们的功劳,不过分享给大家应该也不犯法吧,ᐓ) 1. 确认问题的真实性? 被数据部门告知,某数据量下 ...
- Linux(2)---记录一次线上服务 CPU 100%的排查过程
Linux(2)---记录一次线上服务 CPU 100%的排查过程 当时产生CPU飙升接近100%的原因是因为项目中的websocket时时断开又重连导致CPU飙升接近100% .如何排查的呢 是通过 ...
- 神奇的Java僵尸(defunct)进程问题排查过程
现象描述 大概1个月多以前 在启动脚本中增加了tail -f 用来启动后追踪日志判断是否启动成功 后发现无法执行shutdown.sh(卡住 利用curl) 然后无奈使用kill -9 但通过ps - ...
- Connection refused 排查过程
Connection refused 排查过程 connection refused 排查 起因 今天在连接 rabbitmq 时,报 Connection refused (如下图),借此机会记 ...
- 解Bug之路-记一次中间件导致的慢SQL排查过程
解Bug之路-记一次中间件导致的慢SQL排查过程 前言 最近发现线上出现一个奇葩的问题,这问题让笔者定位了好长时间,期间排查问题的过程还是挺有意思的,正好博客也好久不更新了,就以此为素材写出了本篇文章 ...
- 解Bug之路-记一次存储故障的排查过程
解Bug之路-记一次存储故障的排查过程 高可用真是一丝细节都不得马虎.平时跑的好好的系统,在相应硬件出现故障时就会引发出潜在的Bug.偏偏这些故障在应用层的表现稀奇古怪,很难让人联想到是硬件出了问题, ...
- JDBC连接泄露问题的排查过程总结
当前使用的Spring JDBC版本是5.0.0.RC1,HikariCP版本是3.1.0. 今天测试同学反馈在前端页面点击次数多了,就报500错误,数据显示不出来.于是我在后台服务日志中观察发现Hi ...
随机推荐
- VMware Workstation 无法连接到虚拟机。请确保您有权运行该程序、访问该程序使用的所有目录以及访问所有临时文件目录。 VMware Authorization Service 当前未运行
VMware Workstation 无法连接到虚拟机.请确保您有权运行该程序.访问该程序使用的所有目录以及访问所有临时文件目录. VMware Authorization Service 当前未运行 ...
- 一行导出所有任意微软SQL server数据脚本-基于Python的微软官方mssql-scripter工具使用全讲解
文章标题: 一行导出所有任意微软SQL serer数据脚本-基于Python的微软官方mssql-scripter工具使用全讲解 关键字 : mssql-scripter,SQL Server 文章分 ...
- 印象最深的一个bug:sessionStorage缓存在移动端失效
无bug,不程序:作为程序员的我,不是修bug就是在写bug的路上. 移动端sessionStorage缓存失效是我"印象最深的一个bug"之一,为啥呢,因为这个问题导致我加班到很 ...
- 植物GO注释
本文主要是对没有GO term库的植物进行注释. 1.选用AgriGo 进行注释,在agriGO中点击species后,查看与你目标物种相近的物种作为库 2.比如我以甜菜为例 为了找到和GO term ...
- python-django-分页处理
每个模型都有一个管理器,Manager 通过分页可以先加载一部分的数据内容,然后避免大量的查询带来的等待时间 应用场景是,排行榜,前十条或者 for i in range(100): ...: ... ...
- php操作mongodb手册地址
php操作mongodb手册地址: http://php.net/manual/zh/class.mongocollection.php
- Demo01无重复数字
package 习题集2;//有1,2,3,4四个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?public class Demo1 { public static void main(S ...
- 前端4 — jQuery — 更新完毕
1.下载jQuery 网址:Download jQuery | jQuery 最好下载最新版的,因为有什么bug问题,最新版的都会有,所以学技术就用最新版的,实际开发用的时候就要讲究了 2.开始用j ...
- addict, address, adequate
addict Addiction is a biopsychosocial disorder characterized by repeated use of drugs, or repetitive ...
- day07 ORM中常用字段和参数
day07 ORM中常用字段和参数 今日内容 常用字段 关联字段 测试环境准备 查询关键字 查看ORM内部SQL语句 神奇的双下划线查询 多表查询前提准备 常用字段 字段类型 AutoField in ...