此脚本是mysql主主结构脚本
先执行sql_log.sh 脚本 会显出来 IP mysql的二进制文件 还有msql的pos号
然后再A服务器执行一次,B服务器执行一次(切记mysql server_id号不能相同)
eg: sh sql_log.sh 33
[root@localhost ~]# sh log.sh 33
this is: 192.168.0.210 mysql.000007 245
在执行脚本 sql_master.sh
eg: sh sql_master.sh 192.168.0.210 mysql.000007 245
[root@localhost ~]# sh sql_master.sh 192.168.0.210 mysql.000007 245
先执行sql_log.sh 脚本 会显出来 IP mysql的二进制文件 还有msql的pos号
然后再A服务器执行一次,B服务器执行一次(切记mysql server_id号不能相同)
eg: sh sql_log.sh 33
[root@localhost ~]# sh log.sh 33
this is: 192.168.0.210 mysql.000007 245
在执行脚本 sql_master.sh
eg: sh sql_master.sh 192.168.0.210 mysql.000007 245
[root@localhost ~]# sh sql_master.sh 192.168.0.210 mysql.000007 245
sh sql_log.sh
#!/bin/bash
DIR_SQL=/etc/my.cnf
sed -i -e /^socket/a\server-id=$1 -e /^socket/a\log-bin=mysql.bin $DIR_SQL
systemctl restart mariadb
IP=`ifconfig | awk -F ':' 'NR==2{print $1}' | awk '{print $2}'`
SQL_LOG=`mysql -uroot -p123456 -e "show master status\G;" > log.sql`
SQL_FILE=`awk -F ':' 'NR==2{print $2}' log.sql`
SQL_POS=`awk -F ':' 'NR==3{print $2}' log.sql`
echo -e "\033[35m this is: $IP $SQL_FILE $SQL_POS \033[0m"
sed -i -e 's/^sed/#sed/g' -e 's/^systemctl/#systemctl/g' sql_log.sh
sh sql_master.sh
#!/bin/bash
DIR_SQL=/etc/my.cnf
SQL_LOG=`mysql -uroot -p123456 -e "show master status\G;" > log.sql`
SQL_FILE=`awk -F ':' 'NR==2{print $2}' log.sql`
SQL_POS=`awk -F ':' 'NR==3{print $2}' log.sql`
#mysql sql
mysql -uroot -p123456 -e "grant replication slave on *.* to '2test'@'$1' identified by '123456';"
mysql -uroot -p123456 -e "stop slave"
mysql -uroot -p123456 -e "change master to master_host='$1',master_user='2test',master_password='123456', master_log_file='$2', master_log_pos=$3;"
mysql -uroot -p123456 -e "start slave"