建立shell脚本检测MySql的AB复制简单步骤

2023-05-10,,

下文主要给大家带来建立shell脚本检测MySql的AB复制简单步骤,希望这些内容能够带给大家实际用处,这也是我编辑建立shell脚本检测MySql的AB复制简单步骤这篇文章的主要目的。好了,废话不多说,大家直接看下文吧。

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

vim /usr/local/nagios/libexec/check_mysqlab

  1. #!/bin/bash 
  2. #========================================= 
  3. #File:      checkmysqlab 
  4. #Description: 
  5. #Author:    smileliuyb 
  6. #Modify:    smileliuyb 
  7. #Creation Date: 20130110 
  8. #Last Modified: 20130110 
  9. #========================================= 
  10.  
  11. ipadd=$1 
  12. mysql -h $ipadd -u username -ppasswd -e 'stop slave;' &> /dev/null 
  13. #mysql -h $ipadd -u username -ppasswd -e 'show slave status \G' &> dev/null 
  14. if [ $? -eq 0 ];then 
  15.     mysql -h $ipadd -u username -ppasswd -e 'start slave;' &> /dev/null 
  16.     num=`mysql -h $ipadd -u amoebauser -pabc -e 'show slave status \G' | grep -c Yes` 
  17.     if [ $num -eq 2 ];then 
  18.         echo "OK"; 
  19.         exit 0; 
  20.     else 
  21.         echo "Error"; 
  22.         exit 2; 
  23.     fi 
  24. else 
  25.     echo "Error"; 
  26.     exit 2; 
  27. 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

  1. define command{ 
  2.         command_name    check_mysql_ab 
  3.         command_line    $USER1$/check_mysqlab $HOSTADDRESS$ 
  4.         } 

3.配置Nagios,建立新的被监控对象和被监控服务

vim /usr/local/nagios/etc/objects/localhost.cfg

  1. define host { 
  2.         host_name       192.168.50.62 
  3.         alias           50.62 
  4.         address         192.168.50.62 
  5.         check_command   check-host-alive 
  6.         notification_options    d,u,r 
  7.         check_interval  1 
  8.         max_check_attempts      2 
  9.         contact_groups  admins 
  10.         notification_interval   10 
  11.         notification_period     24x7 

  1. define service{ 
  2.         host_name 192.168.50.62 
  3.         service_description     mysqlab 
  4.         check_period    24x7 
  5.         normal_check_interval   2 
  6.         retry_check_interval    1 
  7.         max_check_attempts      3 
  8.         notification_period     24x7 
  9.         notification_options    w,u,c,r 
  10.         check_command   check_mysql_ab 
  11. 对于以上关于建立shell脚本检测MySql的AB复制简单步骤,大家是不是觉得非常有帮助。如果需要了解更多内容,请继续关注我们的行业资讯,相信你会喜欢上这些内容的。

《建立shell脚本检测MySql的AB复制简单步骤.doc》

下载本文的Word格式文档,以方便收藏与打印。