Nginx common log splitting methods nginx apache nginx php nginx rewrite

WBOY
Release: 2016-07-29 08:55:15
Original
1257 people have browsed it
方式一: nginx cronolog日志分割配置文档,根据下面方法,每分钟分割一次NGINX访问日志。 1.nginx日志配置 access_log access_log /data/access_log_pipe main; 2.先创建一个命名管道 mkfifo /www/log/access_log_pipe 3.配置cronolog: nohup cat /data/access_log_pipe | /usr/local/sbin/cronolog /data/log/domain.access_%Y%m%d%H%M.log & 4.启动Nginx /usr/local/nginx/sbin/nginx 注意: cronolog必须在nginx启动前启动 没有安装cronolog的话,需要先安装 wget http://cronolog.org/download/cronolog-1.6.2.tar.gz tar zxvf cronolog-1.6.2.tar.gz cd cronolog-1.6.2 ./configure make make install 方式二: 定时任务中每小时添加定时任务,执行一下脚本,可以实现小时日志分割 log_dir="/var/log/nginx" date_dir=`date +%Y/%m/%d/%H` /bin/mkdir -p ${log_dir}/${date_dir} > /dev/null 2>&1 /bin/mv ${log_dir}/access.log ${log_dir}/${date_dir}/access.log kill -USR1 `cat /opt/nginx/logs/nginx.pid` 方式三: 使用logrotate做nginx日志轮询 logrotate看名字就知道是专门做日志轮询的,只把任务配置放在/etc/logrotate.d/下,任务就会自动完成,而且无需安装,系统自带,比较推荐使用. vi /etc/logrotate.d/nginx /usr/local/nginx/logs/www.willko.cn.log /usr/local/nginx/logs/nginx_error.log { notifempty daily sharedscripts postrotate /bin/kill -USR1 `/bin/cat /usr/local/nginx/nginx.pid` endscript } 多个日志以空格分开, notifempty 如果日志为空则不做轮询 daily 每天执行一次 postrotate 日志轮询后执行的脚本 这样,每天都会自动轮询,生成nginx.log.1-n 后话: 用Jmeter对方法一进行了测试,新建线程组:线程数200,循环150,新建http请求,请求nginx上的图片,请求30000次,失败326次,后台形成5个文件,行数如下: 2868 access_201112182030.log 7777 access_201112182031.log 7626 access_201112182032.log 7873 access_201112182033.log 3530 access_201112182034.log 29674 total 并没有因为切分文件而丢失日志。
Copy after login

The above introduces the common log splitting methods of Nginx, including nginx content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!