单机部署PXC

时间:2023-12-22 20:01:38
在一台机器上安装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
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)