小编教你使用shell脚本部署mysql主从
服务器配置信息如下:
centos6两台
Master IP:192.168.88.153
Slave IP:192.168.88.152
配置免密登录
ssh-keygen -t rsassh-copy-id [email protected]
编写mysql_master脚本
#!/bin/bashservice iptables stopsetenforce 0yum -y install mysql mysql-serversed -ie '7a\server-id=1\nlog-bin=mysql-bin\nrelay-log\n' /etc/my.cnfservice mysqld restartmysql -e " grant all on *.* to 'tom'@'%' identified by '123'; "mysql -e " flush privileges; "mysql -e " show master status; "
编写mysql_slave脚本
#!/bin/bashbin=`ssh [email protected] "mysql -e 'show master status;'|grep mysql"`file=`echo $bin|awk -F ' ' '{print $1}'`pos=`echo $bin|awk -F ' ' '{print $2}'`service iptables stopsetenforce 0yum -y install mysql mysql-serversed -ie '7a\server-id=1\nlog-bin=mysql-bin\nrelay-log\n' /etc/my.cnfservice mysqld startmysql -e "change master to master_host='192.168.88.152',master_user='tom',master_password='123',master_log_file='$file',master_log_pos=$pos;"mysql -e 'start slave'mysql -e 'show slave status \G;'IO=`mysql -e "show slave status\G;" 2>/dev/null |grep Slave_IO_Running|awk -F ':' '{print $2}'`SQL=`mysql -e "show slave status\G;" 2>/dev/null |grep Slave_SQL_Running|awk -F ':' '{print $2}'`if [ $IO == "Yes" -a $SQL == "Yes" ]thenecho "成功"elseecho "失败"fi
将mysql_slave.sh复制到slave主机
scp mysql_slave.sh 192.168.88.153:/root/
执行脚本
sh mysql_master.shssh [email protected] "sh /root/mysql_slave.sh"
相关推荐
emmm00 2020-11-17
暗夜之城 2020-11-11
疯狂老司机 2020-09-08
tufeiax 2020-09-03
CoderToy 2020-11-16
王艺强 2020-11-17
ribavnu 2020-11-16
bianruifeng 2020-11-16
wangshuangbao 2020-11-13
苏康申 2020-11-13
vivenwan 2020-11-13
moyekongling 2020-11-13
云中舞步 2020-11-12
要啥自行车一把梭 2020-11-12
aydh 2020-11-12
kuwoyinlehe 2020-11-12
minerk 2020-11-12
vitasfly 2020-11-12