nagios pnp4nagios yum 安装 配置

 nagios功能很多,最主要是有报警功能,但是nagios也有一个缺点,就是自身没有图形化工具,要另外去装pnp4nagios,网上大部分都是结合apache的,下面说一下pnp4nagios配合nginx的配置
一,安装pnp4nagios
[root@localhost objects]# yum install pnp4nagios rrdtool  
如果找不到包换epel源,博客里面有搜一下。关于nagios的安装,请参考:nagios 安装配置 详解
二,配置nagios
1,修改nagios.cfg
查看复制打印?
[root@localhost objects]# vim /etc/nagios/nagios.cfg    //修改以下内容  
process_performance_data=1                             //由0改为1  
host_perfdata_command=process-host-perfdata            //前面的注释拿掉  
service_perfdata_command=process-service-perfdata      //注释拿掉  
enable_environment_macros=1                            //如果有注释拿掉  
2,修改commands.cfg
注释掉原有对process-host-perfdata和process-service-perfdata,重新定义
[root@localhost objects]# vim /etc/nagios/objects/commands.cfg  
  
define command {  
       command_name    process-service-perfdata  
       command_line    /usr/bin/perl /usr/libexec/pnp4nagios/process_perfdata.pl  
}  
  
define command {  
       command_name    process-host-perfdata  
       command_line    /usr/bin/perl /usr/libexec/pnp4nagios/process_perfdata.pl -d HOSTPERFDATA  
}  
4、修改配置文件templates.cfg
添加以下内容
查看复制打印?
[root@localhost objects]# vim /etc/nagios/objects/templates.cfg   
  
define host {  
        name       hosts-pnp  
        register   0  
        action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_  
        process_perf_data               1  
}  
define service {  
        name       srv-pnp  
        register   0  
        action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$  
        process_perf_data               1  
}  
5,修改服务器配置文件localhost.cfg
查看复制打印?
[root@localhost objects]# vim /etc/nagios/objects/commands.cfg  
  
define host{  
        use                     linux-server,hosts-pnp  
        host_name               localhost  
        alias                   localhost  
        address                 127.0.0.1  
        }  
  
define service{  
        use                             local-service,srv-pnp  
        host_name                       localhost  
        service_description             PING  
        check_command                   check_ping!100.0,20%!500.0,60%  
        }  
上面只是例举了一个,你可以都加一下。
三,pnp4nagios配置
在网上好多关于pnp4nagios的文章,都是要把mv misccommands.cfg-sample misccommands.cfg 生成配置文件,我是yum安装的,安装目录下根本没有sample这样的东西
[root@localhost objects]# tree /etc/pnp4nagios/  
/etc/pnp4nagios/  
├── background.pdf  
├── check_commands  
│   ├── check_all_local_disks.cfg  
│   ├── check_nrpe.cfg  
│   └── check_nwstat.cfg  
├── config.php  
├── misccommands.cfg  
├── nagios.cfg  
├── npcd.cfg  
├── pages  
│   └── web_traffic.cfg  
├── pnp4nagios_release  
├── process_perfdata.cfg  
└── rra.cfg  
所在我根本没有配置任何东西。
四,重启nagios,启动npcd
[root@localhost pnp4nagios]# /etc/init.d/npcd start  
[root@localhost pnp4nagios]# /etc/init.d/nagios restart  
五,nginx配置
配置nginx的时候,配置挺头痛的,nagios的根目录是有php的,pnp4nagios是放在nagios的根目录下面,pnp4nagios也是php的,配置不好容易错乱的。
查看复制打印?
server  
{  
    listen       80;  
    server_name  nagios.xxxx.com;  
    index  index.php;  
    root   /usr/share/nagios/html;  
  
    location ~ .*\.(php|php5)?$ {        //nagios根目录的php  
        fastcgi_pass  127.0.0.1:9000;  
        fastcgi_index index.php;  
        include fastcgi.conf;  
    }  
  
    location ~ ^(/nagios.*\.(gif|jpg|jpeg|png|bmp|swf))$ {   //nagios的图片重写  
        rewrite ^/nagios/images/(.*) /images/$1 break;  
        expires     30d;  
    }  
  
    location ~ ^(/nagios.*\.(js|css)?)$ {       //nagios的js,css重写  
        rewrite ^/nagios/stylesheets/(.*) /stylesheets/$1 break;  
        expires     1h;  
    }  
  
    location ~ .*\.cgi$ {             //nagios的主程序是perl的,perl的cgi重写  
        root /usr/lib64/nagios/cgi-bin;  
        rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;  
        fastcgi_pass   127.0.0.1:9001;  
        fastcgi_index index.cgi;  
        include fastcgi.conf;  
    }  
  
    location ~ ^(/pnp4nagios.*\.(gif|jpg|jpeg|png|bmp|swf))$ {   //pnp4nagios图片重写  
        rewrite ^/pnp4nagios/index.php/(.*) /pnp4nagios/$1 break;  
        expires     30d;  
    }  
  
    location ~ ^(/pnp4nagios.*\.(js|css))$ {      //pnp4nagios的js,css重写  
        rewrite ^/pnp4nagios/index.php/(.*) /pnp4nagios/$1 break;  
        expires     1h;  
    }  
  
    location ~ ^(/pnp4nagios.*\.php)(.*)$ {       //pnp4nagios的php重写  
        rewrite ^/pnp4nagios/index.php/index.php/(.*)$ /pnp4nagios/index.php/$1; break;  
        fastcgi_pass   127.0.0.1:9000;  
        fastcgi_index index.php;  
        include fastcgi.conf;  
    }  
  
    log_format  access_na  '$remote_addr - $remote_user [$time_local] "$request" '  
              '$status $body_bytes_sent "$http_referer" '  
              '"$http_user_agent" $http_x_forwarded_for';  
    access_log  /var/log/nginx/access_na.log  access_na;  
}  
在这里有一个问题就是http://nagios.xxxx.com/pnp4nagios/index.php/index.php/graph?host=localhost&srv=PING在这里有二个index.php,这个是php的程序加上去的,我并没有改。同一个页面有二种链接。
由nagios的监控页面,跳转到pnp4nagios监控页面的连接是
http://nagios.xxxx.com/pnp4nagios/index.php/graph?host=localhost&srv=PING
点php4nagios监控页面中的连接然后就会多加一个index.php,
http://nagios.xxxx.com/pnp4nagios/index.php/index.php/graph?host=localhost&srv=PING
这也是上面我为什么要加这一句rewrite ^/pnp4nagios/index.php/index.php/(.*)$ /pnp4nagios/index.php/$1; break;的原因
看一下效果图
 

 

你可能感兴趣的:(nginx+pnp)