搭建基于Nginx环境的Nagios监控系统

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

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

准备工作:

  • 下载安装包:
  1. wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.1.tar.gz
  2. wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz
  3. wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz
  4. wget http://www.cpan.org/modules/by-module/FCGI/FCGI-0.67.tar.gz
  5. wget http://search.cpan.org/CPAN/authors/id/G/GB/GBJK/FCGI-ProcManager-0.18.tar.gz
  6. wget http://search.cpan.org/CPAN/authors/id/G/GB/GBARR/IO-1.25.tar.gz
  7. wget http://search.cpan.org/CPAN/authors/id/I/IN/INGY/IO-All-0.39.tar.gz
  • 添加相关用户:
  1. groupadd nagios
  2. useradd -g nagios nagios

开始安装:

  • 编译安装nagios:
  1. tar zxvf nagios-3.4.1.tar.gz
  2. cd nagios
  3. ./configure --prefix=/data/app/nagios --with-nagios-user=nagios --with-nagios-group=nagios
  4. make all
  5. make install
  6. make install-init
  7. make install-commandmode
  8. make install-config
  9. cd ..
  • 编译安装nagios插件:
  1. tar zxvf nagios-plugins-1.4.16.tar.gz
  2. cd nagios-plugins-1.4.16
  3. ./configure --prefix=/data/app/nagios --with-nagios-user=nagios --with-nagios-group=nagios
  4. make
  5. make install
  6. cd ..
  • 编译安装nrpe:
  1. tar zxvf nrpe-2.13.tar.gz
  2. cd nrpe-2.13
  3. ./configure --prefix=/data/app/nagios --with-nrpe-user=nagios --with-nrpe-group=nagios
  4. make
  5. make install
  6. cd ..
  • 安装perl,CGI脚本是用perl实现的:
  1. yum install perl
  • 编译安装perl脚本所需要调用的组件:
  1. tar zxvf FCGI-0.67.tar.gz
  2. cd FCGI-0.67
  3. perl Makefile.PL
  4. make
  5. make install
  6. cd ..
  7. tar zxvf FCGI-ProcManager-0.18.tar.gz
  8. cd FCGI-ProcManager-0.18
  9. perl Makefile.PL
  10. make
  11. make install
  12. cd ..
  13. tar zxvf IO-1.25.tar.gz
  14. cd IO-1.25
  15. perl Makefile.PL
  16. make
  17. make install
  18. tar zxvf IO-All-0.39.tar.gz
  19. cd IO-All-0.39
  20. perl Makefile.PL
  21. make
  22. make install
  • 下载并配置可是实现CGI解析的脚本:
  1. cd /data/app/nginx/sbin/
  2. wget http://www.linux8080.com/perl-fcgi.pl
  3. chmod +x perl-fcgi.pl
  4. chown nginx.nginx perl-fcgi.pl
  5. /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
  6. cd /var/run
  7. chmod 777 nginx-fcgi.sock
  • 创建登录nagios的用户账户和密码文件:
  1. cd /data/app/nagios/etc/
  2. htpasswd -c htpasswd nagios
  • 配置nginx虚拟主机并重启:
  1. server {
  2. listen 80;
  3. server_name 10.10.10.200;
  4. indexindex.html index.htm index.php;
  5. root /data/www/html;
  6. location ~ .*\.(cgi|pl)?$
  7. {
  8. gzip off;
  9. root /data/app/nagios/sbin;
  10. rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
  11. fastcgi_pass unix:/var/run/nginx-fcgi.sock;
  12. fastcgi_param SCRIPT_FILENAME /data/app/nagios/sbin$fastcgi_script_name;
  13. fastcgi_index index.cgi;
  14. fastcgi_read_timeout 60;
  15. fastcgi_param REMOTE_USER $remote_user;
  16. include fcgi.conf;
  17. }
  18. location ~ ^/nagios/.+\.php$
  19. {
  20. fastcgi_pass 127.0.0.1:9000;
  21. fastcgi_index index.php;
  22. include fcgi.conf;
  23. auth_basic "Nagios Access";
  24. auth_basic_user_file /data/app/nagios/etc/htpasswd;
  25. }
  26. }
  • 创建软连接:
  1. ln -s /data/app/nagios/share /data/www/html/nagios
  • 测试登录:

 搭建基于Nginx环境的Nagios监控系统

 登录后的界面如下:

搭建基于Nginx环境的Nagios监控系统

注意:文中所涉及到的一部分安装包,下载链接可能会失效。大家请从我的附件下载。

具体下载目录在 /2014年资料/4月/4日/搭建基于Nginx环境的Nagios监控系统

Nagios 的详细介绍:请点这里
Nagios 的下载地址:请点这里

相关阅读

相关推荐