gteric 发表于 2015-9-8 13:14:17

利用 nagios 自带的插件来监控 mysql 的主从同步状态 (监控多实例)

利用 nagios 自带的插件来监控 mysql 的主从同步状态 (监控多实例)

  Nagios监控Mysql主从同步
  ################################################
  使用check_mysql插件 检查mysql主从同步(3307为从库)
  ################################################
  
  [主动方式]
  
  1、调试check_mysql主从同步的命令
  
  登录到从库的服务器上进行如下操作:
  
  # mysql -u root -p -S /data/3307/mysql.sock
  
  mysql> grant super,replication slave on *.* to hackbase@'192.168.1.%' identified by 'wanqiu';
  Query OK, 0 rows affected (0.00 sec)
  
  mysql> exit
  Bye
  
  接下来我们登录到nagios服务端:
  
  1、用check_mysql插件进行检测
  
  # cd /usr/local/nagios/libexec/
  
  # ./check_mysql -uhackbase -p wanqiu -s /data/3307/mysql.sock -P3307-H 192.168.1.123 -S
  Uptime: 10848Threads: 1Questions: 24Slow queries: 0Opens: 13Flush tables: 1Open tables: 7Queries per second avg: 0.002 Slave IO: Yes Slave SQL: Yes Seconds Behind Master: 0
  
  2、编辑commands.cfg
  
  # cd ../etc/objects/
  
  # vi host.cfg
  
  ******************************************
  define host{
  use                     linux-server
  host_name               mysql-tongbu
  alias                   mysql-tongbu
  address               192.168.1.123
  process_perf_data       1
  }
  
  define hostgroup{
  hostgroup_namelinux-servers
  alias         Linux Servers
  members         mysql-tongbu
  }
  
  define hostextinfo {
  host_name             mysql-tongbu
  action_url            /nagios/pnp/index.php?host=$HOSTNAME$
  }
  ******************************************
  
  # vi commands.cfg
  
  ******************************************
  # 'check_mysql_slave' command definition
  define command{
  command_name    check_mysql_slave
  command_line    $USER1$/check_mysql -uhackbase -p wanqiu -s /data/3307/mysql.sock -P3307-H 192.168.1.123 -S
  }
  ******************************************
  3、添加检查mysql同步的服务配置
  
  # vi service.cfg
  
  **********************************************************
  define service {
  use                           generic-service
  host_name                     mysql-tongbu
  service_description             check_mysql_slave
  check_command                   check_mysql_slave
  max_check_attempts      2
  normal_check_interval   4
  retry_check_interval    4
  check_period            24x7
  notification_interval   1440
  notification_period   24x7
  notification_options    w,u,c,r
  contact_groups          admins
  process_perf_data       1
  }
  **********************************************************
  
  4、检查语法并重起nagios
  
  /etc/init.d/nagios checkconfig
  /etc/init.d/nagios reload
  
  5、进入界面查看变化
  
  不同步状态时的内容,界面服务那一行为红色
  
  check_mysql_slaveCRITICAL 04-24-2011 17:20:11 0d 0h 0m 21s 1/2
  Slave IO: No Slave SQL: Yes Seconds Behind Master: (null)
  
  同步状态时的内容,界面服务那一行为绿色
  
  check_mysql_slave OK 04-24-2011 17:28:11 0d 0h 2m 35s 1/2 Uptime: 182 Threads: 1 Questions: 7 Slow queries: 0 Opens: 11 Flush tables: 1 Open tables: 6 Queries per second avg: 0.038
  Slave IO: Yes Slave SQL: Yes Seconds Behind Master: 0
  
  如下图所示:
  
  

  

  (全文完)
页: [1]
查看完整版本: 利用 nagios 自带的插件来监控 mysql 的主从同步状态 (监控多实例)