阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

线上服务器Nginx日志无切割引起问题及解决

132次阅读
没有评论

共计 2875 个字符,预计需要花费 8 分钟才能阅读完成。

状况:lnmp 环境下 nginx 反向代理服务器,部分网站无法访问,重启服务器后 ok
拿到权限后安装 zabbix 监控,负载 Ok ,
IO 报警:
Disk I/O is overloaded on xss152

使用命令工具查看 io 状况,top 下 78%wa……………………
[root@xx16 /]#  iostat -x 1 10 
avg-cpu:  %user  %nice %system %iowait  %steal  %idle
          0.27    0.00    0.59  21.81    0.00  77.33
 
Device:        rrqm/s  wrqm/s    r/s    w/s  rsec/s  wsec/s avgrq-sz avgqu-sz  await  svctm  %util
sda              9.58  152.95  128.06  63.60  1136.57  1732.58    14.97    12.19  63.58  4.44  85.00
dm-0              0.00    0.00  137.10  216.57  1130.05  1732.58    8.09    25.40  71.82  2.40  84.99
dm-1              0.00    0.00    0.08    0.00    0.65    0.00    7.67    0.00    2.45  2.23  0.02
dm-2              0.00    0.00    0.06    0.00    0.51    0.00    8.00    0.00    2.65  2.39  0.02

%util 长期达到 99%…………….
查看服务器本身状况,在 nginx 日志目录下发现,日志无切割,常年积累下来已经达到可怕的大小
-rw-r–r–  1 nobody root  4959870331 5 月  18 11:38 access.log.1
[root@xx16 logs]# du -sh
37G 

so, 先写 nginx 日志切割,其后强制执行一次.
[root@xx16 logrotate.d]# vim /etc/logrotate.d/nginx
/usr/local/nginx/logs/*log{
    daily
    rotate 7
    compress
    notifempty
    nocompress
    postrotate
    /bin/kill -USR1 `cat /usr/local/nginx/logs/nginx.pid` 2> /dev/null || true
endscript
}

强制执行一次,然后查看 Io 情况.
logrotate -f /etc/logrotate.d/nginx
root@xx16 logrotate.d]#  iostat -x 1 10 
 
avg-cpu:  %user  %nice %system %iowait  %steal  %idle
          0.27    0.00    0.58  20.70    0.00  78.45
avg-cpu:  %user  %nice %system %iowait  %steal  %idle
          0.25    0.00    0.75    0.00    0.00  99.00
 
Device:        rrqm/s  wrqm/s    r/s    w/s  rsec/s  wsec/s avgrq-sz avgqu-sz  await  svctm  %util
sda              0.00    3.00    0.00    2.00    0.00    40.00    20.00    0.02    9.00  5.00  1.00
dm-0              0.00    0.00    0.00    5.00    0.00    40.00    8.00    0.05    9.60  2.00  1.00
dm-1              0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  0.00  0.00
dm-2              0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  0.00  0.00
dm-3              0.00    0.00    0.00    5.00    0.00    40.00    8.00    0.05    9.60  2.00  1.00

TOP 下
1234567 [root@xx16 logrotate.d]# top
 
top – 11:57:35 up  2:20,  3 users,  load average: 0.00, 0.00, 0.26
Tasks: 142 total,  1 running, 141 sleeping,  0 stopped,  0 zombie
Cpu(s):  0.1%us,  0.3%sy,  0.0%ni, 99.3%id,  0.3%wa,  0.0%hi,  0.1%si,  0.0%st
Mem:  3917212k total,  3762456k used,  154756k free,  2144812k buffers
Swap:  8388600k total,        0k used,  8388600k free,  774492k cached

0.3%wa  zabbix 警报解除. 搞定!!

该服务器搭建于 2014 年,上一任管理员写了 nginx 切割脚本,但是没有后面由于 nginx 网站增添,没有添加到脚本,引起 nginx 日志一直无切割.

更多 Nginx 相关教程见以下内容

CentOS 6.2 实战部署 Nginx+MySQL+PHP http://www.linuxidc.com/Linux/2013-09/90020.htm

使用 Nginx 搭建 WEB 服务器 http://www.linuxidc.com/Linux/2013-09/89768.htm

搭建基于 Linux6.3+Nginx1.2+PHP5+MySQL5.5 的 Web 服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm

CentOS 6.3 下 Nginx 性能调优 http://www.linuxidc.com/Linux/2013-09/89656.htm

CentOS 6.3 下配置 Nginx 加载 ngx_pagespeed 模块 http://www.linuxidc.com/Linux/2013-09/89657.htm

CentOS 6.4 安装配置 Nginx+Pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm

Nginx 安装配置使用详细笔记 http://www.linuxidc.com/Linux/2014-07/104499.htm

Nginx 日志过滤 使用 ngx_log_if 不记录特定日志 http://www.linuxidc.com/Linux/2014-07/104686.htm

Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-05/131551.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计2875字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中