Problems caused by no cutting of Nginx logs on the online server and Solutions

Source: Internet
Author: User
Tags nginx reverse proxy

Problems caused by no cutting of Nginx logs on the online server and Solutions

Status: nginx reverse proxy server in lnmp environment. Some websites cannot be accessed. After restarting the server, OK
After obtaining the permission, install zabbix monitoring and load OK,
IO alarm:
Disk I/O is overloaded on xss152

Run the command tool to view the io status. 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 reaches 99% in the long run ................
Check the status of the server. In the nginx log directory, no logs are cut, and the accumulated logs have reached a terrible size all the year round.
-Rw-r -- 1 nobody root 4959870331 May 18 11:38 access. log.1
[Root @ xx16 logs] # du-sh
37G

So, write nginx log cutting first, and then execute it once.
[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
}

Execute the command once and check the Io status.
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, 3 users, load average: 0.00, 0.00, 0.26
Task: 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: 3917212 k total, 3762456 k used, 154756 k free, 2144812 k buffers
Swap: 8388600 k total, 0 k used, 8388600 k free, 774492 k cached

0.3% wa zabbix alarm relief. Done !!

The server was built in 2014. The previous Administrator wrote the nginx cutting script, but it was not added to the script due to the addition of the nginx website, causing no nginx log cutting.

For more Nginx tutorials, see the following:

Deployment of Nginx + MySQL + PHP in CentOS 6.2

Build a WEB server using Nginx

Build a Web server based on Linux6.3 + Nginx1.2 + PHP5 + MySQL5.5

Performance Tuning for Nginx in CentOS 6.3

Configure Nginx to load the ngx_pagespeed module in CentOS 6.3

Install and configure Nginx + Pcre + php-fpm in CentOS 6.4

Nginx installation and configuration instructions

Nginx log filtering using ngx_log_if does not record specific logs

Nginx details: click here
Nginx: click here

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.