安装 Percona-XtraDB-Cluster

架构:

三个节点:

pxc_node_0 30.0.0.196
pxc_node_1 30.0.0.198
pxc_node_2 30.0.0.199

防火墙:

-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 4444 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 4567 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 4568 -j ACCEPT
软件包:
compat-readline5-5.2-17.4.x86_64.rpm
libev4-4.15-7.1.x86_64.rpm
numactl-2.0.9-2.el6.x86_64.rpm
percona-xtrabackup-24-2.4.12-1.el6.x86_64.rpm
Percona-XtraDB-Cluster-57-5.7.23-31.31.2.el6.x86_64.rpm
Percona-XtraDB-Cluster-client-57-5.7.23-31.31.2.el6.x86_64.rpm
Percona-XtraDB-Cluster-devel-57-5.7.23-31.31.2.el6.x86_64.rpm
Percona-XtraDB-Cluster-server-57-5.7.23-31.31.2.el6.x86_64.rpm
Percona-XtraDB-Cluster-shared-57-5.7.23-31.31.2.el6.x86_64.rpm
qpress-11-1.el6.x86_64.rpm
socat-1.7.2.4-1.el6.rf.x86_64.rpm
安装:

下载:

wget https://repo.percona.com/release/centos/6Server/RPMS/x86_64/Percona-XtraDB-Cluster-devel-57-5.7.23-31.31.2.el6.x86_64.rpm
wget https://repo.percona.com/release/centos/6Server/RPMS/x86_64/Percona-XtraDB-Cluster-server-57-5.7.23-31.31.2.el6.x86_64.rpm
wget https://repo.percona.com/release/centos/6Server/RPMS/x86_64/Percona-XtraDB-Cluster-57-5.7.23-31.31.2.el6.x86_64.rpm
wget https://repo.percona.com/release/centos/6Server/RPMS/x86_64/Percona-XtraDB-Cluster-client-57-5.7.23-31.31.2.el6.x86_64.rpm
wget https://repo.percona.com/release/centos/6Server/RPMS/x86_64/Percona-XtraDB-Cluster-shared-57-5.7.23-31.31.2.el6.x86_64.rpm
wget https://repo.percona.com/release/centos/6Server/RPMS/x86_64/percona-xtrabackup-24-2.4.12-1.el6.x86_64.rpm
wget https://repo.percona.com/release/centos/6Server/RPMS/x86_64/qpress-11-1.el6.x86_64.rpm
wget ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/home:/viliampucik:/obs/RedHat_RHEL-6/x86_64/compat-readline5-5.2-17.4.x86_64.rpm
wget ftp://ftp.pbone.net/mirror/ftp.centos.org/6.9/os/x86_64/Packages/numactl-2.0.9-2.el6.x86_64.rpm
wget ftp://ftp.pbone.net/mirror/apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/socat-1.7.2.4-1.el6.rf.x86_64.rpm
wget ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/home:/rudi_m:/devel-snap/CentOS_CentOS-6/x86_64/libev4-4.15-7.1.x86_64.rpm

安装:

rpm -ivh libev4-4.15-7.1.x86_64.rpm
rpm -ivh socat-1.7.2.4-1.el6.rf.x86_64.rpm
rpm -ivh numactl-2.0.9-2.el6.x86_64.rpm
rpm -ivh compat-readline5-5.2-17.4.x86_64.rpm
rpm -ivh percona-xtrabackup-24-2.4.8-1.el6.x86_64.rpm
rpm -ivh qpress-11-1.el6.x86_64.rpm
rpm -ivh Percona-XtraDB-Cluster-shared-57-5.7.19-29.22.3.el6.x86_64.rpm
rpm -ivh Percona-XtraDB-Cluster-client-57-5.7.19-29.22.3.el6.x86_64.rpm
rpm -ivh Percona-XtraDB-Cluster-57-5.7.19-29.22.3.el6.x86_64.rpm
rpm -ivh Percona-XtraDB-Cluster-server-57-5.7.19-29.22.3.el6.x86_64.rpm
rpm -ivh Percona-XtraDB-Cluster-devel-57-5.7.19-29.22.3.el6.x86_64.rpm
配置:

配置文件:

