nginx日志切割

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
nginx日志切割方式一
[root@weixinxiaochengxu ~]# crontab -l
01 05 * * * ntpdate -u 10.100.60.6
#Ansible: nginx-logcut
0 0 * * * /bin/sh /opt/nginx_logcut.sh 2>&1 > /dev/null
#Ansible: nginx-logdel
1 0 * * * /bin/sh /opt/nginx_logdel.sh 2>&1 > /dev/null
[root@weixinxiaochengxu ~]# cat /opt/nginx_logcut.sh
#!/bin/bash
nginxpiddir=/usr/local/nginx/logs
nginxlogpath=/storage/nginx/logs
mv $nginxlogpath/access.log $nginxlogpath/access_`date +%Y-%m-%d`.log
mv $nginxlogpath/error.log $nginxlogpath/error_`date +%Y-%m-%d`.log
kill -USR1 `cat $nginxpiddir/nginx.pid`
 
[root@weixinxiaochengxu ~]# cat /opt/nginx_logdel.sh
#!/bin/bash
rm -rf /storage/nginx/logs/access_`date -d "-30 day" "+%Y-%m-%d"`.log
rm -rf /storage/nginx/logs/error_`date -d "-30 day" "+%Y-%m-%d"`.log
<br><br><br>
nginx日志切割方式二  logrotate
/storage/nginx-logs/*.log {
daily
missingok
rotate 60
compress
delaycompress
dateext
notifempty
sharedscripts
postrotate
  if [ -f /var/run/nginx.pid ]; then
    /bin/kill -USR1 `cat /var/run/nginx.pid`
  fi
endscript
}

  

posted @   yuanbangchen  阅读(1356)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类
点击右上角即可分享
微信分享提示