首页 > 数据库技术 > 详细

mysql主从自动部署

时间:2020-01-31 15:14:37      阅读:60      评论:0      收藏:0      [点我收藏+]
#!/bin/bash
yum -y install mariadb mariadb-server
systemctl stop firewalld
setenforce 0
cat /etc/my.cnf|grep server-id
if [ $? -ne 0 ];then
sed -i ‘10a server-id=1\nlog-bin=mysql-bin\nrelay-log=mysql-relay‘ /etc/my.cnf
fi
systemctl restart mariadb
if [ $? -ne 0 ];then
	systemctl stop mariadb
	systemctl start mariadb
fi

mysql -e "grant all on *.* to ‘tom‘@‘10.0.0.%‘ identified by‘123‘;"
mysql -e "flush privileges;"
log_file=`mysql -e "show master status;"|grep mysql-bin|awk ‘{print $1}‘`
log_pos=`mysql -e "show master status;"|grep mysql-bin|awk ‘{print $2}‘`

ssh root@10.0.0.46 > /dev/null <<eeooff
systemctl stop firewalld
setenforce 0
yum -y install mariadb mariadb-server
sed -i ‘s#server-id=2# #g‘ /etc/my.cnf
sed -i ‘s#log-bin=mysql-bin# #g‘ /etc/my.cnf
sed -i ‘s#relay-log=mysql-relay# #g‘ /etc/my.cnf

sed -i ‘10a server-id=2\nlog-bin=mysql-bin\nrelay-log=mysql-relay‘ /etc/my.cnf
systemctl stop mariadb
systemctl start mariadb
mysql -e "stop slave;"
mysql -e "reset slave;"
mysql -e "change master to master_host=‘10.0.0.45‘,master_user=‘tom‘,master_password=‘123‘,master_log_file=‘$log_file‘,master_log_pos=$log_pos;\r"
mysql -e "start slave;"
exit
eeooff
echo "ok"

  

mysql主从自动部署

原文:https://www.cnblogs.com/gaiting/p/12245378.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!