Node | Host | IP | OS |
---|---|---|---|
Node1 | DB1 | 192.168.56.104 | Centos 7.5 |
Node2 | DB2 | 192.168.56.105 | Centos 7.5 |
Node3 | DB3 | 192.168.56.106 | Centos 7.5 |
注意:不要创建偶数个数的集群,这会导致脑裂
1、安装PXC
先决条件
- 需要主机root权限
开放所需端口
~]# firewall-cmd --add-port=3306/tcp --permanent ~]# firewall-cmd --add-port=4444/tcp --permanent ~]# firewall-cmd --add-port=4567/tcp --permanent ~]# firewall-cmd --add-port=4568/tcp --permanent ~]# firewall-cmd --reload
- 关闭SELinux
安装必要软件
~]# yum install -y openssl socat \ procps-ng chkconfig procps-ng coreutils shadow-utils \ grep libaio libev libcurl perl-DBD-MySQL perl-Digest-MD5 \ libgcc libstdc++ libgcrypt libgpg-error zlib glibc openssl-libs
下载安装
- https://www.percona.com/doc/percona-xtradb-cluster/LATEST/install/yum.html#yum
本例下载后安装
在三个节点上分别安装。[root@db1 pxc]# # yum install percona-xtradb-cluster-server-8.0.19-10.1.el7.x86_64.rpm \ percona-xtradb-cluster-shared-8.0.19-10.1.el7.x86_64.rpm \ percona-xtrabackup-24-2.4.12-1.el7.x86_64.rpm \ percona-xtradb-cluster-client-8.0.19-10.1.el7.x86_64.rpm \ percona-xtradb-cluster-shared-compat-8.0.19-10.1.el7.x86_64.rpm \ qpress-1.1-9.2.x86_64.rpm
首先启动第一个节点
[root@db1 tmp]# systemctl start mysql [root@db1 tmp]# grep 'temporary password' /var/log/mysqld.log 2020-07-02T16:35:09.693714Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: fr6H(XEP%i*i [root@db1 tmp]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 18 Server version: 8.0.19-10 Copyright (c) 2009-2020 Percona LLC and/or its affiliates Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> alter user 'root'@'localhost' identified by 'fr6H(XEP%i*i'; Query OK, 0 rows affected (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql> ###################################### # 然后关闭该节点数据库!!!!!! ###################################### [root@db1 tmp]# systemctl stop mysql
配置Write-Set复制
[root@db1 ~]# vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf [mysqld] # Path to Galera library wsrep_provider=/usr/lib64/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.56.104,192.168.56.105,192.168.56.106 # 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 # Cluster name wsrep_cluster_name=pxc-cluster #If wsrep_node_name is not specified, then system hostname will be used wsrep_node_name=db1 # Node IP address wsrep_node_address=192.168.56.104 #pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING,MASTER pxc_strict_mode=ENFORCING # SST method wsrep_sst_method=xtrabackup-v2 #Authentication for SST method # wsrep_sst_auth="sstuser:s3cp4tretPass" # pxc 8.0 不需要此配置 ############################################################# # 如果配置如下ssl,请确保所有节点 datadir下具有相同的 *pem ############################################################# wsrep_provider_options="socket.ssl_key=server-key.pem;socket.ssl_cert=server-cert.pem;socket.ssl_ca=ca.pem" [sst] encrypt=4 ssl-key=server-key.pem ssl-ca=ca.pem ssl-cert=server-cert.pem ############################################################ [root@db2 ~]# vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf #…… #If wsrep_node_name is not specified, then system hostname will be used wsrep_node_name=db2 # Node IP address wsrep_node_address=192.168.56.105 #…… [root@db3 ~]# vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf #…… #If wsrep_node_name is not specified, then system hostname will be used wsrep_node_name=db3 # Node IP address wsrep_node_address=192.168.56.106 #…… PS: 将该配置文件!include到/etc/my.cnf ######## wsrep ############### !include /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
启动第一个节点
[root@db1 ~]# systemctl start mysql@bootstrap.service # 当有其他节点正常加入进集群之后,可以关闭该节点,以正常方式再次启动 [root@db1 tmp]# mysql -u root -h 127.0.0.1 -P 3306 -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 18 Server version: 8.0.19-10 Percona XtraDB Cluster (GPL), Release rel10, Revision 727f180, WSREP version 26.4.3 Copyright (c) 2009-2020 Percona LLC and/or its affiliates Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show status like 'wsrep%';
创建sst用户,【 pxc 8.0中不需要此步骤 】
mysql> CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 's3cp4tretPass'; Query OK, 0 rows affected (0.01 sec) mysql> GRANT RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT ON *.* TO 'sstuser'@'localhost'; Query OK, 0 rows affected (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
添加其他节点到集群
配置好的节点启动之后会自动加入集群。[root@db2 ~]# systemctl start mysql # 这里有个蹩脚的问题, 如果要启动,datadir下需要为空,但是ssl pem文件需要用于传输(ssh pem文件位于datadir) # 因此,第一次启动失败,然后从节点1传送pem文件到datadir,再次启动即可成功。 [root@db2 tmp]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 19 Server version: 8.0.19-10 Percona XtraDB Cluster (GPL), Release rel10, Revision 727f180, WSREP version 26.4.3 Copyright (c) 2009-2020 Percona LLC and/or its affiliates Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show status like 'wsrep%';
[root@db3 ~]# systemctl start mysql # 这里有个蹩脚的问题, 如果要启动,datadir下需要为空,但是ssl pem文件需要用于传输(ssh pem文件位于datadir) # 因此,第一次启动失败,然后从节点1传送pem文件到datadir,再次启动即可成功。 [root@db3 tmp]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 19 Server version: 8.0.19-10 Percona XtraDB Cluster (GPL), Release rel10, Revision 727f180, WSREP version 26.4.3 Copyright (c) 2009-2020 Percona LLC and/or its affiliates Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show status like 'wsrep%';
关闭并正常启动节点1
[root@db1 tmp]# systemctl stop mysql@bootstrap.service [root@db1 tmp]# [root@db1 tmp]# systemctl start mysql
验证节点间复制