欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Percona-XtraDB-Cluster 5.7版本(PXC)集群部署

程序员文章站 2022-07-01 14:30:59
PXC(Percona-XtraDB-Cluster)5.7版本集群部署 Centos 7.3系统部署Mysql 集群 PXC三个节点分别执行和安装(1)配置hosts cat /etc/hosts172.16.2.10 node1172.16.2.11 node2172.16.2.12 node3 ......

 pxc(percona-xtradb-cluster)5.7版本集群部署

centos 7.3系统部署mysql 集群

pxc三个节点分别执行和安装
(1)配置hosts

cat /etc/hosts
172.16.2.10 node1
172.16.2.11 node2
172.16.2.12 node3

(2)依赖

yum –y remove mariadb-* 
yum -y install gcc gcc-c++ perl-io-socket-ssl.noarch perl-dbd-mysql.x86_64 perl-time-hires openssl* openssl-devel  libcurl-devel wget

(3)下载percona xtrabackup 2.4

wget https://www.percona.com/downloads/percona-xtrabackup-2.4/percona-xtrabackup-2.4.10/binary/redhat/7/x86_64/percona-xtrabackup-24-2.4.10-1.el7.x86_64.rpm
yum -y localinstall percona-xtrabackup-24-2.4.10-1.el7.x86_64.rpm

(4)安装percona release和socat

yum -y install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm
wget 
tar zxvf socat-1.7.3.2.tar.gz
cd socat-1.7.3.2
./configure
make -j 4 && make install

(5)安装pxc 5.7二进制包

wget https://www.percona.com/downloads/percona-xtradb-cluster-latest/percona-xtradb-cluster-5.7.21-29.26/binary/tarball/percona-xtradb-cluster-5.7.21-rel20-29.26.1.linux.x86_64.ssl1:102.tar.gz

tar -xf percona-xtradb-cluster-5.7.21-rel20-29.26.1.linux.x86_64.ssl1_102.tar.gz -c /usr/local/
mv /usr/local/percona-xtradb-cluster-5.7.21-rel20-29.26.1.linux.x86_64.ssl1\:102 /usr/local/mysql
useradd -s /sbin/nologin mysql
chown mysql.mysql -r /usr/local/mysql
mkdir -p /data/mysql/data
chown mysql.mysql -r /data/mysql/
echo 'export path=/usr/local/mysql/bin:$path' > /etc/profile.d/mysql.sh​
source /etc/profile.d/mysql.sh​

先配置第一台机器,并成功启动,在配置其他两台
在第一台主机上创建配置文件:

vim /etc/my.cnf
[client]
port = 3306
socket= /data/mysql/mysql.sock
default-character-set=utf8

[mysqld]
basedir = /usr/local/mysql
datadir = /data/mysql/data
pid-file = /data/mysql/mysql.pid
character-set-server=utf8
init_connect = 'set names utf8'
log-bin=/data/mysql/log_bin
server-id = 101
innodb_buffer_pool_size = 100m
innodb_data_file_path = ibdata1:10m:autoextend
innodb_data_home_dir = /data/mysql
innodb_file_per_table=1
skip-name-resolve
port = 3306
socket = /data/mysql/mysql.sock
user=mysql
log_error=mysql_error.log

#pxc
binlog_format=row
wsrep_cluster_address=gcomm://172.16.2.10,172.16.2.11,172.16.2.12 #三个节点都保持一样
wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so
wsrep_node_address=172.16.2.10 #根据不同的node ip进行修改
wsrep_slave_threads=2
wsrep_cluster_name=pxc_mysql #同一个cluster此值需要一致
wsrep_sst_method=xtrabackup-v2
wsrep_node_name=node_1 #不同节点修改为不同的名字
innodb_autoinc_lock_mode=2
wsrep_sst_auth="sstuser:pxcmysql"
log-slave-updates

[mysql]
no-auto-rehash
default-character-set=utf8


把这个文件写好了,传到其他两台机器的 /etc 下面,
每个主机的server-id 和wsrep_node_address、wsrep_node_name保持不同即可

初始化mysql5.7:(初始化只在第一个节点执行)

mysqld --initialize --user=mysql --datadir=/data/mysql/data

初始化参数使用--initialize-insecure,这样不会设置初始化root密码,如果是 --initialize的话,会随机生成一个密码
grep "password" /data/mysql/data/error.log


启动pxc mysql5.7
​node1上:

/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --wsrep-new-cluster --user=mysql &

新建传送用户:​

grant all privileges on *.* to 'sstuser'@'localhost' identified by 'pxcmysql';(一定要localhost)
flush privileges;

查看集群状态

show status like 'wsrep%';

其他节点安装,具体步骤查看前面步骤
scp percona-xtrabackup-24-2.4.10-1.el7.x86_64.rpm 172.16.2.11:/root
scp percona-xtrabackup-24-2.4.10-1.el7.x86_64.rpm 172.16.2.12:/root
scp percona-xtradb-cluster-5.7.21-rel20-29.26.1.linux.x86_64.ssl1_102.tar.gz 172.16.2.11:/root
scp percona-xtradb-cluster-5.7.21-rel20-29.26.1.linux.x86_64.ssl1_102.tar.gz 172.16.2.12:/root
scp /etc/my.cnf 172.16.2.11:/etc/
scp /etc/my.cnf 172.16.2.12:/etc/

node2和node3启动(无需初始化)

/usr/local/mysql/bin/mysqld_safe  –-defaults-file=/etc/my.cnf &

 

在pxc部署集群多次踩坑:

(1)按照官网文档/etc/init.d/mysql bootstrap-pxc  启动一直失败

解决:一开始怀疑是pxc版本问题,换了二个5.7小版本还是一样报错,最后使用/usr/local/mysql/bin/mysqld_safe 模式启动成功

(2)启动jnode3节点报错:[error] wsrep: command did not run: wsrep_sst_xtrabackup-v2 --role 'donor' --address '172.16.2.12:4444/xtrabackup_sst

解决:修改node3配置文件,用wsrep_sst_method = rsync启动,正常启动后同步数据完成,shutdown node2;然后修改node2的wsrep_sst_method = xtrabackup-v2,可以正常启动数据同步

 以上解决方法希望对你有所帮助,解决方法来之不易,作者多次实验。