搭建基於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
- 測試登錄:
登錄後的界面如下: