nginx使用logrotate对日志进行分割
2016-07-21 19:56
1116 查看
系统环境
ubuntu 14.04LTSnginx 1.4.7
编辑logrotate下的nginx文件
$ vim /etc/logrotate.d/nginx /usr/local/nginx/logs/*.log { //log的位置 su root list //使用root权限 ,如果不使用的话 可能会报权限有关的问题 后面有提到 daily //每天运行一次 missingok //如果日志文件丢失,不报错继续执行下一个 rotate 7 //日志保存7天 dateext //文件后缀是日期格式,也就是切割后文件是:xxx.log-20131216.gz 这样,如果注释掉,切割出来是按数字递增,即前面说的 xxx.log-1 这种格式 notifempty //如果是空文件的话,不转储 create 0640 root root //日志文件的权限 sharedscripts prerotate if [ -d /etc/logrotate.d/httpd-prerotate ]; then \ run-parts /etc/logrotate.d/httpd-prerotate; \ fi \ endscript postrotate [ -s /run/nginx.pid ] && kill -USR1 `cat /run/nginx.pid` endscript }
//后面带日期的文件生成了,表示成功了
测试
$ /usr/sbin/logrotate -f /etc/logrotate.d/nginx //如果生成了文件则表示配置成功
添加到crontab
//每天12点10分执行一次 10 12 * * * /usr/sbin/logrotate -f /etc/logrotate.d/nginx
错误处理
可能会报这个错,如果没有加su root list...insecure permissions (It's world writable or writable by group which is not... ...error: skipping "/usr/local/nginx/logs/access.log" because parent directory...
相关文章推荐
- Ubuntu 默认壁纸历代记
- Ubuntu Remix Cinnamon 20.04 评测:Ubuntu 与 Cinnamon 的完美融合
- 关于Ubuntu 11.10启动提示waiting for the network configuration的问题
- 在 Ubuntu 桌面中使用文件和文件夹
- nginx代理指定目录
- ubuntu下chrome无法同步问题解决
- 访问Nginx发生SSL connection error的一种情况
- Ubuntu Linux使用体验
- 使用 GNOME 优化工具自定义 Linux 桌面的 10 种方法
- 以Ubuntu 9.04为例 将工作环境迁移到 Linux
- Nginx+Naxsi部署专业级Web应用防火墙
- VirtualBox虚拟机XP与宿主机Ubuntu互访共享文件夹
- 从USB安装Ubuntu Server 10.04.3 图文详解
- Ubuntu 15.04 正式版发布下载
- Linux-Ubuntu 10.04安装Cadence-ic610 方法总结图解
- CentOS 6.2实战部署Nginx+MySQL+PHP
- Ubuntu 12.04和Windows 7双系统安装图解
- Ubuntu /home下中文目录如何修改成英文?
- 开机出现:grub rescue的修复方法
- Ubuntu连接Android真机调试