1、配置 Percona 存储库
yum install -y https://repo.percona.com/yum/percona-release-latest.noarch.rpm
percona-release show
percona-release enable-only pxc-80 release
percona-release enable tools release
2、安装 Percona XtraDB 集群包
# 卸载自带mariadb
yum remove -y mariadb*
rm -rf /var/lib/mysql
rm -rf /user/lib64/mysql
# 安装Percona XtraDB 集群
yum install -y percona-xtradb-cluster
3、启动 Percona XtraDB 集群服务器
systemctl start mysql
4、复制超级用户帐户自动生成的临时密码:
grep 'temporary password' /var/log/mysqld.log
5、使用此密码登录root
mysql -u root -p
6、更改超级用户帐户的密码并注销
ALTER USER 'root'@'localhost' IDENTIFIED BY 'rootPass';
7、停止mysql
服务
systemctl stop mysql
8、配置文件
节点一配置文件
# Template my.cnf for PXC
# Edit to your requirements.
[client]
socket=/var/lib/mysql/mysql.sock
[mysqld]
server-id=1
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# Binary log expiration period is 604800 seconds, which equals 7 days
binlog_expire_logs_seconds=604800
######## wsrep ###############
# Path to Galera library
wsrep_provider=/usr/lib64/galera4/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://172.16.10.121,172.16.10.122,172.16.10.123
# In order for Galera to work correctly binlog format should be ROW
binlog_format=ROW
# 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
# Node IP address 节点IP
wsrep_node_address=172.16.10.121
#If wsrep_node_name is not specified, then system hostname will be used
# 节点名称
wsrep_node_name=centos-7-1
default_storage_engine=InnoDB
#pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING,MASTER
pxc_strict_mode=ENFORCING
# SST method
wsrep_sst_method=xtrabackup-v2
[sst]
encrypt=4
ssl-key=server-key.pem
ssl-ca=ca.pem
ssl-cert=server-cert.pem
复制第一个节点的密钥文件到其他节点
scp *.pem centos-7-2:/var/lib/mysql/
scp *.pem centos-7-3:/var/lib/mysql/
# 在其他节点执行,修改文件为mysql用户所属
cd /var/lib/mysql/
chown mysql:mysql *.pem
其他节点配置文件
# 配置文件和节点一保持一致,只需修改下列内容
wsrep_node_address=
wsrep_node_name=
9、集群启动
#关闭第一个节点mysql服务,使用systemctl start mysql@bootstrap.service 命令再次启动
systemctl start mysql@bootstrap.service
#登录第一个节点mysql,查看状态
show status like 'wsrep%';
# 其他节点启动
systemctl start mysql
评论区