zoukankan      html  css  js  c++  java
  • 检测mysq组复制的脚本

    #!/bin/bash
    
    PROG_OUT="/root/checkmysql-group.log" # 输出日志到至此文件,建议配置绝对路径
    #PROG_OUT="/dev/null" #如果不想输出日志,则打开注释
    
    
    MYSQL_IP=127.0.0.1 
    MYSQL_PORT=3306
    MYSQL_USER=root
    MYSQL_PASSWORD=kWYM6%pnbVnvsR4K
    MYSQL_PATH=/usr/bin/mysql
    
    echo "">>$PROG_OUT
    
    echo $(date "+%Y-%m-%d %H:%M:%S") check start >>$PROG_OUT
    
    if netstat -lntp | grep -q ':'$MYSQL_PORT' ';then
      echo port $MYSQL_PORT exist >>$PROG_OUT
    else
      echo port $MYSQL_PORT not exist >>$PROG_OUT
      echo $(date "+%Y-%m-%d %H:%M:%S") check end >>$PROG_OUT
      exist 1
    fi
    
    mysql_master_host_name=`$MYSQL_PATH -h$MYSQL_IP -u$MYSQL_USER -p$MYSQL_PASSWORD -P$MYSQL_PORT -e "SELECT * FROM performance_schema.replication_group_members WHERE MEMBER_ID = (SELECT VARIABLE_VALUE FROM performance_schema.global_status WHERE VARIABLE_NAME= 'group_replication_primary_member')" |awk 'NR==2{print}'|awk -F" " '{print $3}'`
    echo mysql_master_host_name:$mysql_master_host_name>>$PROG_OUT
    
    mysql_machine_host_name=`hostname`
    echo mysql_machine_host_name:$mysql_machine_host_name>>$PROG_OUT
     
    if [ "$mysql_machine_host_name"X = "$mysql_master_host_name"X ];then
       echo this is Master >>$PROG_OUT
       echo $(date "+%Y-%m-%d %H:%M:%S") check end >>$PROG_OUT
       exit 0
    else
       echo this is not Master >>$PROG_OUT
       echo $(date "+%Y-%m-%d %H:%M:%S") check end >>$PROG_OUT
       exit 1
    fi
  • 相关阅读:
    网站初学笔记1
    如何在新项目中使用曾经创建的用户控件
    C#用户控件的一些尝试
    MVC的含义
    Chrome浏览器面板基础了解
    VScode快捷键
    Windows中的键盘快捷方式
    node.js状态码
    JavaScript小结
    Truncate a string
  • 原文地址:https://www.cnblogs.com/maobuji/p/10174392.html
Copyright © 2011-2022 走看看