现在的位置: 首页 > 综合 > 正文

添加Nginx-1.0.4/5的Munin-1.4.6的监控(Munin+Nginx)和需要依赖perl-libwww-perl

2013年10月02日 ⁄ 综合 ⁄ 共 2831字 ⁄ 字号 评论关闭

1. 确认你的nginx加载了http_stub_status_module模块,没有的话,重新编译。
查看Nginx版本:

1 [root@hexuweb102 monitor]$ /usr/local/nginx/sbin/nginx -v
2 #nginx: nginx version: nginx/1.0.4

查看安装哪些模块:

1 [root@hexuweb102 monitor]$ /usr/local/nginx/sbin/nginx -V
2 #nginx: nginx version: nginx/1.0.4
3 #nginx: built by gcc 4.1.2 20080704 (Red Hat 4.1.2-50)
4 #nginx: TLS SNI support disabled
5 #nginx: configure arguments: --prefix=/usr/local/nginx --user=nobody --group=nobody --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module

从上面看,我的已经安装,如果你的没有安装使用下方法重新编译安装即可:

01 [root@hexuweb102 monitor]$tar
zxf nginx-1.0.4.tar.gz
02 [root@hexuweb102 monitor]$cd
nginx-1.0.4
03 [root@hexuweb102 monitor]$./configure \
04         --prefix=/usr/local/nginx \
05         --user=nobody \
06         --group=nobody \
07         --with-http_ssl_module \
08         --with-http_stub_status_module \
## 添加此模块
09         --with-http_gzip_static_module
10 [root@hexuweb102 monitor]$make
&& make
install

2. 在Nginx Server (Vhost) 添加下面代码:

01 [root@hexuweb102 monitor]$  vi
/usr/local/nginx/conf/nginx.conf
02 server {
03        listen 127.0.0.1;
04        server_name localhost;
05        location /nginx_status {
06                stub_status on;
07                access_log   off;
08                allow 127.0.0.1;
09                deny all;
10        }
11  }

下载nginx plugin for munin,重命名为nginx_combined_

将文件拷贝(到你的munin插件库目录)并改名字:

1 [root@hexuweb102 monitor]$ cp
./Nginx_Combined-v2 /opt/munin/lib/plugins/nginx_combined_

然后 ln 到(注意后面名字会显示在 munin):

1 [root@hexuweb102 monitor]$ ln
-s /opt/munin/lib/plugins/nginx_combined_ /etc/opt/munin/plugins/nginx_combined
2  #也可以其它方式::
3  #example1: ./nginx_mysite.net
4  #example2: ./nginx_10.0.0.1

完成上面两步之后,重启munin-node即可,如果想马上看到就执行一下munin-cron:

1 [root@hexuweb102 monitor]$ ps
aux | grep
munin
## 查看 munin ID
2 [root@hexuweb102 monitor]$ kill
$muninId       ## ps 看到 ID
3 [root@hexuweb102 monitor]$ kill
$muninId       ## ps 看到 ID
4 [root@hexuweb102 monitor]$ /opt/munin/sbin/munin-node
## 启动
5 [root@hexuweb102 monitor]$ /opt/munin/bin/munin-cron 
## 可以马上看到

nginx_combined 默认Title个人感觉整个不合配置,改下面内容即可:

1    ### 因为这里有一从此 $URL ######
2    #print "graph_title NGINX status: $URL\n;
3 print "graph_title NGINX status combined\n";

注意,如果所有操作完成后,为确保成功正常的运行,可以使用munin-run测试,下面使用munin自带的nginx_request测试
常见问题: munin监控nginx出现 no (LWP::UserAgent not found)

1 [root@hexuweb102 monitor]$ /opt/munin/sbin/munin-run nginx_request
2 #Can't locate object method "new" via package "LWP::UserAgent" at /etc/opt/munin/plugins/nginx_request line 106.

发现有BUG了,是因为perl-libwww-perl没有安装,安装即可:

1 [root@hexuweb102 monitor]$ yum -y
install perl-libwww-perl

然后再确认:

1 [root@hexuweb102 monitor]$ /opt/munin/sbin/munin-run nginx_request
2 #request.value 3351969

抱歉!评论已关闭.