这个实验是建立在nagios的第二篇文章的基础(安装配置好nagios,并且监听某些主机和服务)之上
实现的功能是把繁琐的数据分析装换成报表的形式,可以动态的查看,能有效的控制主机和服务的状态
相关阅读:
VMware Linux下Nagios的安装 http://www.linuxidc.com/Linux/2011-11/47908.htm
VMware Linux下Nagios的基本配置 http://www.linuxidc.com/Linux/2011-11/47909.htm
这里yum -y install php*(把php的模块都安装上)
1、首先安装rrdtool
[root@localhost ~]# ls rrdtool-1.3.1.tar.gz
rrdtool-1.3.1.tar.gz
[root@localhost ~]# tar zxvf rrdtool-1.3.1.tar.gz
[root@localhost rrdtool-1.3.1]# ./configure –prefix=/usr/loca/rrdtool(出现的那个警告可以不予以理会,仅仅做以下的动作就好了)
[root@localhost rrdtool-1.3.1]# cp /usr/local/rrdtool/lib/perl/5.8.8/i386-linux-thread-multi/auto/RRDs/RRDs.so /usr/lib/perl5/5.8.8/i386-linux-thread-multi/
[root@localhost rrdtool-1.3.1]# make;make install
2、安装pnp套件
[root@localhost ~]# ls pnp-0.4.13.tar.gz
pnp-0.4.13.tar.gz
[root@localhost ~]# tar zxvf pnp-0.4.13.tar.gz
[root@localhost ~]# cd pnp-0.4.13
[root@localhost pnp-0.4.13]# ./configure –with-nagios-user=nagios –with-nagios-group=nagios –with-rrdtool=/usr/local/rrdtool/bin/rrdtool –with-perfdata-dir=/usr/local/nagios/share/perfdata
[root@localhost pnp-0.4.13]# make;make install
[root@localhost pnp-0.4.13]# make install-config
[root@localhost pnp-0.4.13]# make install-init
3、具体的配置
[root@localhost ~]# cd /usr/local/nagios/etc/pnp/(根据模板文件制作主设置档案)
[root@localhost pnp]# cp process_perfdata.cfg-sample process_perfdata.cfg
[root@localhost pnp]# cp npcd.cfg-sample npcd.cfg
[root@localhost pnp]# cp rra.cfg-sample rra.cfg
[root@localhost pnp]# chown nagios:nagios *
[root@localhost ~]# vi /usr/local/nagios/etc/pnp/process_perfdata.cfg(保证下边的两项为下边列出的,其他的根据自己需要修改即可)
LOG_FILE = /usr/local/nagios/var/perfdata.log
LOG_LEVEL = 2
[root@localhost ~]# cd /usr/local/nagios/etc/objects/(下边的步骤是修改配置文件)
[root@localhost objects]# vi templates.cfg //添加下边的pnp的设置
define host{
name host-pnp
register 0
action_url /nagios/pnp/index.php?host=$HOSTNAME$
process_perf_data
}
define service{
name service-pnp
register 0
action_url /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
process_perf_data
}
[root@localhost objects]# vi ../nagios.cfg
process_performance_data=1 //启用nagios的数据输出功能
host_perfdata_command=process-host-perfdata //启用本机的数据输出功能
service_perfdata_command=process-service-perfdata //启用服务的输出功能
[root@localhost objects]# vi commands.cfg (修改对应的句段为下边的摸样)
# ‘process-host-perfdata’ command definition
define command{
command_name process-host-perfdata //主机数据输出的设置
command_line /usr/local/nagios/libexec/process_perfdata.pl //存放到这个文件中,便于取用
}
# ‘process-service-perfdata’ command definition
define command{
command_name process-service-perfdata
command_line /usr/local/nagios/libexec/process_perfdata.pl
}
[root@localhost objects]# vi services.cfg //添加pnp的支持
##################### web ###########################
define service{
use local-service,service-pnp
host_name web
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use local-service,service-pnp
host_name web
service_description SSH
check_command check_ssh
}
define service{
use local-service,service-pnp
host_name web
service_description SSHD
check_command check_tcp!22
}
define service{
use local-service,service-pnp
host_name web
service_description http
check_command check_http
}
###################### mysql ########################
define service{
use local-service,service-pnp
host_name mysql
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use local-service,service-pnp
host_name mysql
service_description SSH
check_command check_ssh
}
define service{
use local-service,service-pnp
host_name mysql
service_description ftp
check_command check_ftp
}
define service{
use local-service,service-pnp
host_name mysql
service_description mysqlport
check_command check_tcp!3306
}
define service{
use local-service,service-pnp
host_name mysql
service_description load
check_command check_local_load
}
define service{
use local-service,service-pnp
host_name mysql
service_description disk
check_command check_local_disk
}
define servicegroup{
servicegroup_name servicegroup
alias service-group
members web,PING,web,SSH,web,SSHD,web,http,mysql,PING,mysql,SSH,mysql,ftp,mysql,mysqlport,mysql,load,mysql,disk
}
4、测试的部分
[root@localhost ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg //检查配置是否有问题,有问题的话按照提示修改
………………………………
………………………………………
Total Warnings: 0 //出现这样的字样就表示没问题啦
Total Errors: 0
[root@localhost ~]# /etc/init.d/nagios restart
[root@localhost ~]# /etc/init.d/httpd restart
[root@localhost web]# ls(查看可用的小太阳,出现数据模块的服务名称,在web的页面的小太阳就能成功形成相关的报表)
SSHD.rrd SSHD.xml SSH.rrd SSH.xml
最后IE http://ip/nagios nagiosadmin 123登录 点击小太阳就可以看看效果啦