nginx日志切割

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介:

发现nginx的日志没有正常的切割

cat logrotate.d/nginx

1
2
3
4
5
6
7
8
/home/log/nginx1 .0.11/*.log{
     daily
     rotate 30
     copytruncate
     missingok
     notifempty
     compress
}

参照http://wiki.nginx.org/LogRotation

1
2
3
4
mv  access.log access.log.0
kill  -USR1 ` cat  master.nginx.pid`
sleep  1
gzip  access.log.0     # do something with access.log.0

nginx 提供了USR1信号 可重新打开日志

逐修改cat logrotate.d/nginx为

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/home/log/nginx1 .0.11/*.log{
     daily         #每日
     rotate 30     #保留30天的
     copytruncate    #用于还在打开中的日志文件,把当前日志备份并截断
     missingok      #找不到log文件也继续
     notifempty     #如果文件为空不转储
     compress      #压缩
     dateext      #用日期做归档日志的扩展名
postrotate       #post脚本开始
     if  [ -f  /var/run/nginx .pid ];  then
         kill  -USR1 ` cat  /var/run/nginx .pid`
     fi
endscript           #post脚本结束
}

执行

1
/usr/sbin/logrotate  -f  /etc/logrotate .d /nginx

查看日志归档正常

############################nginx信号#############################################

TERM, INT

Quick shutdown

快速关闭

QUIT

Graceful shutdown

从容关闭

HUP

Configuration reload Start the new worker  processes with a new configuration

Gracefully shutdown the old worker  processe

重载配置

用新的配置开始新的工作进程

从容关闭旧的工作进程

USR1

Reopen the log files

重新打开日志文件

USR2

Upgrade Executable on the fly

平滑升级可执行程序。

WINCH

Gracefully shutdown the worker processes

从容关闭工作进程



      本文转自天山三害 51CTO博客,原文链接:http://blog.51cto.com/skybug/1346529,如需转载请自行联系原作者






相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
相关文章
|
3天前
|
应用服务中间件 nginx
nginx error日志 client intended to send too large body: 1434541 bytes 如何处理?
【8月更文挑战第27天】nginx error日志 client intended to send too large body: 1434541 bytes 如何处理?
16 6
|
8天前
|
应用服务中间件 Linux nginx
在Linux中,如何统计ip访问情况?分析 nginx 访问日志?如何找出访问页面数量在前十位的ip?
在Linux中,如何统计ip访问情况?分析 nginx 访问日志?如何找出访问页面数量在前十位的ip?
|
13天前
|
存储 监控 应用服务中间件
查看nginx日志文件
器性能和提高网站可用性。掌握日志文件的路径、查看方法和基本分析技能对于任何服务器管理员来说都是必备技能。
32 1
|
16天前
|
存储 Ubuntu 应用服务中间件
如何在 Ubuntu VPS 上配置 Nginx 的日志记录和日志轮转
如何在 Ubuntu VPS 上配置 Nginx 的日志记录和日志轮转
13 4
|
24天前
|
存储 应用服务中间件 nginx
部署ELK+filebeat收集nginx日志
部署ELK+filebeat收集nginx日志
部署ELK+filebeat收集nginx日志
|
18天前
|
应用服务中间件 Linux nginx
Nginx log 日志文件较大,按日期生成 实现日志的切割
Nginx log 日志文件较大,按日期生成 实现日志的切割
79 0
|
24天前
|
应用服务中间件 nginx
[nginx]日志中记录自定义请求头
[nginx]日志中记录自定义请求头
|
24天前
|
应用服务中间件 Shell nginx
shell分析nginx日志的一些指令
shell分析nginx日志的一些指令
|
24天前
|
应用服务中间件 Shell Linux
使用logrotate定期切割nginx日志
使用logrotate定期切割nginx日志
|
2月前
|
应用服务中间件 Linux 开发工具
Nginx14---目录结构分析,查看Ngnix访问日志命令的写法​
Nginx14---目录结构分析,查看Ngnix访问日志命令的写法​
下一篇
云函数