[心缘地方]同学录
首页 | 功能说明 | 站长通知 | 最近更新 | 编码查看转换 | 代码下载 | 常见问题及讨论 | 《深入解析ASP核心技术》 | 王小鸭自动发工资条VBA版
登录系统:用户名: 密码: 如果要讨论问题,请先注册。

[备忘]nginx日志,切割,保留几天的,logrotate

上一篇:[备忘]nginx反向代理到域名地址时,报404错误的解决方法
下一篇:[GDS]Sabre的BFM里,Corp Id的使用

添加日期:2017/11/20 17:07:36 快速返回   返回列表 阅读2501次
nginx日志,切割,保留几天的
参考:https://linux.cn/article-4126-1.html
------------------
linux下默认有个logrotate这个东西,
nginx安装后,会自动生成一个文件:
/etc/logrotate.d/nginx

内容是:


/var/log/nginx/*log {
    create 0644 nginx nginx
    daily
    rotate 10
    missingok
    notifempty
    compress
    sharedscripts
    postrotate
        /bin/kill -USR1 `cat /run/nginx.pid 2>/dev/null` 2>/dev/null || true
    endscript
}



大概意思就是保留10天的日志,路径是/var/log/nginx/下的log文件

我把我的日志路径也放进去,
就是/data/logs/nginx/*log /var/log/nginx/*log
也就是空格分隔

就行了吧?这东西貌似就每天执行了。

---------------
logrotate -d /etc/logrotate.d/nginx

这是演戏一次

不带-d就是执行一次。
---------------------------------------
logrotate貌似不是零点执行的,

看这:
vim /etc/anacrontab


SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22

#period in days   delay in minutes   job-identifier   command
1       5       cron.daily              nice run-parts /etc/cron.daily
7       25      cron.weekly             nice run-parts /etc/cron.weekly
@monthly 45     cron.monthly            nice run-parts /etc/cron.monthly


应该改START_HOURS_RANGE这个就行吧?
 

评论 COMMENTS
没有评论 No Comments.

添加评论 Add new comment.
昵称 Name:
评论内容 Comment:
验证码(不区分大小写)
Validation Code:
(not case sensitive)
看不清?点这里换一张!(Change it here!)
 
评论由管理员查看后才能显示。the comment will be showed after it is checked by admin.
CopyRight © 心缘地方 2005-2999. All Rights Reserved