Linux中使用Systemd和Crontab实现日志轮转的方法和步骤
在Linux中,可使用Systemd和Crontab来实现日志轮转。下面是使用这两个工具来实现日志轮转的方法和步骤:
使用Systemd实现日志轮转的步骤:
/etc/systemd/system/logrotate.service。[Unit]
Description=Logrotate Service
[Service]
ExecStart=/usr/sbin/logrotate /etc/logrotate.conf/etc/systemd/system/logrotate.timer。[Unit]
Description=Logrotate Timer
[Timer]
OnCalendar=daily
AccuracySec=1h
Persistent=true
[Install]
WantedBy=timers.targetsudo systemctl start logrotate.service
sudo systemctl enable logrotate.timer使用Crontab实现日志轮转的步骤:
crontab -e0 3 * * * /usr/sbin/logrotate /etc/logrotate.conf不管你选择使用Systemd或Crontab,上述步骤都会定期履行日志轮转。你可以根据需要自定义日志轮转的时间和配置文件路径。
TOP