您的位置:首页 > 运维架构 > Nginx

搭建基于nginx环境的nagios监控系统 推荐

2012-11-21 18:21 721 查看
搭建基于apache的nagios系统比较容易,网上的资料也比较多。可是在nginx环境下就有点费劲了,因为nginx本身不支持CGI,所以需要在三方程序的配合下,才能实现CGI的解析。

本文只讲述安装部分,有机会再给大家补上配置部分。下面就开始学习在nginx环境下安装,安装nagios监控系统。

准备工作:

下载安装包:

wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.1.tar.gz wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz wget http://www.cpan.org/modules/by-module/FCGI/FCGI-0.67.tar.gz wget http://search.cpan.org/CPAN/authors/id/G/GB/GBJK/FCGI-ProcManager-0.18.tar.gz wget http://search.cpan.org/CPAN/authors/id/G/GB/GBARR/IO-1.25.tar.gz wget http://search.cpan.org/CPAN/authors/id/I/IN/INGY/IO-All-0.39.tar.gz


添加相关用户:

groupadd nagios
useradd -g nagios nagios

开始安装:

编译安装nagios:

tar zxvf nagios-3.4.1.tar.gz
cd nagios
./configure --prefix=/data/app/nagios --with-nagios-user=nagios --with-nagios-group=nagios
make all
make install
make install-init
make install-commandmode
make install-config
cd ..


编译安装nagios插件:

tar zxvf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --prefix=/data/app/nagios --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
cd ..


编译安装nrpe:

tar zxvf nrpe-2.13.tar.gz
cd nrpe-2.13
./configure --prefix=/data/app/nagios --with-nrpe-user=nagios --with-nrpe-group=nagios
make
make install
cd ..


安装perl,CGI脚本是用perl实现的:

yum install perl


编译安装perl脚本所需要调用的组件:

tar zxvf FCGI-0.67.tar.gz
cd FCGI-0.67
perl Makefile.PL
make
make install
cd ..

tar zxvf FCGI-ProcManager-0.18.tar.gz
cd FCGI-ProcManager-0.18
perl Makefile.PL
make
make install
cd ..

tar zxvf IO-1.25.tar.gz
cd IO-1.25
perl Makefile.PL
make
make install

tar zxvf IO-All-0.39.tar.gz
cd IO-All-0.39
perl Makefile.PL
make
make install


下载并配置可是实现CGI解析的脚本:

cd /data/app/nginx/sbin/
wget http://www.linux8080.com/perl-fcgi.pl chmod +x perl-fcgi.pl
chown nginx.nginx perl-fcgi.pl
/data/app/nginx/sbin/perl-fcgi.pl -pid /var/run/nginx-fcgi.pid -S /var/run/nginx-fcgi.sock -l /var/log/perl-fcgi.log
cd /var/run
chmod 777 nginx-fcgi.sock


创建登录nagios的用户账户和密码文件:

cd /data/app/nagios/etc/
htpasswd -c htpasswd nagios


配置nginx虚拟主机并重启:

server {
listen 80;
server_name 10.10.10.200;
index index.html index.htm index.php;
root /data/www/html;
location ~ .*\.(cgi|pl)?$
{
gzip off;
root /data/app/nagios/sbin;
rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
fastcgi_pass unix:/var/run/nginx-fcgi.sock;
fastcgi_param SCRIPT_FILENAME /data/app/nagios/sbin$fastcgi_script_name;
fastcgi_index index.cgi;
fastcgi_read_timeout 60;
fastcgi_param REMOTE_USER $remote_user;
include fcgi.conf;
}
location ~ ^/nagios/.+\.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
auth_basic "Nagios Access";
auth_basic_user_file /data/app/nagios/etc/htpasswd;
}
}


创建软连接:

ln -s /data/app/nagios/share /data/www/html/nagios


测试登录:




登录后的界面如下:



注意:文中所涉及到的一部分安装包,下载链接可能会失效。大家请从我的附件下载。
如果大家安装有问题的话,请及时联系我!!

附件:http://down.51cto.com/data/2361810
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息