需求场景:原有的pxc环境数据量已经比较大,新买的服务器要加入此集群中,如何让其用IST的方式传输,而不是SST.
PXC传输数据有两种方式:
IST:Incremental State Transfer 增量同步
SST:State Snapshot Transfer 全量同步
IST 发生的条件:This is done using caching mechanism on nodes (即只发生在之前集群里的节点数据还有在缓存中)
判断方法:
mysql> show global status like 'wsrep_local_cached_downto';+---------------------------+-------+| Variable_name | Value |+---------------------------+-------+| wsrep_local_cached_downto | 1 |+---------------------------+-------+1 row in set (0.00 sec) |
此值小于新开节点的seqno:
[root@zejin241 I6000]# cat grastate.dat # GALERA saved stateversion: 2.1uuid: 6c86dc17-246f-11e6-9955-ae4d7e89eed2seqno: 4cert_index: |
所以我们的思路即通过备份一个集群中节点的数据,恢复到新节点上,并伪造一个grastate.dat,来记录备份数据的seqno,这样当新节点启动时就会自动用IST的方法来进行,而不是SST(注意gcache.size应该有足够的容量来保证在备份及恢复这段时间内新产生的数据都被缓存到)
galera.cache: This file is used as a main writeset store. It's implemented as a permanent ring-buffer filethat is preallocated on disk when the node is initialized. File size can be controlled with the variablegcache.size. If this value is bigger, more writesets are cached and chances are better that the rejoining node will get IST instead of SST. Filename can be changed with the gcache.name variable. |
如下为这次的操作步骤:
node240:192.168.1.240 --已经存在的集群节点
node241:192.168.1.241 --将要加入的集群节点
step1:启动新的集群中的第一个节点
/usr/local/pxc_56/bin/mysqld_safe --defaults-file=/home/mysql/pxc6000.cnf --ledir=/usr/local/pxc_56/bin/ --wsrep-new-cluster &
配置文件如下:
[root@zejin240 I6000]# cat /home/mysql/pxc6000.cnf[client]port = 6000socket = /home/mysql/I6000/mysql.sockdefault-character-set=utf8[mysqld]basedir = /usr/local/pxc_56datadir = /home/mysql/I6000pid-file = /home/mysql/I6000/mysql.pidcharacter-set-server=utf8init_connect = 'SET NAMES utf8'log-bin=/home/mysql/I6000/log_binserver-id = 9816000innodb_buffer_pool_size = 100Minnodb_data_file_path = ibdata1:10M:autoextendinnodb_data_home_dir = /home/mysql/I6000innodb_file_per_table=1skip-name-resolveport = 6000socket = /home/mysql/I6000/mysql.sockuser=mysqllog_error=/home/mysql/I6000/mysql_error.log#pxcuser=mysqllog_error=error.logbinlog_format=ROW#6000 for mysqld port, 6020 for sst port, 6031 for ist port, 6030 for cluster communication portwsrep_cluster_address='gcomm://192.168.1.240:6030,192.168.1.241:6030,192.168.1.242:6030'wsrep_provider=/usr/local/pxc_56/lib/libgalera_smm.sowsrep_sst_receive_address=192.168.1.240:6020wsrep_node_incoming_address=192.168.1.240:6000wsrep_node_address=192.168.1.240:6000wsrep_provider_options = "gmcast.listen_addr=tcp://192.168.1.240:6030;ist.recv_addr=192.168.1.240:6031;"wsrep_slave_threads=2wsrep_cluster_name=pxc_zejinwsrep_sst_method=xtrabackup-v2wsrep_node_name=node6000_240innodb_autoinc_lock_mode=2wsrep_sst_auth="sstuser:123"log-slave-updates[mysql]no-auto-rehashdefault-character-set=utf8 |