1. 程式人生 > >新節點線上加入PXC

新節點線上加入PXC

環境

192.168.139.151 新增節點

192.168.139.148-150 叢集節點

 

192.168.139.151 已經安裝好PXC軟體

計劃:

選用192.168.139.150 節點先與192.168.139.151組成主從節點

再轉成叢集節點

構建主從環境

150 節點建立主從同步賬號:

mysql>create user 'bak'@'192.168.139.%' identified by '123456';

mysql>grant replication slave on *.* to 'bak'@'192.168.139.%';

mysql>flush privileges;

150資料拷貝至151上

#mysqldump --single-transaction -uroot -p123456 -A --master-data=2 > all.sql

#scp all.sql [email protected]:/opt/

151上恢復資料

mysql>SET GLOBAL pxc_strict_mode=PERMISSIVE;

#mysql -u root -p123456   < all.sql

151配置主從同步

#####master_log 資訊可在150 使用flsuh logs ; show master status檢視

 change master to master_host='192.168.139.150',master_user='bak',master_password='123456',master_log_file='pxc-bin.000001',master_log_pos=928;

151開啟同步

start slave;

show slave status\G;

151配置叢集

systemctl stop mysql

 

 vim /etc/my.cnf   ===>注意檔案下面的include ,配置檔案可能在指定路徑中,my.cnf只是類似於軟鏈

server-id=4  #與叢集中其他的節點不一樣

[mysqld]
# Path to Galera library
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so # Cluster connection URL contains IPs of nodes
#If no IP is found, this implies that a new cluster needs to be created,
#in order to do that you need to bootstrap this node
wsrep_cluster_address=gcomm://192.168.139.148,192.168.139.149,192.168.139.150,192.168.139.151 # In order for Galera to work correctly binlog format should be ROW
binlog_format=ROW # MyISAM storage engine has only experimental support
default_storage_engine=InnoDB # Slave thread to use
wsrep_slave_threads= 8 wsrep_log_conflicts # This changes how InnoDB autoincrement locks are managed and is a requirement for Galera
innodb_autoinc_lock_mode=2 # Node IP address
wsrep_node_address=192.168.139.151
# Cluster name
wsrep_cluster_name=pxc-cluster #If wsrep_node_name is not specified,  then system hostname will be used
wsrep_node_name=pxc-cluster-node-4 #pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING,MASTER
pxc_strict_mode=ENFORCING # SST method
wsrep_sst_method=xtrabackup-v2 #Authentication for SST method
srep_sst_auth="sstuser:passw0rd"  

150檢查PXC需要同步位置

mysqlbinlog -v -v mysql-bin.000001 | grep Xid   ===》找到position 對應的,沒有 就在MySQL中的表隨便插入什麼東西,執行commit ,在查詢

scp /var/lib/mysql/grastate.dat [email protected]:/var/lib/mysql/

 

151編輯檔案

vim /var/lib/mysql/grastate.dat seqno  ===> 修改成Xid對應的值   chown mysql:mysql /var/lib/mysql/grastate.dat   systemctl start mysql  

151檢視測試結果:

mysql> show status like 'wsrep%'; 可在其他節點插入資料,檢視151節點的資料是否同步