er2121e 发表于 2015-2-11 15:50:48

nagios添加主机和写mysql插件

在nagios服务器上添加监控的主机及服务:
Nagios配置文件:
# cd objects/
# ls
commands.cfg(定义监控命令)localhost.cfg(定义监控什么)switch.cfg(定义交换机) timeperiods.cfg(模板文件)
contacts.cfg(定义联系人的)printer.cfg(定义打印机模板的)    templates.cfg(模板定制文件)windows.cfg(监控windows及其模板)
# pwd
/usr/local/nagios/etc/objects
添加一台主机:# vim localhost.cfg

检查配置文件是否有误:

重启服务并查看(点击host):


监控服务(ssh):# vim localhost.cfg

# /etc/init.d/nagios reload
Running configuration check...
Reloading nagios configuration...
Done


写插件:
0         正常
1         警告
2         严重警告
一:写一个监控本机mysql的插件:
# 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
测试插件;
# chmod 755 check_mysql

二:写一个调用插件的命令

测试插件:
# /usr/local/nagios/libexec/check_mysql -H localhost
mysql stop
# /etc/init.d/mysqld start
启动 MySQL:                                             [确定]
# /usr/local/nagios/libexec/check_mysql -H localhost
mysql runing.....
写localhost.cfg文件;
# vim localhost.cfg

测试配置文件是否有错:
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# /etc/init.d/nagios reload
Running configuration check...
Reloading nagios configuration...
Done



gaocancan 发表于 2015-3-12 14:32:59

看不到图片
页: [1]
查看完整版本: nagios添加主机和写mysql插件