搭建基於nginx環境的nagios監控系統

轉載時請務必以超鏈接形式標明文章 原始出處 、作者信息和本聲明。否則將追究法律責任。http://cyr520.blog.51cto.com/714067/1066462

    搭建基於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.  
  8. tar zxvf FCGI-ProcManager-0.18.tar.gz  
  9. cd FCGI-ProcManager-0.18  
  10. perl Makefile.PL  
  11. make  
  12. make install  
  13. cd ..  
  14.  
  15. tar zxvf IO-1.25.tar.gz  
  16. cd IO-1.25  
  17. perl Makefile.PL  
  18. make  
  19. make install  
  20.  
  21. tar zxvf IO-All-0.39.tar.gz  
  22. cd IO-All-0.39  
  23. perl Makefile.PL  
  24. make  
  25. 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. index index.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. }  
  • 創建軟連接:
  1. ln -s /data/app/nagios/share /data/www/html/nagios 
  • 測試登錄:

clip_p_w_picpath002

登錄後的界面如下:

clip_p_w_picpath004

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章