centos(linux): logrotate是怎么触发日志轮询的?

一,通过查看crontab中的配置,没有logroate

1,查看crontab

[root@blog logrotate.d]# more /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed 

2,查看/etc/cron.daily

[root@blog etc]# ls /etc/cron.daily/

二,logrotate的服务状态:

查看logrotate.service的状态

[root@blog etc]# systemctl status logrotate.service
○ logrotate.service - Rotate log files
     Loaded: loaded (;;file://blog/usr/lib/systemd/system/logrotate.service/usr/lib/systemd/system/logrotate.service;;; static)
     Active: inactive (dead) since Thu 2024-09-19 00:00:30 CST; 15h ago
TriggeredBy: ● logrotate.timer
       Docs: ;;man:logrotate(8)man:logrotate(8);;
             ;;man:logrotate.conf(5)man:logrotate.conf(5);;
    Process: 822095 ExecStart=/usr/sbin/logrotate /etc/logrotate.conf (code=exited, status=0/SUCCESS)
   Main PID: 822095 (code=exited, status=0/SUCCESS)
        CPU: 25ms

Sep 19 00:00:30 iZ2zejc9t0hf6pnw6sewrxZ systemd[1]: Starting Rotate log files...
Sep 19 00:00:30 iZ2zejc9t0hf6pnw6sewrxZ systemd[1]: logrotate.service: Deactivated successfully.
Sep 19 00:00:30 iZ2zejc9t0hf6pnw6sewrxZ systemd[1]: Finished Rotate log files.

状态未激活,
但可以看到是由logratate.timer触发

查看logrotate.timer的状态

[root@blog etc]# systemctl status logrotate.timer
● logrotate.timer - Daily rotation of log files
     Loaded: loaded (;;file://blog/usr/lib/systemd/system/logrotate.timer/usr/lib/systemd/system/logrotate.timer;;; enabled; preset: enabled)
     Active: active (waiting) since Tue 2024-07-09 09:04:00 CST; 2 months 11 days ago
      Until: Tue 2024-07-09 09:04:00 CST; 2 months 11 days ago
    Trigger: Fri 2024-09-20 00:00:00 CST; 8h left
   Triggers: ● logrotate.service
       Docs: ;;man:logrotate(8)man:logrotate(8);;
             ;;man:logrotate.conf(5)man:logrotate.conf(5);;

Jul 09 09:04:00 AliYun systemd[1]: Started Daily rotation of log files.

可以看到这个timer触发的服务是logrotate.service,
而且它的状态是active的

说明logrotate是使用Systemd timer模式来触发服务

posted @ 2024-09-19 15:50  刘宏缔的架构森林  阅读(50)  评论(0编辑  收藏  举报