先说一下本机环境,centos 6.5 64位,nagios是用yum装的,版本是nagios core 3.5.1,自带的就有check_mysql 1,修改commands.cfg # vim /etc/nagios/objects/commands.cfg #添加以下内容define command{ command_name check_mysql command_line $user1$/check
先说一下本机环境,centos 6.5 64位,nagios是用yum装的,版本是nagios core 3.5.1,自带的就有check_mysql
1,修改commands.cfg
# vim /etc/nagios/objects/commands.cfg #添加以下内容define command{ command_name check_mysql command_line $user1$/check_mysql -h $arg1$ -u $arg2$ -p $arg3$}
在这里要注意,这三个参数服务器,用户名和密码
2,修改监控机器文件localhost.cfg
# vim /etc/nagios/objects/localhost.cfg #添加以下内容define service{ use local-service host_name localhost service_description mysql check_command check_mysql!localhost!root!root}
!localhost!root!root分别对应$arg1$,$arg2$,$arg3$,这三个参数
3,修改客户端nrpe.cfg
# vim /etc/nagios/nrpe.cfg #添加以下内容command[check_mysql]=/usr/lib64/nagios/plugins/check_mysql -h localhost -u root -p root
在这里要注意,等于号后面的命令是可执行的,并且不能有错。
[root@node1 objects]# /usr/lib64/nagios/plugins/check_mysql -h localhost -u root -p rootuptime: 78680 threads: 1 questions: 3488 slow queries: 0 opens: 126 flush tables: 1 open tables: 133 queries per second avg: 0.044
4,重启nagios和nrpe
# /etc/init.d/nrpe start# /etc/init.d/nagios start
如果重启nagios报以下错误:
running configuration check... config error! restart aborted. check your nagios configuration.
解决办法:
[root@node1 objects]# /usr/sbin/nagios -v /etc/nagios/nagios.cfg
检测配置文件错在什么地方,你就可以很轻松的修改错误的地方。如果没有报错,就说明配置ok了。
原文地址:nagios监控mysql, 感谢原作者分享。