mysql之PXC5.7.18集群系列——1.Percona XtraDB Cluster搭建

1. 相关准备

官方教程:https://www.percona.com/doc/percona-xtradb-cluster/LATEST/install/yum.html#yum
epel介绍:https://fedoraproject.org/wiki/EPEL
epel6下载:https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm

备注:rhel不安装epel,很多集群搭建依赖的包无法通过yum安装,很是不便 

2. 集群节点

Nodes Hostname IP
HAProxy haproxy 172.16.3.30
Node1 mysql01 172.16.3.31
Node2 mysql02 172.16.3.32
Node3 mysql03 172.16.3.33
备注:RHEL6.8,4G内存

3. 先决条件

(1) 开放端口

# iptables -I INPUT -p tcp -m multiport –dport 3306,4444,4567,4568 -j ACCEPT
# service iptables save
# service iptables restart

备注:1.service iptables status 查看防火墙状态  

(2) SELinux

# vim /etc/selinux/config
SELINUX = disabled
# setenforce 0

备注:1.SELINUX = permissive 或者 setenforce 0 都是设置SELINUX状态为permissive,只不过前者需要重启服务器,后者立即生效
备注:2.getenforce 查看SELINUX状态  

4. 安装文件

文件 描述
Percona-XtraDB-Cluster Percona-XtraDB-Cluster-5.7.18-29.20-r346-el6-x86_64-bundle.tar
socat yum -y install socat
libev yum -y install libev
perl-DBD-MySQL yum -y install perl-DBD-MySQL
xtrabackup percona-xtrabackup-24-2.4.6-2.el6.x86_64.rpm
cluster Percona-XtraDB-Cluster-57-5.7.18-29.20.1.el6.x86_64.rpm
client Percona-XtraDB-Cluster-client-57-5.7.18-29.20.1.el6.x86_64.rpm
server Percona-XtraDB-Cluster-server-57-5.7.18-29.20.1.el6.x86_64.rpm
shared Percona-XtraDB-Cluster-shared-57-5.7.18-29.20.1.el6.x86_64.rpm

5. 创建目录

# mkdir -p /home/mysql/{data,log,run,backup}

备注:data,mysql数据目录
备注:log,mysql日志目录
备注:run,mysql运行目录
备注:backup,mysql备份目录,推荐使用xtrabackup

6. my.cnf 配置

(1) Node1

[mysql]
port = 3306
socket = /home/mysql/run/mysql.soc

[mysqld]
### Percona XtraDB Cluster 官方配置 begin
wsrep_provider = /usr/lib64/galera3/libgalera_smm.so
wsrep_cluster_name = pxc-cluster
wsrep_cluster_address = gcomm://172.16.3.31,172.16.3.32,172.16.3.33
wsrep_node_name = pxc1
wsrep_node_address = 172.16.3.31
wsrep_sst_method = xtrabackup-v2
wsrep_sst_auth = sstuser:sstpassword
wsrep_provider_options="gcache.size=8G;" #个人(非官方)强烈推荐
pxc_strict_mode = enforcing
binlog_format = ROW
default_storage_engine = InnoDB
innodb_autoinc_lock_mode = 2
### Percona XtraDB Cluster 官方配置 end

#### 自定义配置 begin
user = mysql
port = 3306

datadir = /home/mysql/data
log-bin = /home/mysql/log/mysql-bin
expire_logs_days = 14
log-error = /home/mysql/log/mysql.err

pid-file = /home/mysql/run/mysql.pid
socket = /home/mysql/run/mysql.soc

character_set_server = utf8
collation_server = utf8_general_ci
### 自定义配置 end

### 性能优化 begin
innodb_buffer_pool_size = 3G #80%
innodb_log_file_size = 256M #5%
innodb_flush_method = O_DIRECT #避免双缓冲技术
max_allowed_packet = 16777216 #最大允许的数据包大小,16M,默认1024*1024*4

sync_binlog = 0 #事务已提交,而无需同步到磁盘
innodb_flush_log_at_trx_commit = 0 #0意味着刷新到磁盘,但不同步(在提交时不执行实际IO)
### 性能优化 end

备注:wsrep_provider_options="gcache.size=8G;",个人强烈推荐,原因:
利用xtrabackup+IST方式而不是SST向已有集群中加入新Node,详见接下来的系列教程。     

(2) Node2

wsrep_node_name = pxc2
wsrep_node_address = 172.16.3.32

(3) Node3

wsrep_node_name = pxc3
wsrep_node_address = 172.16.3.33

7. 文件权限

# chowm -R mysql.mysql /home/mysql

8. 集群启动

(1) Node1

# service mysql bootstrap-pxc

备注:谨记,只要是启动集群的第一个Node(首次搭建集群或者集群全部关闭),都要用此命令  

(2) Node2

# service mysql start

备注:谨记,只要集群有一个Node启动,其余节点都是用此命令  

(3) Node3

# service mysql start

9. 创建账号

mysql> create user 'sstuser'@'localhost' identified by 'sstpassword';
mysql> grant process, reload, lock tables, replication client on *.* to 'sstuser'@'localhost';

备注:sstuser,用于xtrabackup在集群之间同步数据    

10. 查看集群状态

mysql> show status like 'wsrep%';

你可能感兴趣的:(mysql)