nagios功能不少,最主要是有報警功能,可是nagios也有一個缺點,就是自身沒有圖形化工具,要另外去裝pnp4nagios,網上大部分都是結合apache的,下面說一下pnp4nagios配合nginx的配置php
一,安裝pnp4nagioscss
[root@localhost objects]# yum install pnp4nagios rrdtool html
若是找不到包換epel源,博客裏面有搜一下。關於nagios的安裝,請參考:nagios 安裝配置 詳解linux
二,配置nagiosios
1,修改nagios.cfgnginx
[root@localhost objects]# vim /etc/nagios/nagios.cfg //修改如下內容 apache
process_performance_data=1 //由0改成1 vim
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 #根據實際路徑
}
四、修改配置文件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/localhost.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 ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { //nagios的圖片重寫
rewrite ^/nagios/images/(.*) /images/$1 break;
rewrite ^/pnp4nagios/index.php/(.*) /pnp4nagios/$1 break;
expires 30d;
}
location ~ .*\.(js|css)?$ { //nagios的js,css重寫
rewrite ^/nagios/stylesheets/(.*) /stylesheets/$1 break;
rewrite ^/nagios/js/(.*) /js/$1 break;
rewrite ^/pnp4nagios/index.php/(.*) /pnp4nagios/$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.*\.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;
}
}
在這裏有一個問題就是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;的緣由
看一下效果圖
nagios 監控頁面看到pnp4nagios圖標,折線小圖
點擊上圖中的折線小圖,進入下圖
pnp4nagios 管理頁面