• 检测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
  • 相关阅读:
    [转]学习B站动态转发抽奖脚本
    【LeetCode】236. 二叉树的最近公共祖先
    Java中邮件的发送
    最长递增子序列(LIS)
    最长公共子序列(LCS)
    【LeetCode】69. x 的平方根
    Lombok的使用
    Centos 中文乱码解决方法
    FWT,FST入门
    [UOJ310][UNR #2]黎明前的巧克力
  • 原文地址:https://www.cnblogs.com/maobuji/p/10174392.html
Copyright © 2020-2023  润新知