相關文章
linux Systemd詳解
linux log rotation日誌滾動詳解
/etc/init.d/functions運用實戰配置systemd nginx服務詳解
在配置system nginx服務後,對其nginx日誌進行自定義並定時備份清理。
1. 配置systemd配置文件
$ mkdir -p /etc/systemd/system/nginx.service.d/
$ vim etc/systemd/system/nginx.service.d/nginx.conf
[Service]
SyslogIdentifier=nginx
2. rsyslog配置單獨的日誌
$ vim /etc/rsyslog.d/nginx.conf
if $programname == "nginx" then /var/log/nginx/nginx.log
& stop
3. logrotate配置定時備份並清理策略
$ vim /etc/logrotate.d/nginx
/var/log/nginx/nginx.log {
weekly
rotate 8
missingok
notifempty
size 10M
create 0644 root root
}
4. 重啓服務
$ systemctl restart rsyslog
$ systemctl status nginx
5.查看日誌是否生效
$ cat /var/log/nginx/nginx.log
Jun 25 13:20:38 monitor1 nginx: /etc/rc.d/init.d/nginx: line 29: kill: /usr/local/nginx/sbin/nginx: arguments must be process or job IDs
Jun 25 13:20:38 monitor1 nginx: nginx is already running