nginx日志緩存,提升磁盤性能
將多個日志進行積累,達到一定量級后寫入到磁盤,可以減少磁盤旋轉,從而降低磁盤i/o,提升nginx能效
語法:
access_log path
access_log [存儲路徑] [buff=大小] [gzip=壓縮級別] [flush=time 刷新時間]
max: 最大字節數量。
inactive:設置時間 默認是10s
min_uses:日志寫入指定次數后壓縮
valid:設置檢查頻率,默認60s
off:禁用緩存
1. 全局定義 log_format 日志格式
log_format aaa '$remote_addr - $remote_user [$time_local]'
'"$request" $status $body_bytes_sent'
'"$http_referer" "$http_user_agent"';
2. http server配置
access_log /application/nginx/logs/access_81.log aaa buffer=64k flush=1m;
open_log_file_cache max=1000 inactive=20s valid=1m min_uses=1s;
##解釋:
buffer=64k #日志文件緩存在內存中的大小
flush=1m #內存中日志存留一分鍾
max=1000 #文件描述符
inactive=20s #日志文件在緩存中沒有被使用就會被取消
valid=1m #默認 1m 或 60s 兩個單位都可以使用
min_uses=1 #在存活時間內日志被寫入幾次才會記錄到緩存
3. 重啟nginx
官方文檔:
http://nginx.org/en/docs/http/ngx_http_log_module.html#open_log_file_cache