logrotate管理nginx日志文件
2015-03-11 16:39
483 查看
转自:http://linux008.blog.51cto.com/2837805/555829/
描述:linux日志文件如果不定期清理,会填满整个磁盘。这样会很危险,因此日志管理是系统管理员日常工作之一。我们可以使用"logrotate"来管理linux日志文件,它可以实现日志的自动滚动,日志归档等功能。下面以nginx日志文件来讲解下logrotate的用法。
配置:
1、在/etc/logrotate.d目录下创建一个nginx的配置文件"nginx"配置内容如下
#vim /etc/logrotate.d/nginx
/usr/local/nginx/logs/*.log {
daily
rotate 5
missingok
notifempty
sharedscripts
postrotate
if [ -f /usr/local/nginx/logs/nginx.pid ]; then
kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
fi
endscript
}
mongodb截取日志
# mongodb-log rotate
/data/var/log/mongodb/mongod.log {
daily
dateext
rotate 30
copytruncate
missingok
}
logrotate -vf /etc/logrotate.d/mongodb-log
保存退出。
2、执行logrotate
#/usr/sbin/logrotate -f /etc/logrotate.d/nginx
在/usr/local/nginx/logs目录中会产生
error.log
error.log.1
说明logrotate配置成功。
3、让logrotate每天进行一次滚动,在crontab中添加一行定时脚本。
#crontab -e
59 23 * * * /usr/sbin/logrotate -f /etc/logrotate.d/nginx
每天23点59分进行日志滚动
4、配置文件说明
dateext:以日期为后缀
daily:日志文件每天进行滚动
rotate:保留最5次滚动的日志
notifempty:日志文件为空不进行滚动
copytruncate:保留种子日志
sharedscripts:运行postrotate脚本
下面是一个脚本
postrotate
if [ -f /usr/local/nginx/logs/nginx.pid ]; then
kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
fi
endscript
脚本让nginx重新生成日志文件。
描述:linux日志文件如果不定期清理,会填满整个磁盘。这样会很危险,因此日志管理是系统管理员日常工作之一。我们可以使用"logrotate"来管理linux日志文件,它可以实现日志的自动滚动,日志归档等功能。下面以nginx日志文件来讲解下logrotate的用法。
配置:
1、在/etc/logrotate.d目录下创建一个nginx的配置文件"nginx"配置内容如下
#vim /etc/logrotate.d/nginx
/usr/local/nginx/logs/*.log {
daily
rotate 5
missingok
notifempty
sharedscripts
postrotate
if [ -f /usr/local/nginx/logs/nginx.pid ]; then
kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
fi
endscript
}
mongodb截取日志
# mongodb-log rotate
/data/var/log/mongodb/mongod.log {
daily
dateext
rotate 30
copytruncate
missingok
}
logrotate -vf /etc/logrotate.d/mongodb-log
保存退出。
2、执行logrotate
#/usr/sbin/logrotate -f /etc/logrotate.d/nginx
在/usr/local/nginx/logs目录中会产生
error.log
error.log.1
说明logrotate配置成功。
3、让logrotate每天进行一次滚动,在crontab中添加一行定时脚本。
#crontab -e
59 23 * * * /usr/sbin/logrotate -f /etc/logrotate.d/nginx
每天23点59分进行日志滚动
4、配置文件说明
dateext:以日期为后缀
daily:日志文件每天进行滚动
rotate:保留最5次滚动的日志
notifempty:日志文件为空不进行滚动
copytruncate:保留种子日志
sharedscripts:运行postrotate脚本
下面是一个脚本
postrotate
if [ -f /usr/local/nginx/logs/nginx.pid ]; then
kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
fi
endscript
脚本让nginx重新生成日志文件。
相关文章推荐
- 使用logrotate管理nginx日志文件
- 使用logrotate管理nginx日志文件
- 使用logrotate管理nginx日志文件
- 使用logrotate管理nginx日志文件
- 使用logrotate管理nginx日志文件
- 在Linux系统中使用logrotate来管理日志文件的方法
- NGINX 日志文件切割及管理
- logrotate定时管理linux日志文件
- logrotate定时管理linux日志文件2
- 使用cron,logrotate来管理日志文件
- 使用cron,logrotate来管理日志文件
- logrotate管理分割nginx日志无效
- Linux的日志文件管理工具——logrotate(linux日志切割与轮循)
- 使用cron,logrotate来管理日志文件
- nginx日志管理之logrotate
- How to use logrotate to manage log files in linux(如何在Linux中使用logrotate去管理日志文件)
- linux之使用cron,logrotate管理日志文件
- 使用logrotate 管理日志文件 (Linux相关)
- 使用cron,logrotate来管理日志文件
- 使用cron,logrotate来管理日志文件