MSYQL master-slave replication mode -Gtid

My name He Zhang, greedy lust. A qualified LINUX operation and maintenance engineers, focusing on LINUX study and research, was responsible for the website operation and maintenance of a medium-sized enterprises, loving Buddhist and running.
Personal blog: Chuan Songzhen
author micro letter: zhanghe15069028807

1, MYSQL master copy from mode -Gtid

Main Gtid manner consistent with the principles from the reproduction mode and conventional manner, most of the same configuration, only the configuration different from a fraction.

Gtid master copy from below, from the multi-To, from the following rearrangement once.

1, environment preparation

Database master-slave replication as follows. For multi from, the following test configuration once again from the case.

operating system MYSQL version IP Roles
centos7 5.7 192.168.70.160 Master
centos7 5.7 192.168.70.161 Slave

/etc/hostsFile parsing (two machines the same)

192.168.70.160 master1
192.168.80.161 slave1

2, MasterConfiguration

//打开二进制日志
[root@master1 ~]# cat /etc/my.cnf
[mysqld]
datadir=/mysql
socket=/var/lib/mysql/mysql.sock
log-bin       #打开二进制日志
server-id=160 #给一个server-id
gtid_mode = ON   #打开Gtid
enforce_gtid_consistency = 1    #还有这一行
//重启数据库
[root@master1 ~]# systemctl restart mysqld
//准备数据
[root@master1 ~]# mysql -pcba-123
mysql> create database linuxdb;
mysql> use linuxdb;
mysql> create table t1(id int,name varchar(20));
mysql> insert into t1 values (1,'tt');
mysql> insert into t1 values (2,'ttt');
mysql> select * from t1;
+------+------+
| id   | name |
+------+------+
|    1 | tt   |
|    2 | ttt  |
+------+------+
//确认二进制日志有没有开启
[root@master1 ~]# mysql -pcba-123 -e "show variables like 'log_bin%';"
+---------------------------------+--------------------------+
| Variable_name                   | Value                    |
+---------------------------------+--------------------------+
| log_bin                         | ON                       |
| log_bin_basename                | /mysql/master1-bin       |
| log_bin_index                   | /mysql/master1-bin.index |
| log_bin_trust_function_creators | OFF                      |
| log_bin_use_v1_row_events       | OFF                      |
+---------------------------------+--------------------------+
//授权,允许能够远程连接的主机
mysql> grant replication slave,replication client on *.* to 'rep'@'192.168.70.%' identified by 'Rep123.com';
//导出当前数据,主从复制也要基于全备,这次备份是准备复制给slave主机的
[root@master1 ~]# mysqldump -uroot -pcba-123 --all-databases --single-transaction --master-data=1 --flush-logs >/root/db-$(date +%F)-all.sql;
//传输给slave主机
[root@master1 ~]# scp /root/db-2019-11-30-all.sql root@slave1:/root

replication means is responsive

3. SlaveConfiguration

//检测是否能登录master的数据库
[root@slave1 ~]# mysql -hmaster1 -urep -p'Rep123.com'
//给一个server-id,不用配置bin-log
[root@slave1 ~]# cat /etc/my.cnf
[mysqld]
datadir=/mysql
socket=/var/lib/mysql/mysql.sock
server-id=161
gtid_mode = ON   #打开Gtid
enforce_gtid_consistency = 1    #还有这一行
//重启mysql服务
[root@slave1 ~]# systemctl restart mysqld
//导入数据
[root@slave1 ~]# mysql -uroot -p'cba-123' -e "source /root/db-2019-11-30-all.sql;"
//连接master
mysql> change master to master_host='master1',
master_user='rep',
master_password='Rep123.com',
master_auto_position=1;
//启动slave角色
mysql> start slave;
//查看角色是否同步
mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: master1
                  Master_User: rep
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: master1-bin.000001
          Read_Master_Log_Pos: 154
               Relay_Log_File: slave1-relay-bin.000003
                Relay_Log_Pos: 371
        Relay_Master_Log_File: master1-bin.000001
             Slave_IO_Running: Yes   #这两个线程一定要是YES才可以
            Slave_SQL_Running: Yes   

4, & error to solve

报错一:UUID冲突
Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work.
解决办法:
将从上面的/mysql/auto.cnf更改名字,然后一下数据库
mv /mysql/auto.cnf /mysql/auto.cnf.bak

Guess you like

Origin www.cnblogs.com/yizhangheka/p/11963225.html