一.基本信息
现有pxc三节点:
集群名:pcx_zengxw
节点一:10.16.24.107
节点二:10.16.24.108
节点三:10.16.24.109
节点四: 10.16.24.106(节点三的从库)
Percona-XtraDB-Cluster-5.6.21
现需要将从库增加到pxc集群中,作为pxc的一个节点。
二.10.16.24.106上启用wsrep
确认 Exec_Master_Log_Pos的位置:1306
(product)root@localhost [(none)]> show slave status\G
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 10.16.24.109
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000023
Read_Master_Log_Pos: 1306
Relay_Log_File: relay-bin.000002
Relay_Log_Pos: 1066
Relay_Master_Log_File: mysql-bin.000023
Slave_IO_Running: No
Slave_SQL_Running: No
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: 1306
关闭msyql:
/etc/init.d/mysql stop
启用wsrep,并修改IP:
vi /etc/my.cnf
wsrep_cluster_name=pcx_zengxw
wsrep_cluster_address=gcomm://10.16.24.107,10.16.24.108,10.16.24.109,10.16.24.106
wsrep_node_address=10.16.24.106
wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so
#wsrep_sst_method=rsync
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth=sst:zengxw1
三.10.16.24.109确认PXC同步位置
bash-4.1$ mysqlbinlog -vv mysql-bin.000023 |grep Xid
#160625 11:22:59 server id 1093306 end_log_pos 321 CRC32 0xc10df1ae Xid = 10
#160625 11:23:43 server id 1083306 end_log_pos 523 CRC32 0xb8debe80 Xid = 11
#160626 17:36:46 server id 1093306 end_log_pos 922 CRC32 0x3696d35d Xid = 13
#160626 17:38:40 server id 1083306 end_log_pos 1114 CRC32 0x635af4a2 Xid = 14
#160626 17:39:46 server id 1073306 end_log_pos 1306 CRC32 0x5571ec8f Xid = 15
确认position 1306对应的Xid为15。
将grastate.dat copy到从库对应目录下:
cd /data/mysql/mysql_3306/data
scp -p grastate.dat [email protected]:/data/mysql/mysql_3306/data
四.10.16.24.106设置同步开始位置
cd /data/mysql/mysql_3306/data
vi grastate.dat
将seqno: -1改成seqno: 15
这个就是pxc同步开始的位置。
五.pxc三节点参数更改
增加10.16.24.106到以下参数中:
wsrep_cluster_address=gcomm://10.16.24.107,10.16.24.108,10.16.24.109,10.16.24.106
六.10.16.24.106启动mysql
/etc/init.d/mysql start
七.集群状态检查
各节点(共四个)检查wsrep相关状态是否正常:
show status like 'wsrep%';
重点关注如下状态:
wsrep_incoming_addresses | 10.16.24.109:3306,10.16.24.107:3306,10.16.24.108:3306,10.16.24.106:3306 |
wsrep_local_state | 4
wsrep_local_state_comment | Synced
wsrep_cluster_status | Primary
wsrep_cluster_size | 4
wsrep_connected | ON
wsrep_ready | ON
八.在pxc其它节点插入数据,验证是否同步
pxc节点10.16.24.109:
insert into demo1 select 11,11;
从库10.16.24.106:
select * from demo1;
+----+-----+
| ID | OID |
+----+-----+
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 4 | 4 |
| 5 | 5 |
| 6 | 6 |
| 7 | 8 |
| 8 | 8 |
| 9 | 9 |
| 10 | 10 |
| 11 | 11 |
+----+-----+
11 rows in set (0.00 sec)
pxc节点10.16.24.108:
insert into demo1 select 12,12;
从库10.16.24.106:
select * from demo1;
+----+-----+
| ID | OID |
+----+-----+
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 4 | 4 |
| 5 | 5 |
| 6 | 6 |
| 7 | 8 |
| 8 | 8 |
| 9 | 9 |
| 10 | 10 |
| 11 | 11 |
| 12 | 12 |
+----+-----+
12 rows in set (0.00 sec)
pxc节点10.16.24.107:
insert into demo1 select 13,13;
从库10.16.24.106:
select * from demo1;
----+-----+
| ID | OID |
+----+-----+
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 4 | 4 |
| 5 | 5 |
| 6 | 6 |
| 7 | 8 |
| 8 | 8 |
| 9 | 9 |
| 10 | 10 |
| 11 | 11 |
| 12 | 12 |
| 13 | 13 |
+----+-----+
13 rows in set (0.00 sec)
确认四台pxc之间是同步的。