zoukankan      html  css  js  c++  java
  • 实时抓取主从的同步状态

    #!/bin/bash                                                                                           
     # monitor_mysql_slave status                                                                          
     export master_ip=192.168.7.206 
     export slave_ip=192.168.7.207                                         
     export cmd=/data/mysql/bin/mysql                                                                      
     export mysqluser=root                                                                                 
     export mysqlpwd=123456                                                                                
     export log=/data/monitor03.log                                                                        
     while true                                                                                            
     do                                                                                                    
     datetime=`date '+%Y-%m-%d %H:%M:%S'`                                                                  
     # echo $datetime                                                                                      
     array=$($cmd -h $master_ip -u$mysqluser  -e "show slave statusG"|grep -iE "_running|last_error")     
     # echo $array                                                                                         
     io_running=`echo  $array|grep -i slave_io_running|awk '{print $2}'`                                   
     # echo $io_running                                                                                    
     sql_running=`echo   $array|grep -i slave_sql_running|awk '{print $2}'`                                
     # echo $sql_running                                                                                   
     last_error=`echo $array|grep -i last_error|awk '{print $2}'`                                          
     # echo $last_error                                                                                    
     if [ "$io_running" == "Yes" -a "$sql_running" == "Yes" ]                                              
     then                                                                                                  
     echo "$datetime | 'Master is:' | $master_ip | replaction is ok | 'Slave is:' | $slave_ip | slave is running!" >> $log       
     else                                                                                                  
     echo "$datetime | FAIL | Slave is not running!" >> $log                                               
     echo "$datetime | FAIL | $last_error" >> $log                                                         
     $cmd -u$mysqluser  -e "stop slave;set global sql_slave_skip_counter=1;start slave;exit;"              
     char="$datatime $ip MySQL slave is not running"                                                       
    echo "$last_error"|mail -s "$char" 1******5@163.com                                                   
     break                                                                                                 
     fi                                                                                                    
     sleep 20                                                                                              
                                                                                                           
     array=$($cmd -h $slave_ip -u$mysqluser  -e "show slave statusG"|grep -iE "_running|last_error")      
     # echo $array                                                                                         
     io_running=`echo  $array|grep -i slave_io_running|awk '{print $2}'`                                   
     # echo $io_running                                                                                    
     sql_running=`echo   $array|grep -i slave_sql_running|awk '{print $2}'`                                
     # echo $sql_running                                                                                   
     last_error=`echo $array|grep -i last_error|awk '{print $2}'`                                          
     # echo $last_error                                                                                    
     if [ "$io_running" == "Yes" -a "$sql_running" == "Yes" ]                                              
     then                                                                                                  
     echo "$datetime | 'Master is:' | $slave_ip | replaction is ok | 'Slave is:' | $master_ip | slave is running!" >> $log       
     else                                                                                                  
     echo "$datetime | FAIL | Slave is not running!" >> $log                                               
     echo "$datetime | FAIL | $last_error" >> $log                                                         
     $cmd -u$mysqluser  -e "stop slave;set global sql_slave_skip_counter=1;start slave;exit;"              
     char="$datatime $ip MySQL slave is not running"                                                       
     echo "$last_error"|mail -s "$char" 1******5@163.com                                                   
     break                                                                                                 
     fi                                                                                                    
     sleep 20                                                                                              
     done   
  • 相关阅读:
    6.25作业
    博客园第一篇
    532. 数组中的K-diff数对
    echarts
    跨域问题
    数组中第三大的数 leetcode 414
    除自身以外数组的乘积leetcode 238
    xshell工具
    插入、删除和随机查询时间复杂度都为O(1) leetcode 381
    组合总和3 leetcode 216
  • 原文地址:https://www.cnblogs.com/iyoume2008/p/9712142.html
Copyright © 2011-2022 走看看