原文:http://www.weiruoyu.cn/?p=750

首先感谢51cto的Bensen仁兄的文章,按照做,没问题,谢谢。

地址:http://myhat.blog.51cto.com/blog/391263/654830

http://myhat.blog.51cto.com/391263/654952

nagios安装后,libexec里没有check_mysql怎么办?


  1. nagios监控mysql服务器:

  2. 方法:定期去select下某个空闲的数据库

  3. 使用插件:check_mysql

  4. 问题:安装完成nagios后,发现居然没有这个插件,怎么办?

  5. 解决方法:

  6. # yum install mysql-devel <我系统默认没装mysql的>

  7. 重装下nagios-plugins插件包

  8. [root@svr4 nagios-plugins-1.4.15]# ./configure

  9. --with-apt-get-command:

  10. --with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s

  11. --with-ping-command: /bin/ping -n -U -w %d -c %d %s

  12. --with-ipv6: yes

  13. --with-mysql: /usr/bin/mysql_config

  14. --with-openssl: yes

  15. --with-gnutls: no

  16. --enable-extra-opts: no

  17. --with-perl: /usr/bin/perl

  18. --enable-perl-modules: no

  19. --with-cgiurl: /nagios/cgi-bin

  20. --with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin

  21. --enable-libtap: no

  22. [root@svr4 nagios-plugins-1.4.15]# make && make install

  23. 结果:这个插件有了!

  24. [root@svr4 nagios-plugins-1.4.15]# ll /usr/local/nagios/libexec/check_mysql*

  25. -rwxr-xr-x 1 root root 124343 Aug 31 13:13 /usr/local/nagios/libexec/check_mysql

  26. -rwxr-xr-x 1 root root 120909 Aug 31 13:13 /usr/local/nagios/libexec/check_mysql_query


nagios使用check_mysql监控mysql


  1. nagios监控mysql服务器:

  2. 1、建立专用数据库:

  3. [root@svr3 ~]# /usr/local/webserver/mysql/bin/mysql -u root -p

  4. Enter password:

  5. Welcome to the MySQL monitor. Commands end with ; or \g.

  6. Your MySQL connection id is 51910

  7. Server version: 5.5.3-m3-log Source distribution

  8. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  9. mysql> create database nagios;

  10. Query OK, 1 row affected (0.00 sec)

  11. mysql> grant select on nagios.* to nagios@'%' identified by '123qweasd';

  12. Query OK, 0 rows affected (0.00 sec)

  13. mysql> flush privileges;

  14. Query OK, 0 rows affected (0.00 sec)

  15. mysql> select User,Password,Host from user;

  16. +----------------+-------------------------------------------+------------------+

  17. | User | Password | Host |

  18. +----------------+-------------------------------------------+------------------+

  19. | root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 | localhost |

  20. | nagios | *A1F1CB851D62F002C09A0C9C4A76262473432F55 | % |

  21. +----------------+-------------------------------------------+------------------+

  22. 14 rows in set (0.00 sec)

  23. 12 rows in set (0.00 sec)

  24. [root@svr3 ~]# /usr/local/nagios/libexec/check_mysql -H 10.1.1.30 -u nagios -d nagios -p 123qweasd

  25. Uptime: 970046 Threads: 1 Questions: 684583 Slow queries: 3 Opens: 672 Flush tables: 1 Open tables:

  26. 369 Queries per second avg: 0.705

  27. [root@svr4 nrpe_install]# /usr/local/nagios/libexec/check_mysql -H 10.1.1.30 -u nagios -d nagios -p 123qweasd

  28. Uptime: 970348 Threads: 1 Questions: 684584 Slow queries: 3 Opens: 672 Flush tables: 1 Open tables: 369 Queries per second avg: 0.705

  29. 果断开始设置:

  30. #定义用户

  31. #定义组,及隶属用户

  32. #用户增加

  33. 在command.cfg里增加插件命令:

  34. #check mysql

  35. define command{

  36. command_name check_mysql

  37. command_line $USER1$/check_mysql -H $HOSTADDRESS$ -u nagios -d nagios -p 123qweasd

  38. }

  39. #定义服务:

  40. define service {

  41. host_name svr3.labexam.com

  42. service_description MysqlDB

  43. check_period 24x7

  44. max_check_attempts 2

  45. normal_check_interval 1

  46. retry_check_interval 1

  47. contact_groups sagroup,dbagroup

  48. notification_interval 5

  49. notification_period 24x7

  50. notification_options w,u,c,r

  51. check_command check_mysql

  52. }

  53. 感谢秋香老师,你的书给了我很大帮助。