您的位置:首页 > 运维架构 > Nginx

nginx日志导致IO负载较高,如何处理

2014-02-17 16:31 369 查看
使用Nginx来收集日志,访问量较大,在将收集的数据直接记录磁盘文件时,导致磁盘IO过高,机器直接挂掉。

为减少磁盘IO操作,将日志写如内存分区;但日志量太大,很容易将内存写满。

Nginx支持日志压缩功能,具体如下:
access_log path format gzip[=level] [buffer=size] [flush=time];


If either the buffer or gzip (1.3.10, 1.2.7) parameter is used, writes to log will be buffered.
The buffer size must not exceed the size of an atomic write to a disk file. For FreeBSD this size is unlimited


When buffering is enabled, the data will be written to the file:
if the next log line does not fit into the buffer;
if the buffered data is older than specified by the flush parameter (1.3.10, 1.2.7);
when a worker process is re-opening log files or is shutting down.

If the gzip parameter is used, then the buffered data will be compressed before writing to the file. The compression level can be set between 1 (fastest, less compression) and 9 (slowest, best compression). By default, the buffer size is equal to 64K bytes,
and the compression level is set to 1. Since the data is compressed in atomic blocks, the log file can be decompressed or read by “zcat” at any time.
Example:

access_log /path/to/log.gz combined gzip flush=5m;
For gzip compression to work, nginx must be built with the zlib library.


nginx支持压缩后写日志,使用此功能可以将日志文件放在内存分区,减少磁盘IO操作。然后定时对日志轮询,将日志写入磁盘或传输到日志处理集群。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Nginx