`
masterkey
  • 浏览: 337740 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Nginx and Cronolog (zz)

阅读更多

Nginx and Cronolog

I recently setup Nginx for one of our webservers and needed to hook cronolog up to it for all the normal reasons you want cronolog.

But Nginx doesn't support piped logging yet :( But we can use fifo's though to accomplish the same thing :)

  1. Configure nginx.conf to log to logs/access.log and logs/error.log like normal.
  2. Remove those files from the logs directory.
  3. Recreate them as fifo's using "mkfifo access.log" and "mkfifo error.log".
  4. Tweak the nginx startup script to start cronolog just before nginx.

Something like this:

(cat /usr/local/nginx/logs/access.log |\
/usr/local/sbin/cronolog -l /var/log/nginx/access.log \
/var/log/nginx/%Y/%m/%d/%H/access.log) &
(cat /usr/local/nginx/logs/error.log |\
/usr/local/sbin/cronolog -l /var/log/nginx/error.log \
/var/log/nginx/%Y/%m/%d/%H/error.log) &


That's it. It seems that you'd need to stop cronolog when shutting down nginx, but at least on CentOS this isn't required. I suspect that when the fifo is closed for writing it gets closed for reading and cat exists which exits cronolog as well. Would love it it someone could confirm that though.

UPDATE

Igor Sysoev made the comment that the above might hinder nginx's performance because of context switching and the blocking between the worker processes. So instead of the above you can simulate it with the following as an hourly cron task:

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
/bin/mv ${log_dir}/error.log ${log_dir}/${date_dir}/error.log
kill -USR1 `cat /var/run/nginx.pid`
/bin/gzip ${log_dir}/${date_dir}/access.log &
/bin/gzip ${log_dir}/${date_dir}/error.log &

 

我还是很喜欢nginx作者(Igor Sysoev )的方案!

0
3
分享到:
评论

相关推荐

    nginx-1.7.2 + cronolog-1.6.2

    **Nginx 1.7.2 和 Cronolog 1.6.2:构建高效反向代理与日志管理系统** Nginx 和 Cronolog 是在 Linux 系统中广泛使用的两个工具,它们分别用于网络服务器的反向代理服务和日志管理。在本文中,我们将深入探讨这两个...

    High Performance Caching with Nginx and Nginx Plus

    NGINX caching and cache clustering are powerful tools that can exponentially improve the performance of your website while also reducing hardware requirements, complexity, and cost. This ebook is a ...

    NGINX and FFMPEG.rar

    标题 "NGINX and FFMPEG.rar" 提到的两个核心工具是Nginx和FFmpeg,它们在IT领域,特别是视频流媒体服务中扮演着重要角色。FFMPEG是一款强大的开源命令行工具,用于处理音频和视频文件,包括转换、编码、解码、分割...

    cronolog-1.6.2.tar.gz cronolog-1.6.2下载

    3. 集成:在Apache或Nginx等Web服务器中,通过修改配置文件(如`httpd.conf`或`nginx.conf`),将日志输出指向cronolog进程,以便让cronolog处理日志。 4. 管理:一旦启用cronolog,用户需要定期检查日志目录,确保...

    cronolog-1.6.2.tar.gz

    1、下载(最新版本) # wget http://cronolog.org/download/cronolog-1.6.2.tar.gz 2、解压缩 # tar zxvf cronolog-1.6.2.tar.gz 3、进入cronolog安装文件所在目录 # cd cronolog-1.6.2 4、运行安装 # ./configure #...

    Nginx From Beginner to Pro(Apress,2016)

    Teaches you to start up Nginx and quickly take your expertise to a level where you can comfortably work with various aspects of the web server and make informed design decisions for your web farm....

    arm 架构 docker运行nginx镜像包

    arm 架构 docker运行nginx镜像包,arm 架构 docker运行nginx镜像包,arm 架构 docker运行nginx镜像包,arm 架构 docker运行nginx镜像包,arm 架构 docker运行nginx镜像包,arm 架构 docker运行nginx镜像包,arm 架构...

    Complete-NGINX-Cookbook-2019.pdf

    explore advanced features of both NGINX and NGINX Plus, the free and licensed versions of this server. You’ll find recipes for: - High-performance load balancing with HTTP, TCP, and UDP - Traffic ...

    centos8 nginx1.20.1 与nginx配置文件

    现在,我们可以下载Nginx的源代码包`nginx-1.20.1.tar.gz`。你可以通过wget或者浏览器将文件下载到本地,然后解压: ```bash wget http://nginx.org/download/nginx-1.20.1.tar.gz tar -zxvf nginx-1.20.1.tar.gz cd...

    cronolog最新可用版

    cronolog的配置文件通常设置在HTTP服务器的配置中,例如Apache或Nginx的配置文件,通过将日志输出重定向到cronolog来实现日志分割。 安装cronolog的步骤简单明了,正如描述中提到的,解压文件后,执行以下命令: 1...

    nginx版本升级步骤

    **Nginx版本升级步骤详解** 在Web服务器领域,Nginx以其高性能、低内存消耗以及高并发处理能力而备受青睐。随着新版本的发布,可能会包含性能优化、安全修复和新特性,因此定期更新Nginx版本是必要的。本文将详细...

    Nginx 1.22.0 Linux 版本,解压安装。

    Nginx 1.22.0 Linux 版本,解压安装。 Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理...能够支持高达 50,000 个并发连接数的响应,感谢Nginx为我们选择了 epoll and kqueue作为开发模型。

    nginx arm64版本nginx-linux-arrch64.zip

    这个名为"nginx-linux-arm64.zip"的压缩包提供的是专为ARM64架构(也称为AArch64)编译的Nginx版本,适用于基于Linux操作系统的64位ARM处理器设备,如树莓派、某些云服务器或嵌入式系统。无需繁琐的编译过程,只需...

    nginx-1.13.3,nginx1.13.3不存在信息泄漏漏洞安全稳定nginx版本

    **Nginx 1.13.3 版本详解** Nginx 是一款高性能的 HTTP 和反向代理服务器,广泛应用于网站托管、负载均衡以及应用程序交付等领域。它以其高效、稳定和轻量级的特性著称,尤其在处理静态内容和高并发请求时表现优秀...

    nginx带nginx-http-flv模块windows编译版rtmp

    **Nginx与Nginx-RTMP及Nginx-HTTP-FLV模块** Nginx是一款高性能、轻量级的Web服务器/反向代理服务器,被广泛应用于高并发场景,尤其在处理静态文件、HTTP缓存以及反向代理等方面表现出色。Nginx以其高效的事件驱动...

    Nginx 1.22.0 Windows版本,解压安装。

    Nginx 1.22.0 Windows版本,解压安装。 Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)...能够支持高达 50,000 个并发连接数的响应,感谢Nginx为我们选择了 epoll and kqueue作为开发模型。

    实战nginx.pdf

    实战nginx.pdf。主要内容包括:第1章 Nginx简介;第2章Nginx服务器安装与配置;第3章Nginx基本配置与优化;第4章Nginx与PHP;第5章Nginx与JSP、ASP.NET..第6章Nginx http负载均衡和反向代理;第7章Nginx 的rewrite...

Global site tag (gtag.js) - Google Analytics