1、安装前准备
nagios-3.2.3.tar.gz
nagios-plugins-1.4.15.tar.gz
FCGI-0.67.tar.gz
FCGI-ProcManager-0.22.tar.gz
IO-All-0.39.tar.gz
 
2、安装
1)安装nagios
groupadd nagios
useradd -g nagios -d /usr/local/nagios -s /bin/false nagios
tar -xzf nagios-3.2.3.tar.gz
cd nagios-3.2.3
./configure --prefix=/usr/local/nagios
make all
make install  #安装主要的程序,CGI及HTML文件
make install-init
make install-commandmode  #给外部命令访问nagios配置文件权限
make install-config  ##把配置文件的例子复制到nagios的安装目录
2)安装插件
tar -xzf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --prefix=/usr/local/nagios/  --with-mysql  --with-perl --enable-redhat-pthread-workaround --enable-perl-modules
make && make install
启动nagios
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #检测配置
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg #启动
/usr/local/nagios/bin/nagiostats #查看运行状态
 
nagios依赖PHP环境和perl环境,以下搭建perl环境:
3)安装perl fcgi
tar -xzf FCGI-0.67.tar.gz
cd FCGI-0.67
perl Makefile.PL
make && make install
4)安装FCGI-ProcManager
tar -xzf FCGI-ProcManager-0.22.tar.gz
cd FCGI-ProcManager-0.22
perl Makefile.PL
make && make install
5)安装perl-IO-ALL
tar -xzf IO-All-0.39.tar.gz
cd IO-All-0.39
perl Makefile.PL
make && make install
6)监听请求
nagios中web界面为cgi程序,使用unix socket来监听perl CGI请求并解析
chmod +x /usr/local/nginx/sbin/nginx-fcgi.pl
#启动nginx-fcgi.pl
perl nginx-fcgi.pl -l /usr/local/nginx/logs/nginx-fcgi.log -pid /usr/local/nginx/logs/nginx-fcgi.pid -S /usr/local/nginx/logs/nginx-fcgi.sock
chmod 777 /usr/local/nginx/logs/nginx-fcgi.sock
 
3、配置
1)nginx配置
server {
    listen       8888;
    server_name  192.168.3.7;
    root   /usr/local/nagios/share;
    index  index.php index.html index.htm;
    location ~ .*\.(php|php5)?$
    {
        #fastcgi_pass  unix:/tmp/php-cgi.sock;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi.conf;
    }
    location ~ \.cgi$
    {
        root /usr/local/nagios/sbin;
        rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
        fastcgi_index index.cgi;
        fastcgi_pass    unix:/usr/local/nginx/logs/nginx-fcgi.sock;
        fastcgi_param   SCRIPT_FILENAME             /usr/local/nagios/sbin$fastcgi_script_name;
        fastcgi_param   HTTP_ACCEPT_LANGUAGE        zh-cn;
        include /usr/local/nginx/conf/fastcgi.conf;
    }
}
重启nginx
 
2)nagios
chmod 755 /usr/local/nagios/
vi /usr/local/nagios/etc/cgi.cfg
use_authentication=0
#不使用认证
重启nagios
 
然后就可以访问了