在一臺機器上安裝PXC Linux:centos 7 IP:192.168.30.221 PXC版本:Percona-XtraDB-Cluster-5.7.17-rel13-29.20.3.Linux.x86_64.ssl101.tar.gz PXC節點:①192.168.30.221:3306 c ...
在一臺機器上安裝PXC Linux:centos 7 IP:192.168.30.221 PXC版本:Percona-XtraDB-Cluster-5.7.17-rel13-29.20.3.Linux.x86_64.ssl101.tar.gz PXC節點:①192.168.30.221:3306 cluster_address:4030 ②192.168.30.221:3307 cluster_address:5030 ③192.168.30.221:3308 cluster_address:6030 yum -y install rsync wget https://www.percona.com/downloads/Percona-XtraDB-Cluster-LATEST/Percona-XtraDB-Cluster-5.7.17-29.20/binary/tarball/Percona-XtraDB-Cluster-5.7.17-rel13-29.20.3.Linux.x86_64.ssl101.tar.gz 1、將二進位包解壓,添加mysql賬號,做軟連接: mkdir /opt/mysql cd /opt/mysql tar zxvf /data/src/Percona-XtraDB-Cluster-5.7.17-rel13-29.20.3.Linux.x86_64.ssl101.tar.gz cd /usr/local ln -s /opt/mysql/Percona-XtraDB-Cluster-5.7.17-rel13-29.20.3.Linux.x86_64.ssl101/ mysql groupadd mysql useradd -M -g mysql -s /sbin/nologin/ -d /usr/local/mysql mysql 2、新建文件夾請授權: mkdir -p /data/mysql/mysql_3306/{data,logs,tmp} mkdir -p /data/mysql/mysql_3306/logs/binlog mkdir -p /data/mysql/mysql_3307/{data,logs,tmp} mkdir -p /data/mysql/mysql_3307/logs/binlog mkdir -p /data/mysql/mysql_3308/{data,logs,tmp} mkdir -p /data/mysql/mysql_3308/logs/binlog chown -R mysql:mysql /data/mysql/ chown -R mysql:mysql /usr/local/mysql 3、配置文件my.cnf 3306: default_storage_engine=Innodb innodb_locks_unsafe_for_binlog=1 #pxc on a single physical box wsrep_cluster_address='gcomm://192.168.30.221:5030,192.168.30.221:6030' wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so wsrep_sst_receive_address=192.168.30.221:4020 wsrep_node_incoming_address=192.168.30.221 wsrep_slave_threads=2 wsrep_cluster_name=pxc_sampson wsrep_provider_options = "gmcast.listen_addr=tcp://192.168.30.221:4030;" wsrep_sst_method=rsync wsrep_sst_auth=sst:sampson wsrep_node_name=node3306 innodb_autoinc_lock_mode=2 3307: default_storage_engine=Innodb innodb_locks_unsafe_for_binlog=1 #pxc on a single physical box wsrep_cluster_address='gcomm://192.168.30.221:4030,192.168.30.221:6030' wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so wsrep_sst_receive_address=192.168.30.221:5020 wsrep_node_incoming_address=192.168.30.221 wsrep_slave_threads=2 wsrep_cluster_name=pxc_sampson wsrep_provider_options = "gmcast.listen_addr=tcp://192.168.30.221:5030;" wsrep_sst_method=rsync wsrep_sst_auth=sst:sampson wsrep_node_name=node3307 innodb_autoinc_lock_mode=2 3308: default_storage_engine=Innodb innodb_locks_unsafe_for_binlog=1 #pxc on a single physical box wsrep_cluster_address='gcomm://192.168.30.221:4030,192.168.30.221:5030' wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so wsrep_sst_receive_address=192.168.30.221:6020 wsrep_node_incoming_address=192.168.30.221 wsrep_slave_threads=2 wsrep_cluster_name=pxc_sampson wsrep_provider_options = "gmcast.listen_addr=tcp://192.168.30.221:6030;" wsrep_sst_method=rsync wsrep_sst_auth=sst:sampson wsrep_node_name=node3308 innodb_autoinc_lock_mode=2 4、啟動主節點: cd /usr/local/mysql bin/mysqld_safe --defaults-file= /data/mysql/mysql_3306/my.cnf --wsrep-new-cluster 在error.log里看到 [Note] WSREP: Shifting JOINED -> SYNCED (TO: 7) [Note] WSREP: Waiting for SST/IST to complete. [Note] WSREP: New cluster view: global state: f71affa6-2b55-11e7-b8db-6afbe908670d:7, view# 1: Primary, number of nodes: 1, my index: 0, protocol version 3 則啟動成功,登錄mysql -uroot -p 主節點添加賬號: grant usage on *.* to 'pxc-monitor'@'%' identified by 'pxc-monitor'; grant all privileges on *.* to 'sst'@'%' identified by 'sampson'; 5、啟動剩下的兩個節點: bin/mysqld_safe --defaults-file=/data/mysql/mysql_3307/my.cnf 查看對應的error.log,能看到 [Note] WSREP: Shifting JOINER -> JOINED (TO: 7) [Note] WSREP: Member 1.0 (node3307) synced with group. [Note] WSREP: Shifting JOINED -> SYNCED (TO: 7) [Note] WSREP: Synchronized with group, ready for connections 則表示node啟動並加入cluster集群成功。 bin/mysqld_safe --defaults-file=/data/mysql/mysql_3308/my.cnf 6、查看節點個數: mysql> show global status like 'wsrep_cluster_size'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | wsrep_cluster_size | 3 | +--------------------+-------+ 1 row in set (0.02 sec)
註:參考網址https://www.percona.com/doc/percona-xtradb-cluster/5.7/howtos/singlebox.html#how-to-setup-3-node-cluster-on-single-box