1. nagios监控mysql服务器: 
  2.  
  3. 1、建立专用数据库: 
  4. [root@svr3 ~]# /usr/local/webserver/mysql/bin/mysql -u root -p 
  5. Enter password:  
  6. Welcome to the MySQL monitor.  Commands end with ; or \g. 
  7. Your MySQL connection id is 51910 
  8. Server version: 5.5.3-m3-log Source distribution 
  9.  
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 
  11.  
  12. mysql> create database nagios; 
  13. Query OK, 1 row affected (0.00 sec) 
  14.  
  15. mysql> grant select on nagios.* to nagios@'%' identified by '123qweasd'; 
  16. Query OK, 0 rows affected (0.00 sec) 
  17.  
  18. mysql> flush privileges; 
  19. Query OK, 0 rows affected (0.00 sec) 
  20.  
  21. mysql> select User,Password,Host from user; 
  22. +----------------+-------------------------------------------+------------------+ 
  23. | User           | Password                                  | Host             | 
  24. +----------------+-------------------------------------------+------------------+ 
  25. | root           | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 | localhost        | 
  26. | nagios         | *A1F1CB851D62F002C09A0C9C4A76262473432F55 | %                | 
  27. +----------------+-------------------------------------------+------------------+ 
  28. 14 rows in set (0.00 sec) 
  29. 12 rows in set (0.00 sec) 
  30.  
  31. [root@svr3 ~]# /usr/local/nagios/libexec/check_mysql -H 10.1.1.30 -u nagios -d nagios -p 123qweasd 
  32. Uptime: 970046  Threads: 1  Questions: 684583  Slow queries: 3  Opens: 672  Flush tables: 1  Open tables:  
  33.  
  34. 369  Queries per second avg: 0.705 
  35.  
  36. [root@svr4 nrpe_install]# /usr/local/nagios/libexec/check_mysql -H 10.1.1.30 -u nagios -d nagios -p 123qweasd 
  37. Uptime: 970348  Threads: 1  Questions: 684584  Slow queries: 3  Opens: 672  Flush tables: 1  Open tables: 369  Queries per second avg: 0.705 
  38.  
  39. 果断开始设置: 
  40. #定义用户 
  41. #定义组,及隶属用户 
  42. #用户增加 
  43.  
  44. 在command.cfg里增加插件命令: 
  45. #check mysql 
  46. define command{ 
  47. command_name check_mysql 
  48. command_line $USER1$/check_mysql -H $HOSTADDRESS$ -u nagios -d nagios -p 123qweasd 
  49.  
  50. #定义服务: 
  51. define service { 
  52.         host_name svr3.labexam.com 
  53.         service_description MysqlDB 
  54.         check_period 24x7 
  55.         max_check_attempts 2 
  56.         normal_check_interval 1 
  57.         retry_check_interval 1 
  58.         contact_groups sagroup,dbagroup 
  59.         notification_interval 5 
  60.         notification_period 24x7 
  61.         notification_options w,u,c,r 
  62.         check_command check_mysql 
  63. 感谢秋香老师,你的书给了我很大帮助。