1、# cat db.txt
backend 3310
base 3320
storage 3330
payment 3340
promotion 3350

2、# cat restart_mysql_slave.sh
#!/bin/sh
export PATH=$PATH:/usr/local/mysql/bin

echo -e "\033[31m`date +"%Y-%m-%d %T"` Restart begin! \033[0m"

#停止数据库
/opt/ops-tool/stop_all.sh

#启动数据库
/opt/ops-tool/start_all.sh

#启动从库
/opt/ops-tool/start_slave.sh

#检查主从状态
/opt/ops-tool/mysql_replication_check.sh

echo -e "\033[31m`date +"%Y-%m-%d %T"` Restart end! \n \033[0m"

3、#

cat stop_all.sh
#!/bin/sh
export PATH=$PATH:/usr/local/mysql/bin
 
#停止数据库
cat /opt/ops-tool/db.txt| while read line
do
  pwd='xxx'
  port=$(echo $line |awk '{print $2}')
  /usr/local/mysql/bin/mysqladmin -h127.0.0.1 -P$port -umtdba_admin -p$pwd shutdown   &>/dev/null
  sleep 10
done

4、# cat start_all.sh
/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/account_3550/conf/my.cnf &>/dev/null &
/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/backend_3310/conf/my.cnf &>/dev/null &
/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/base_3320/conf/my.cnf &>/dev/null &
/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/bbtoms_3520/conf/my.cnf &>/dev/null &
/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/bcoin_3610/conf/my.cnf &>/dev/null &

sleep 20

5、cat start_slave.sh
#!/bin/sh
export PATH=$PATH:/usr/local/mysql/bin
cat /opt/ops-tool/db.txt| while read line
do
  pwd='xxx'
  port=$(echo $line |awk '{print $2}')
  /usr/local/mysql/bin/mysql  -umtdba_admin -p$pwd -h127.0.0.1 -P$port -e"start slave ;"  &>/dev/null
  sleep 5
done

6、#

cat mysql_replication_check.sh
#!/bin/sh
export PATH=$PATH:/usr/local/mysql/bin
cat /opt/ops-tool/db.txt| while read line
do
  pwd='xxx'
  service=$(echo $line |awk '{print $1}')
  port=$(echo $line |awk '{print $2}')
  mysql="/usr/local/mysql/bin/mysql -h127.0.0.1 -P$port -umtdba_admin -p$pwd"
  $mysql -e "show slave status \G;" 2>/dev/null > tmp.log
  IO_env=`cat tmp.log | grep -w Slave_IO_Running | awk '{print $2}'`
  SQL_env=`cat tmp.log | grep -w Slave_SQL_Running | awk '{print $2}'`
  #判断Slave_IO_Running Slave_SQL_Running状态
  if [ "$IO_env" = "Yes" -a "$SQL_env" = "Yes" ]
  then
    echo -e "    replication \033[32m$service --> $port \033[0m OK!"
  else
    echo -e "    replication \033[31m$service --> $port \033[0m is abnormal!"
  fi
done
 
 
/bin/rm -rf tmp.log

配置crontab任务计划

# crontab -l
0 17 * * * /bin/bash /opt/ops-tool/restart_mysql_slave.sh > /tmp/restart_mysql_$(date "+\%Y-\%m-\%d").log

mysql 单机多实例重启数据库服务的更多相关文章

  1. MySQL单机多实例安装并配置主从复制

    单机多实例据说可以最大程度提高硬件使用,谁知道呢,但是以前的公司喜欢这样搞,我最近也在学习复制什么的,电脑搞不起两台虚拟机,刚好单机多实例可以解救我.下面就说说步骤. 承上文http://www.cn ...

  2. mysql单机多实例

    在数据库服务器上,可以架构多个Mysql服务器,进行单机多实例的读写分离: 可以通过mysqld_multi来进行多实例的管理,mysqld_multi是用perl写的脚本,原理是通过mysql_ad ...

  3. mysqld_multi部署mysql单机多实例

    1.安装gcc-c++.ncurses依赖包 # yum install gcc-c++ ncurses-devel 2.安装cmake,用来编译mysql # tar -xvf cmake-3.2. ...

  4. 多配置文件部署mysql单机多实例

    1.安装gcc-c++.ncurses依赖包 # yum install gcc-c++ ncurses-devel 2.安装cmake,用来编译mysql # tar -xvf cmake-3.2. ...

  5. mysql单机多实例配置

    Windows上配置多个mysql实例,主要改下配置文件即可,mysql目录如下: my2中主要改两个配置内容 datadir = D:/Program Files/Mysql/mysql-5.7.2 ...

  6. MySQL单机单实例安装脚本(转载)

    说明:使用mysql generic tar.gz包快速安装mysql 三个文件installation_of_single_mysql.sh.template_install-my.cnf.mysq ...

  7. MySQL单机单实例安装脚本

    说明:使用mysql generic tar.gz包快速安装mysql 三个文件installation_of_single_mysql.sh.template_install-my.cnf.mysq ...

  8. mysql 单机多实例配置

    如果你想在一台机器上进行主从配置实验,本篇可以帮助你实现愿望 [client] #password = your_password port = 3306 socket = /tmp/mysql.so ...

  9. 使用mysqld_multi 实现Mysql 5.6.36 + 5.7.18 单机多实例多版本安装

    Mysql 5.6.36 + 5.7.18 单机多实例多版本安装 随着硬件层面的发展,各种高性能服务器如雨后春笋般出现,但高性能服务器不免造成浪费, MySQL单机多实例,是指在一台物理服务器上运行多 ...

随机推荐

  1. codeforces 1010 C. Border【exgcd】

    题目链接:戳这里 学习博客:戳这里 题意:给n种数,n种数取任意个任意组合相加为sum,求sum%k有哪些值. 解题思路: 由exgcd可知(具体用到的是贝祖定理),ax + by = c,满足gcd ...

  2. Gym 101480F Frightful Formula(待定系数)题解

    #include<cmath> #include<set> #include<map> #include<queue> #include<cstd ...

  3. 7816协议时序和采用UART模拟7816时序与智能卡APDU指令协议

    7816时序 7816时一个比较早的老通讯时序了,最近项目上需要用UART模拟所以,简单学习时序. 时序比较简单,熟悉UART的一眼看着就像是串口的时序,只是他没有停止位,取而代之的就是保护时间gur ...

  4. hardsource bug

    hardsource bug webpack crashed bug memory stackoverflow [hardsource:32210703] Could not freeze refs ...

  5. how to remove git commit history

    how to remove git commit history 如何删除 GitHub 仓库的历史数据 git filter-branch remove GitHub git commit hist ...

  6. free online linux terminal & github cli online

    free online linux terminal & github cli online gitpod https://www.gitpod.io/features/ https://bc ...

  7. Node.js & process.env & OS Platform checker

    Node.js & process.env & OS Platform checker Window 10 Windows 7 ia32 CentOS $ node # process ...

  8. webIM & IM

    webIM & IM sdk 埋点 U-App AI https://developer.umeng.com/docs/67953/detail/68131 https://account.u ...

  9. 闲着蛋疼看下a++的过程

    赋值过程 int a = 1; int b = a++; x86 反汇编: int a = 1; 00D06428 C7 45 F8 01 00 00 00 mov dword ptr [a],1 i ...

  10. 1094 The Largest Generation ——PAT甲级真题

    1094 The Largest Generation A family hierarchy is usually presented by a pedigree tree where all the ...