竹子开花的时 发表于 2019-1-15 08:27:28

Nagios自定义shell脚本检测MySql的AB复制

  1. 建立一个Shell脚本,用于检测MySql的AB复制


  vim /usr/local/nagios/libexec/check_mysqlab


[*]#!/bin/bash
[*]#=========================================
[*]#File:      checkmysqlab
[*]#Description:
[*]#Author:    smileliuyb
[*]#Modify:    smileliuyb
[*]#Creation Date: 20130110
[*]#Last Modified: 20130110
[*]#=========================================
[*]
[*]ipadd=$1
[*]mysql -h $ipadd -u username -ppasswd -e 'stop slave;' &> /dev/null
[*]#mysql -h $ipadd -u username -ppasswd -e 'show slave status \G' &> dev/null
[*]if [ $? -eq 0 ];then
[*]    mysql -h $ipadd -u username -ppasswd -e 'start slave;' &> /dev/null
[*]    num=`mysql -h $ipadd -u amoebauser -pabc -e 'show slave status \G' | grep -c Yes`
[*]    if [ $num -eq 2 ];then
[*]      echo "OK";
[*]      exit 0;
[*]    else
[*]      echo "Error";
[*]      exit 2;
[*]    fi
[*]else
[*]    echo "Error";
[*]    exit 2;
[*]fi

  chown nagios.nagios /usr/local/nagios/libexec/check_mysqlab
  chmod a+x /usr/local/nagios/libexec/check_mysqlab
  2.配置Nagios,在Nagios中加入新命令调用该脚本
  vim /usr/local/nagios/etc/objects/commands.cfg


[*]define command{
[*]      command_name    check_mysql_ab
[*]      command_line    $USER1$/check_mysqlab $HOSTADDRESS$
[*]      }

  3.配置Nagios,建立新的被监控对象和被监控服务
  vim /usr/local/nagios/etc/objects/localhost.cfg




[*]define host {
[*]      host_name       192.168.50.62
[*]      alias         50.62
[*]      address         192.168.50.62
[*]      check_command   check-host-alive
[*]      notification_options    d,u,r
[*]      check_interval1
[*]      max_check_attempts      2
[*]      contact_groupsadmins
[*]      notification_interval   10
[*]      notification_period   24x7
[*]}



[*]define service{
[*]      host_name 192.168.50.62
[*]      service_description   mysqlab
[*]      check_period    24x7
[*]      normal_check_interval   2
[*]      retry_check_interval    1
[*]      max_check_attempts      3
[*]      notification_period   24x7
[*]      notification_options    w,u,c,r
[*]      check_command   check_mysql_ab
[*]}




页: [1]
查看完整版本: Nagios自定义shell脚本检测MySql的AB复制