Chinaunix首页 | 论坛 | 博客
  • 博客访问: 380802
  • 博文数量: 114
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1219
  • 用 户 组: 普通用户
  • 注册时间: 2015-02-07 21:23
文章分类

全部博文(114)

文章存档

2018年(1)

2017年(5)

2016年(87)

2015年(21)

我的朋友

分类: 系统运维

2016-07-27 16:21:34


  1. 利用 nagios 自带的插件来监控 mysql 的主从同步状态
  2. [主动方式]
  3. 1、调试check_mysql主从同步的命令
  4. 登录到从库的服务器上进行如下操作:
  5. grant super,replication slave on *.* to nagios@'192.168.88.%' identified by 'tcs6688';
  6. flush privileges;
  7. nagios服务端:
  8. 1、用check_mysql插件进行检测
  9. [root@Nagios ~]# /usr/local/nagios/libexec/check_mysql -H 192.168.88.253 -unagios -p tcs6688 -S
  10. Uptime: 1017185 Threads: 1 Questions: 3485390 Slow queries: 0 Opens: 63 Flush tables: 1 Open tables: 57 Queries per second avg: 3.426 Slave IO: Yes Slave SQL: Yes Seconds Behind Master: 0
  11. 2、编辑commands.cfg
  12. [root@Nagios ~]# cd /usr/local/nagios/etc/objects/
  13. [root@Nagios objects]# tail commands.cfg

  14. # 'check_mysql_slave' command definition
  15. define command{

  16.         command_name check_mysql

  17.         command_line $USER1$/check_mysql -H $HOSTADDRESS$ -unagios -p tcs6688 -S -P3306
  18.         }

  19.         备注:-u指定用户,-P指定端口,-p指定密码,-s指定sock文件路径(多实例),-S监控主从
  20.         
  21. host文件中添加主机
  22. #shenzhen/server host
  23. define host{
  24. use linux-server
  25. host_name web253
  26. address 192.168.88.253
  27. }

  28. server文件中添加服务
  29. define service{
  30. use generic-service
  31. host_name web253
  32. service_description mysql_slave
  33. check_command check_mysql

  34. 3. 检查配置文件
  35. /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
  36.  service nagios reload

  37.  
  38. 4.脚本监控
  39. [root@zsq libexec]# cat check_mysql_slave
  40. #!/bin/sh
  41. declare -a slave_is
  42. slave_is=($(mysql -ucheck -ptcs6688 -e "show slave status\G"|grep Running|awk '{print $2}'))
  43. if [ "${slave_is[0]}" = "Yes" -a "${slave_is[1]}" = "Yes" ]
  44. then
  45.         echo "slave yes is ok"
  46. exit 0
  47. else
  48.         echo "slave yes is error"
  49. exit 2
  50. fi

  51. 5、在/usr/local/nagios/etc/nrpe.cfg中添加监控mysql主从的命令

  52. command[check_mysql_slave]=/usr/local/nagios/libexec/check_mysql_slave

  53. 6、编辑/usr/local/nagios/etc/objects/server.cfg ,添加监控mysql主从项目:

  54. define service{
  55.         use generic-service
  56.         host_name light
  57.         service_description check_mysql_slave
  58.         check_command check_nrpe!check_mysql_slave
  59.         }

  60. 4、重启nagios就OK了

  61. /etc/init.d/nagios restart

阅读(1060) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~