vim /etc/my.cnf
[client]
port=3306
socket = /tmp/mysql.sock [mysqld]
server-id=1
port=3306
datadir=/data/database/mysql
socket=/tmp/mysql.sock
log-error=/var/run/mysqld/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
user=mysql # General
back_log=2000
connect_timeout=15
skip_name_resolve=ON
max_connections=5000
table_definition_cache=2000
table_open_cache=10000
metadata_locks_hash_instances=256
ssl=0
core_file # Innodb
innodb_buffer_pool_size = 10240M
innodb_buffer_pool_instances=8
innodb_log_file_size = 1024M
innodb_log_buffer_size = 16M
innodb_lock_wait_timeout = 20
innodb_autoinc_lock_mode=2
innodb_read_io_threads = 5
innodb_write_io_threads = 5
innodb_thread_concurrency = 8
innodb_doublewrite=1
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = 'O_DIRECT'
innodb-page-cleaners=8
innodb_purge_threads=4
innodb_lru_scan_depth=2048
innodb_io_capacity=8000
innodb_io_capacity_max=16000
innodb_adaptive_hash_index=OFF
innodb-change-buffering=none
innodb_flush_neighbors=0
innodb_max_dirty_pages_pct = 90
innodb_max_dirty_pages_pct_lwm = 10 # Binlog
relay-log=relay-1
binlog_format=ROW
enforce-gtid-consistency
gtid-mode=on
master-info-repository=TABLE
relay-log-info-repository=TABLE
binlog-checksum=NONE
log-bin
log_slave_updates
expire_logs_days=3
sync_binlog=1 # Monitoring
innodb_monitor_enable='%'
performance_schema=ON
performance_schema_instrument='%synch%=on' # Galera
symbolic-links=0
explicit_defaults_for_timestamp=true
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
wsrep_cluster_address=gcomm://30.0.0.196,30.0.0.198,30.0.0.199
default_storage_engine=InnoDB
wsrep_slave_threads= 20
wsrep_log_conflicts
wsrep_cluster_name=pxc-cluster
wsrep_node_name=pxc3
wsrep_node_address=30.0.0.196
pxc_strict_mode=ENFORCING
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth="sstuser:s3cret"

差异化配置:

# 需要根据相应的节点配置
server-id=1
wsrep_node_name=pxc3
wsrep_node_address=30.0.0.196

配置数据目录:

mkdir -p /data/database/mysql
chown mysql:mysql -R /data/database/mysql
启动:

启动第一个节点

/etc/init.d/mysql bootstrap-pxc

或者这样:

# 初始化
/usr/sbin/mysqld --defaults-file=/etc/my.cnf --initialize --datadir=/data/database/mysql --user=mysql
# 启动
/usr/bin/mysqld_safe --defaults-file=/etc/my.cnf --wsrep-new-cluster &

查看密码

# root初始化密码被记录到log-error中
grep 'temporary password' /var/run/mysqld/mysqld.log

修改root密码,并配置SST认证账号

mysql> CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 's3cret';
mysql> GRANT RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT ON *.* TO 'sstuser'@'localhost';
mysql> FLUSH PRIVILEGES;

启动其他节点

/etc/init.d/mysql start

各个加点都采用第一个几点修改的root密码登录

偷窥一下:

查看节点数:

show global status like 'wsrep_cluster_size';

查看集群状态:

show global status like 'wsrep%';

查看当前节点状态:

show global status like 'wsrep_cluster_status';

讲点小故事

重要的配置参数
  • wsrep_provider:指定Galera库路径,没有这个库,节点只是一个MySQL单实例,无法参与pxc集群

    • Debian or Ubuntu: /usr/lib/libgalera_smm.so
    • Red Hat or CentOS: /usr/lib64/galera3/libgalera_smm.so
  • wsrep_cluster_name:集群名称,所有节点相同

  • wsrep_cluster_address:集群所有节点IP地址列表

  • wsrep_node_name:节点名称,默认为主机名称

  • wsrep_node_address:节点IP地址

  • wsrep_sst_method:指定SST方法,推荐wsrep_sst_method=xtrabackup-v2

  • wsrep_sst_auth:SST认证账号密码

    • <sst_user>:<sst_pass>
    • 当第一个节点启动后手动创建该账号密码,并授予相应的权限
  • pxc_strict_mode:PXC严格控制模式,

一些名词解释
  • WS:write set写数据集,写/更新事务

  • IST:Incremental State Transfer 增量同步

  • SST:State Snapshot Transfe 全量同步。

    • SST支持的方法有:mysqldump,rsync ,xtrabackup
    • mysqldump,rsync同步需要READ LOCK, (SST applies FLUSH TABLES WITH READ LOCK command)
    • xtrabackup 在整个同步数据过程中不需要READ LOCK
    • 配置参数:wsrep_sst_method=xtrabackup-v2
  • UUID:节点状态改变及顺序的唯一标识

  • GTID:Global Transaction ID,由UUID和sequence number偏移量组成。wsrep api中定义的集群内部全局事务id,用于记录集群中发生状态改变的唯一标识以及队列中的偏移量。

  • WSRWP API:在DBMS库和wsrep provider之间提供接口

