在nagios服务器上添加监控的主机及服务:
Nagios配置文件:
[root@a etc]# cd objects/
[root@a objects]# ls
commands.cfg(定义监控命令) localhost.cfg(定义监控什么) switch.cfg(定义交换机) timeperiods.cfg(模板文件)
contacts.cfg(定义联系人的) printer.cfg(定义打印机模板的) templates.cfg(模板定制文件) windows.cfg(监控windows及其模板)
[root@a objects]# pwd
/usr/local/nagios/etc/objects
添加一台主机:[root@a objects]# vim localhost.cfg
检查配置文件是否有误:
重启服务并查看(点击host):
监控服务(ssh):[root@a objects]# vim localhost.cfg
[root@a objects]# /etc/init.d/nagios reload
Running configuration check...
Reloading nagios configuration...
Done
写插件:
0 正常
1 警告
2 严重警告
一:写一个监控本机mysql的插件:
[root@a libexec]# vim check_mysql
#!/bin/bash
mysql -e "show databases" &>/dev/null
if [ $? -eq 0 ]
then
echo "mysql runing....."
exit 0
else
echo "mysql stop"
exit 2
fi
测试插件;
[root@a libexec]# chmod 755 check_mysql
二:写一个调用插件的命令
测试插件:
[root@a objects]# /usr/local/nagios/libexec/check_mysql -H localhost
mysql stop
[root@a objects]# /etc/init.d/mysqld start
启动 MySQL: [确定]
[root@a objects]# /usr/local/nagios/libexec/check_mysql -H localhost
mysql runing.....
写localhost.cfg文件;
[root@a objects]# vim localhost.cfg
测试配置文件是否有错:
[root@a objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[root@a objects]# /etc/init.d/nagios reload
Running configuration check...
Reloading nagios configuration...
Done