亲宝软件园·资讯

展开

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

liucx 人气:0

 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 socat libcurl-devel wget

(3)下载Percona XtraBackup 2.4

wget https://www.percona.comhttps://img.qb5200.com/download-x/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

yum -y install http://www.percona.comhttps://img.qb5200.com/download-x/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm

(5)安装PXC 5.7二进制包

wget https://www.percona.comhttps://img.qb5200.com/download-x/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 https://img.qb5200.com/download-x/data/mysqlhttps://img.qb5200.com/download-x/data
  chown mysql.mysql -R https://img.qb5200.com/download-x/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= https://img.qb5200.com/download-x/data/mysql/mysql.sock
default-character-set=utf8

[mysqld]
basedir = /usr/local/mysql
datadir = https://img.qb5200.com/download-x/data/mysqlhttps://img.qb5200.com/download-x/data
pid-file = https://img.qb5200.com/download-x/data/mysql/mysql.pid
character-set-server=utf8
init_connect = 'SET NAMES utf8'
log-bin=https://img.qb5200.com/download-x/data/mysql/log_bin
server-id = 101
innodb_buffer_pool_size = 100M
innodb_data_file_path = ibdata1:10M:autoextend
innodb_data_home_dir = https://img.qb5200.com/download-x/data/mysql
innodb_file_per_table=1
skip-name-resolve
port = 3306
socket = https://img.qb5200.com/download-x/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=https://img.qb5200.com/download-x/data/mysqlhttps://img.qb5200.com/download-x/data

初始化参数使用--initialize-insecure,这样不会设置初始化root密码,如果是 --initialize的话,会随机生成一个密码
grep "password" https://img.qb5200.com/download-x/data/mysqlhttps://img.qb5200.com/download-x/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 &

加载全部内容

相关教程
猜你喜欢
用户评论