[iyunv@node1 ~]# cd /usr/local/nagios/etc/objects/
[iyunv@node1 objects]# cp localhost.cfg localhost.cfg.bak
在文件末尾添加以下内容
define service{
use local-service ; Name of service template to use
host_name localhost
service_description NFS
check_command check_tcp!2049
notifications_enabled 0
}
配置nagios.cfg主配置文件
[iyunv@node1 objects]# vim /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
安装和启动NFS服务器
1
2
3
4
5
6
7
8
[iyunv@node1 objects]# mkdir /nfs
[iyunv@node1 objects]# vim /etc/exports
/nfs *(rw)
[iyunv@node1 objects]# /etc/init.d/nfs restart
验证nfs
[iyunv@node1 objects]# showmount -e 192.168.31.101
Export list for 192.168.31.101:
/nfs *
检查localhost是否已经正常启用,检查nagios配置文件,如无错误,则重启nagios服务
1
2
[iyunv@node1 objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[iyunv@node1 objects]# service nagios restart
验证
1
2
[iyunv@node1 objects]# service nfs stop
[iyunv@node1 objects]# service nfs restart
2.2 Nagios远程监控Mysql数据库状态
安装mysql服务器
[iyunv@node1 ~]# yum -y install mysql mysql-server mysql-devel
[iyunv@node1 ~]# service mysqld restart
[iyunv@node1 ~]# chkconfig mysqld on
创建测试数据库
1
2
3
mysql> create database nagiostest;
mysql> grant select on nagiostest.* to nagiostest@"localhost";
mysql> flush privileges;
[iyunv@node1 objects]# vim services.cfg
define service{
use local-service
host_name node2.cn
service_groups MysqlGroup
service_description MySqlSev
check_command check_mysql
}
define service{
use local-service ; Name of service template to u
se
host_name node2.cn
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use local-service ; Name of service template to u
se
host_name node2.cn
service_description Root Partition
check_command check_local_disk!20%!10%!/
}
…………
define servicegroup{
servicegroup_name MysqlGroup
alias MySQLServer
members node2.cn,MySqlSev
}
检查配置文件无错误和警告信息则重启服务
1
2
[iyunv@node1 objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[iyunv@node1 objects]# service nagios restart