您的位置:首页 > 其它

基于gtid复制模式下的主从同步搭建测试

2016-04-27 10:45 696 查看
1.基本信息

主库:

IP:10.16.24.107 port:3377

server-id = 1073377

data_dir:/data/mysql/mysql3377/data/

base_dir:/usr/local/mysql

从库:

IP:10.16.24.108 port:3377

server-id = 1083377

data_dir:/data/mysql/mysql3377/data/

base_dir:/usr/local/mysql

2.先在主库上导出,并将导出文件复制到从库

mysqldump -u root -psafe2016 -S /tmp/mysql3377.sock --master-data=2 --single-transaction -A > A0426_3377.sql

scp A0426_3377.sql
root@10.16.24.108:/data/mysql/mysql3377/data/

3.在从库上将导入数据

mysql -u root -psafe2016 -S /tmp/mysql3377.sock </data/mysql/mysql3377/data/A0426_3377.sql

检查数据库是否有看到:

(product)root@localhost [(none)]> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| lots |

| mysql |

| performance_schema |

+--------------------+

4 rows in set (0.00 sec)

4.主库上建立复制帐号

grant replication slave on *.* to
'repl'@'10.16.24.%' identified by "repl_safe";

5.主库增加或修改如下参数

server-id = 1073377

log-bin = /data/mysql/mysql3377/logs/mysql-bin

binlog_format=row

log-slave-updates #slave更新是否记入日志

gtid-mode=on #启用gtid类型,否则就是普通的复制架构

enforce-gtid-consistency=true #强制GTID的一致性

master-info-repository=TABLE #主服信息记录库=表/文件

relay-log-info-repository=TABLE #中继日志信息记录库

sync-master-info=1 #同步主库信息

slave-parallel-workers=4 #从服务器的SQL线程数,要复制库数目相同

binlog-checksum=CRC32 #校验码

master-verify-checksum=1 #主服校验

slave-sql-verify-checksum=1 #从服校验

binlog-rows-query-log_events=1 #二进制日志详细记录事件

report-port=3377 #提供复制报告端口

report-host=10.16.24.107 #提供复制报告主机

重启主库

6.从库增加或修改如下参数

server-id = 1083377

log-bin = /data/mysql/mysql3377/logs/mysql-bin

binlog_format=row

log-slave-updates

gtid-mode=on

enforce-gtid-consistency=true

master-info-repository=TABLE

relay-log-info-repository=TABLE

sync-master-info=1

slave-parallel-workers=4

binlog-checksum=CRC32

master-verify-checksum=1

slave-sql-verify-checksum=1

binlog-rows-query-log_events=1

report-port=3377

report-host=10.16.24.108

重启从库,并查看uuid。

[mysql@mvxl0783 mysql3377]$ mysql -uroot -psafe_2016 -S /tmp/mysql3376.sock -e "show global variables like '%uuid%';"

Warning: Using a password on the command line interface can be insecure.

+---------------+--------------------------------------+

| Variable_name | Value |

+---------------+--------------------------------------+

| server_uuid | d4d206a0-0b91-11e6-9e4d-0050568a6e64 |

+---------------+--------------------------------------+

7.配置复制环境

从库上操作:

(product)root@localhost [(none)]> change master to master_host='10.16.24.107',master_port=3377, master_user='repl',master_password='repl_safe', master_auto_position=1;

Query OK, 0 rows affected, 2 warnings (0.02 sec)

8.启动slave

start slave;

9.查看状态

(product)root@localhost [(none)]> start slave;

Query OK, 0 rows affected, 1 warning (0.01 sec)

(product)root@localhost [(none)]> show slave status\G

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 10.16.24.107

Master_User: repl

Master_Port: 3377

Connect_Retry: 60

Master_Log_File: mysql-bin.000017

Read_Master_Log_Pos: 406

Relay_Log_File: relay-bin.000002

Relay_Log_Pos: 616

Relay_Master_Log_File: mysql-bin.000017

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB:

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 406

Relay_Log_Space: 814

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert: No

Last_IO_Errno: 0

Last_IO_Error:

Last_SQL_Errno: 0

Last_SQL_Error:

Replicate_Ignore_Server_Ids:

Master_Server_Id: 1073377

Master_UUID: ae2d957d-f682-11e5-94fa-0050568a0bcb

Master_Info_File: mysql.slave_master_info

SQL_Delay: 0

SQL_Remaining_Delay: NULL

Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it

Master_Retry_Count: 86400

Master_Bind:

Last_IO_Error_Timestamp:

Last_SQL_Error_Timestamp:

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set: ae2d957d-f682-11e5-94fa-0050568a0bcb:1

Executed_Gtid_Set: ae2d957d-f682-11e5-94fa-0050568a0bcb:1

Auto_Position: 1

1 row in set (0.00 sec)

10.验证同步

在主库上建立database zengxuewen.

(product)root@localhost [(none)]> show processlist;

+----+------+--------------------+------+------------------+------+-----------------------------------------------------------------------+------------------+

| Id | User | Host | db | Command | Time | State | Info |

+----+------+--------------------+------+------------------+------+-----------------------------------------------------------------------+------------------+

| 2 | repl | 10.16.24.108:53836 | NULL | Binlog Dump GTID | 294 | Master has sent all binlog to slave; waiting for binlog to be updated | NULL |

| 3 | root | localhost | NULL | Query | 0 | init | show processlist |

+----+------+--------------------+------+------------------+------+-----------------------------------------------------------------------+------------------+

2 rows in set (0.00 sec)

在从库查看是否有同步:

(product)root@localhost [(none)]> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| lots |

| mysql |

| performance_schema |

| zengxuewen |

+--------------------+

5 rows in set (0.00 sec)

(product)root@localhost [(none)]> show processlist;

+----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------------+------------------+

| Id | User | Host | db | Command | Time | State | Info |

+----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------------+------------------+

| 8 | system user | | NULL | Connect | 260 | Waiting for master to send event | NULL |

| 9 | system user | | NULL | Connect | 110 | Slave has read all relay log; waiting for the slave I/O thread to update it | NULL |

| 10 | system user | | NULL | Connect | 260 | Waiting for an event from Coordinator | NULL |

| 11 | system user | | NULL | Connect | 260 | Waiting for an event from Coordinator | NULL |

| 12 | system user | | NULL | Connect | 260 | Waiting for an event from Coordinator | NULL |

| 13 | system user | | NULL | Connect | 110 | Waiting for an event from Coordinator | NULL |

| 14 | root | localhost | NULL | Query | 0 | init | show processlist |

+----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------------+------------------+

7 rows in set (0.00 sec)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: