Nginx下搭建Nagios监控平台(转载)

Nagios依赖PHP环境和perl环境,由于Nginx不支持Perl的CGI,需先来搭建Perl环境,Nagios原理介绍略。

文章原出处:https://blog.linuxeye.com/312.html
1、下载最新稳定源码包和Perl脚本

mkdir nagios-cacti
cd nagios-cacti wget http://www.cpan.org/modules/by-module/FCGI/FCGI-0.74.tar.gz wget http://www.cpan.org/authors/id/B/BO/BOBTFISH/FCGI-ProcManager-0.24.tar.gz wget http://blog.linuxeye.com/wp-content/uploads/2013/04/perl-fcgi.pl wget http://jaist.dl.sourceforge.net/project/nagios/nagios-3.x/nagios-3.5.0/nagios-3.5.0.tar.gz wget http://nchc.dl.sourceforge.net/project/nagiosplug/nagiosplug/1.4.16/nagios-plugins-1.4.16.tar.gz wget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz

2、Nginx对Perl的CGI支持
Nginx支持Perl的CGI方法有好几种,基本原理都是通过Perl的FCGI模块实现,下面的方法就是其中一种:
安装FCGI模块

tar xzf FCGI-0.74.tar.gz cd FCGI-0.74 perl Makefile.PL make && make install cd ../

安装FCGI-ProcManager模块

tar xzf FCGI-ProcManager-0.24.tar.gz cd FCGI-ProcManager-0.24 perl Makefile.PL make && make install cd ../

Perl脚本

cp perl-fcgi.pl /usr/local/nginx chmod +x /usr/local/nginx/perl-fcgi.pl /usr/local/nginx/perl-fcgi.pl > /usr/local/nginx/logs/perl-fcgi.log 2>&1 & #启动Perl chmod 777 /usr/local/nginx/logs/perl-fcgi.sock #Nginx Log中提示Permision Denied方法 cd ../

3、Nagios安装(服务端)

useradd -s /sbin/nologin nagios groupadd nagcmd usermod -a -G nagcmd nagios usermod -a -G nagcmd www tar xzf nagios-3.5.0.tar.gz cd nagios yum -y install gd-devel ./configure --prefix=/usr/local/nagios --with-command-group=nagcmd make all make install #用于安装主要的程序、CGI及HTML文件 make install-init #用于生成init启动脚本 make install-config #用于安装示例配置文件 make install-commandmode #用于设置相应的目录权限 chkconfig --add nagios chkconfig nagios on cd ../

Nagios主程序只是提供一个运行框架,其具体监控是靠运行在其下的插件完成的,Nagios插件必须安装

tar xzf nagios-plugins-1.4.16.tar.gz cd nagios-plugins-1.4.16 ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios make && make install cd ../

由于Nagios只能监测自己所在的主机的一些本地情况,例如,cpu负载、内存使用、硬盘使用等等。如果想要监测被监控的服务器上的这些本地情况,就要
用到NRPE。NRPE(Nagios Remote Plugin
Executor)是Nagios的一个扩展,它被用于被监控的服务器上,向Nagios监控平台提供该服务器的一些本地的情况。NRPE可以称为
Nagios的Linux客户端。

tar xzf nrpe-2.14.tar.gz cd nrpe-2.14 ./configure make && make install cp sample-config/nrpe.cfg /usr/local/nagios/etc/ chown nagios.nagios /usr/local/nagios/etc/nrpe.cfg cd ../

4、Nginx配置(服务端)

ln -s /usr/local/nagios/share /data/admin/nagios

以http://www.linuxeye.com/nagios,需要建立软链接,服务nginx.conf配置文件如下:

################http://www.linuxeye.com/nagios#########################
        server {
        listen  80; server_name _; access_log /dev/null; root /data/admin; index index.php; location ~ .*\.(php|php5)?$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } location ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 1h; } location /status { stub_status on; } location ~ .*\.(cgi|pl)?$ { auth_basic "Nagios Access"; auth_basic_user_file /usr/local/nagios/etc/htpasswd.users; gzip off; root /usr/local/nagios/sbin; rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break; fastcgi_pass unix:/usr/local/nginx/logs/perl-fcgi.sock; fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin$fastcgi_script_name; fastcgi_index index.cgi; fastcgi_param REMOTE_USER $remote_user; fastcgi_param HTTP_ACCEPT_LANGUAGE en_US; include fastcgi_params; fastcgi_read_timeout 60; } }

以http://nagios.linuxeye.com服务nginx.conf配置文件如下:

################http://nagios.linuxeye.com##############################
        server {
        listen  80; server_name nagios.linuxeye.com; access_log logs/nagios_access.log combined; auth_basic "Nagios Access"; auth_basic_user_file /usr/local/nagios/etc/htpasswd.users; location / { root /usr/local/nagios/share; index index.html index.htm index.php; } location ~ .*\.(php|php5)?$ { root /usr/local/nagios/share; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } location /nagios { alias /usr/local/nagios/share; } location /cgi-bin/images { alias /usr/local/nagios/share/images; } location /cgi-bin/stylesheets { alias /usr/local/nagios/share/stylesheets; } location /cgi-bin { alias /usr/local/nagios/sbin; } location ~ .*\.(cgi|pl)?$ { gzip off; root /usr/local/nagios/sbin; rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break; fastcgi_pass unix:/usr/local/nginx/logs/nginx-fcgi.sock; fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin$fastcgi_script_name; fastcgi_index index.cgi;

转载于:https://www.cnblogs.com/evevil/p/5057251.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值