集群端口说明
  • 3306:数据库对外提供服务的端口

  • 4444:全量数据传输SST,集群数据同步端口,全量同步,新节点加入时启用该端口接受数据(DONOR节点接受新节点的请求后会启动一个随机端口主动来连接4444端口)

  • 4567:集群节点间相互通信的端口

  • 4568:增量数据同步IST,节点下线、重启后启用该端口接受数据(DONOR节点接受新节点的请求后会启动一个随机端口主动来连接4568端口)

MySQL PXC集群部署的更多相关文章

  1. MySQL Cluster 集群部署

    前言 此篇博客用以介绍 MySQL Cluster 集群部署方法 一.节点规划 序号 IP地址 节点名称 1 172.16.1.201 mysql-manage 2 172.16.1.202 mysq ...

  2. MySQL PXC集群安装配置

    1.关闭防火墙 [root@node04 ~]#systemctl disable firewalld [root@node04 ~]#systemctl stop firewalld [root@n ...

  3. MySQL数据库高可用集群搭建-PXC集群部署

    Percona XtraDB Cluster(下文简称PXC集群)提供了MySQL高可用的一种实现方法.集群是有节点组成的,推荐配置至少3个节点,但是也可以运行在2个节点上. PXC原理描述: 分布式 ...

  4. docker中mysql pxc集群

    PXC集群 https://hub.docker.com/r/percona/percona-xtradb-cluster 安装PXC镜像 下载镜像或者导入本地镜像 docker pull perco ...

  5. Galera Cluster mysql+keepalived集群部署

    1.卸载mysql 查找本机安装的mysqlrpm -qa | grep -i mysql --nodeps --force rpm -ev MySQL-server-5.6.15-1.el6.x86 ...

  6. mysql PXC集群方案总结

    同时写集群内的所有机器 写性能依赖最慢的那个机器 读性能提高X倍

  7. docker mysql pxc集群(percona-xtradb-cluster)

    docker pull percona/percona-xtradb-cluster docker tag percona/percona-xtradb-cluster pxc docker netw ...

  8. 02使用java脚本向Pxc集群写入数据

    使用java脚本向Pxc集群写入数据 批量写入pxc集群程序 导入mysql驱动包 # 批量插入数据的java脚本 package pxc_demo; import java.sql.Connecti ...

  9. openstack高可用集群21-生产环境高可用openstack集群部署记录

    第一篇 集群概述 keepalived + haproxy +Rabbitmq集群+MariaDB Galera高可用集群   部署openstack时使用单个控制节点是非常危险的,这样就意味着单个节 ...

随机推荐

  1. Android使得Fragment 切换时不重新实例化

    以前实现Fragment的切换都是用replace方法实现 public void startFragmentAdd(Fragment fragment) { FragmentManager frag ...

  2. Linux下的python等操作【转载】

    转自:https://blog.csdn.net/healthy_coder/article/details/50546384 https://blog.csdn.net/boyun58/articl ...

  3. 对接口(interface)的思考

    接口,java中用关键字interface定义.今天学习java基础API时,发现一个特点:每个包中都定义了一堆的接口,感觉有马克思主义中提到的“上层建筑”的味道.接口就是为需要实现的功能定一个基调, ...

  4. JAVA生成六位随机数

    public static String getSixNum() { String str = "0123456789"; StringBuilder sb = new Strin ...

  5. mybatis之注解式开发之关联查询

    package com.bjsxt.mapper; import org.apache.ibatis.annotations.Select; import com.bjsxt.pojo.Clazz; ...

  6. LeetCode167.两数之和II-输入有序数组

    给定一个已按照升序排列 的有序数组,找到两个数使得它们相加之和等于目标数. 函数应该返回这两个下标值 index1 和 index2,其中 index1 必须小于 index2. 说明: 返回的下标值 ...

  7. python windows 安装sklearn

  8. MySQL创建外键约束的报错Error : Can't create table '#sql-534_185' (errno: 150)

    总得来说是因为两个表的字段类型不一致,例如: 两个字段的类型或大小不严格匹配,一个为tinyint,另一个为char:或一个为int(10)另一个为int(9)也是不行的,即使都为int(10),但一 ...

  9. samba共享目录无法访问的一般解决方案,非用户登录和读写权限问题

    配smb,被第四点坑了很久,特此转载. 由于这5点都是比较普通的情况,不涉及用户登录和读写权限问题 1)关闭防火墙: #sevice iptables stop 2)修改 /etc/samba/smb ...

  10. NGINX的几个应用场景

    NGINX的几个应用场景 两个参考地址: NGINX的百度百科:https://baike.baidu.com/item/nginx/3817705?fr=aladdin NGINX的中文网站:htt ...