首先,需要安装最新版本的nagios 插件 ,因为 最新的nagios插件中包含了对mysql的监控脚本
1. 添加授权用户:
[root@moniter.china.org ~]# /usr/local/mysql/bin/mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 51910 Server version: 5.5.3-m3-log Source distribution Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> grant select on test.* to nagios@'%' identified by 'test123'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
2. 测试check_mysql 命令
[root@moniter.china.org ~]# /usr/local/nagios/libexec/check_mysql -H 10.20.190.58 -P 3306 -u nagios -p test123 Uptime: 970046 Threads: 1 Questions: 684583 Slow queries: 3 Opens: 672 Flush tables: 1 Open tables: 369 Queries per second avg: 0.705
3. 修改nagios 对应的配置文件
在command.cfg里增加插件命令: #check mysql define command{ command_name check_mysql command_line $USER1$/check_mysql -H $HOSTADDRESS$ -P 3306 -u nagios -p test123 } #定义服务: define service { host_name moniter.china.org service_description MysqlDB check_period 24x7 max_check_attempts 2 normal_check_interval 1 retry_check_interval 1 contact_groups sagroup,dbagroup notification_interval 5 notification_period 24x7 notification_options w,u,c,r check_command check_mysql }