Centos7安装Nginx监控组件Nginx-rrd【二】

Centos7安装Nginx监控组件Nginx-rrd

  • 1. 安装perl、rrdtool
  • 2. 安装Nginx-rrd
    • 1. 下载Nginx-rrd
    • 2. 配置nginx-rrd.conf
  • 3. 配置Nginx
  • 4. 配置收集、绘制图表的定时任务
  • 5. 访问监控页面

1. 安装perl、rrdtool

yum install perl rrdtool perl-libwww-perl libwww-perl perl-rrdtool 

备注: 若出现No package XXX available ,就将centos的yum源更换为阿里云yum源,详细步骤请查看该博主的博客:请点击

2. 安装Nginx-rrd

1. 下载Nginx-rrd

wget http://soft.vpser.net/status/nginx-rrd/nginx-rrd-0.1.4.tgz #下载rrd包
tar zxvf nginx-rrd-0.1.4.tgz
cd nginx-rrd-0.1.4    
cp -p usr/sbin/* /usr/sbin     #复制主程序文件到/usr/sbin目录 下 
cp -p etc/nginx-rrd.conf /etc  #复制配置文件到 /etc目录下
cp html/index.php /home/node1/nginx/html/  #复制监控页面到已安装nginx的html目录下
mkdir /home/node1/nginx/html/rrd  #创建存放Nginx-rrd数据的目录

2. 配置nginx-rrd.conf

vi /etc/nginx-rrd.conf
#####################################################
# dir where rrd databases are stored
RRD_DIR="/home/node1/nginx/html/rrd";
# dir where png images are presented
WWW_DIR="/home/node1/nginx/html/";
# process nice level
NICE_LEVEL="-19";
# bin dir
BIN_DIR="/usr/sbin";
# servers to test
# server_utl;server_name  
SERVERS_URL="http://127.0.0.1:8080/nginx_status;one_server http://127.0.0.1:8081/nginx_status;second_server"

*备注:多个虚拟主机,SERVERS_URL中空格分开。如: SERVERS_URL=server_url1:server_name1 server_url2:server_name2 *

3. 配置Nginx

首先确认安装的nginx否包含了stub_status模块,若没有包含该模块,请添加stub_status模块。
Centos7安装Nginx监控组件Nginx-rrd【二】_第1张图片
Nginx.conf配置如下:

#user  nobody;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    #default_type  application/octet-stream;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
    server {
        listen       8080;
        server_name  one_server;
        #access_log  logs/host.access.log  main;
        location / {
            root   /home/node1/nginx/html;
            index  index.html index.htm index.php;
            location /nginx_status {
                stub_status on;
                access_log off;
            }
        }
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #此处一定要配置,因为监控页面是php页面,php页面需要fastcgi解析之后浏览器才能识别展示
        location ~ \.php$ {
            root           /home/node1/nginx/html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /home/node1/nginx/html$fastcgi_script_name;
            include        fastcgi_params;
            include fastcgi.conf;
        }
    }
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    server {
        listen       8081;
      #  listen       somename:8080;
        server_name  second_server;
        location / {
            root   html;
            index  index.html index.htm;
        }
        location /nginx_status {
                stub_status on;
                access_log off;
        }
    }
}

重启Nginx服务:/home/node1/nginx/sbin/nginx -s reload

备注: 由于监控页面是.php,所以要想访问,nginx所在的服务器必须要安装php-fpm,否则页面加载不出来,详细安装步骤请查看该博主的博客:地址

4. 配置收集、绘制图表的定时任务

vim /etc/crontab
#在文件中增加下面俩行配置
* * * * * root /usr/sbin/nginx-collect
*/15 * * * * root /usr/sbin/nginx-graph

5. 访问监控页面

在页面中输入:http://IP:8080/index.php
就能看到如下的监控图形数据了。
Centos7安装Nginx监控组件Nginx-rrd【二】_第2张图片

你可能感兴趣的:(nginx,nginx)