基于Docker的MYSQL PXC集群搭建

堵才哲
2023-12-01

pxc集群是Percona XtraDB Cluster的缩写,是基于percona数据库和galera中间件一种特殊MYSQL数据库,而且据说percona数据库的性能要比mysql还要好一些,并且是基于mysql,可以使用mysql的jdbc和客户端进行连接的。

pxc集群相比mysql单一数据库或者mysql主从复制数据库的优点如下

1、所有节点均可读可写,可以轻松的起到HA的作用,任意一台节点宕机都不会影响全局服务

2、在任意一节点写入都是事务强一致性的,不会像主从复制那样使用异步复制的方案导致主从数据不一致的情况。

3、某一个节点宕机之后,再重启恢复后会自动的将宕机期间没有写入的数据补充回来

所以pxc集群不仅可以实现传统的读写分离功能,更在高可用和强一致性上提供了超强的解决方案。大大提高了mysql数据库的可靠性,并且部署还非常简单,下面以基于ubuntu:16.04的docker为例介绍一下在docker部署pxc集群的方法。

官网上也有相关的手册和安装包:https://www.percona.com/software/mysql-database/percona-xtradb-cluster

首先我们需要拉取ubuntu:16.04的操作系统

docker pull ubuntu:16.04

然后我们进入这个docker,安装wget和vim,一会会用到

C:\Users\alex>docker run -itd ubuntu:16.04 /bin/bash
58470aed38c6569fc5a450a59b18163cbfc47c661c830057caed40e180957b67

C:\Users\alex>docker attach 5
root@58470aed38c6:/# apt-get update
root@58470aed38c6:/# apt-get install wget vim

然后下载安装Percona XtraDB Cluster的apt源,方便下载相关安装包,注意下面的xenial为ubuntu16.04的代号,要根据操作系统不同而修改

root@58470aed38c6:/# cd /home
root@58470aed38c6:/home# wget https://repo.percona.com/apt/percona-release_0.1-6.xenial_all.deb

你也可以去https://repo.percona.com/apt/手动选择deb包。

然后我们就可以安装这个deb包,并观察有哪些软件包可以安装了

dpkg -i ./percona-release_0.1-6.xenial_all.deb
apt-get update
apt-cache search percona

软件包列表如下

galera-3 - Replication framework for transactional applications
percona-galera-3 - Galera replication framework for Percona XtraDB Cluster
percona-galera-3-dbg - debugging symbols for percona-galera-3
percona-galera-arbitrator-3 - Galera arbitrator daemon for Percona XtraDB Cluster
percona-galera-arbitrator-3-dbg - debugging symbols for percona-galera-arbitrator-3
percona-server-5.6-dbg - Debugging package for Percona Server
percona-server-server - Percona Server database server
percona-server-server-5.6 - Percona Server database server binaries
percona-server-source-5.6 - Percona Server 5.6 source
percona-server-test - Percona Servere regression test suite
percona-server-test-5.6 - Percona Server database test suite
percona-xtrabackup-dbg - Debug symbols for Percona XtraBackup
percona-xtrabackup-test - Test suite for Percona XtraBackup
percona-xtradb-cluster-server - Percona XtraDB Cluster database server
percona-xtradb-cluster-server-5.6 - Percona XtraDB Cluster database server binaries
xtrabackup - Transitional package for percona-xtrabackup
libperconaserverclient18 - Percona Server database client library
libperconaserverclient18-dev - Percona Server database development files
libperconaserverclient18.1 - Percona Server database client library
libperconaserverclient18.1-dev - Percona Server database development files
libperconaserverclient20 - Percona Server database client library
libperconaserverclient20-dev - Percona Server database development files
percona-cacti-templates - Percona Monitoring Plugins for Cacti
percona-nagios-plugins - Percona Monitoring Plugins for Nagios
percona-release - Package to install Percona gpg key and APT repo
percona-server-5.5-dbg - Debugging package for Percona Server
percona-server-5.7-dbg - Debugging package for Percona Server
percona-server-client - Percona Server database client
percona-server-client-5.5 - Percona Server database client binaries
percona-server-client-5.6 - Percona Server database client binaries
percona-server-client-5.7 - Percona Server database client binaries
percona-server-common-5.5 - Percona Server database common files
percona-server-common-5.6 - Percona Server database common files (e.g. /etc/mysql/my.cnf)
percona-server-common-5.7 - Percona Server database common files (e.g. /etc/mysql/my.cnf)
percona-server-mongodb - This metapackage will install the mongo shell, import/export tools, other client utilities, server software, default configuration, and init.d scripts.
percona-server-mongodb-32 - This metapackage will install the mongo shell, import/export tools, other client utilities, server software, default configuration, and init.d scripts.
percona-server-mongodb-32-dbg - Debugging package for Percona Server for MongoDB
percona-server-mongodb-32-mongos - This package contains mongos - the Percona Server for MongoDB sharded cluster query router
percona-server-mongodb-32-server - This package contains the Percona Server for MongoDB server software, default configuration files and init.d scripts
percona-server-mongodb-32-shell - This package contains the Percona Server for MongoDB shell
percona-server-mongodb-32-tools - Mongo tools for high-performance MongoDB fork from Percona
percona-server-mongodb-34 - This metapackage will install the mongo shell, import/export tools, other client utilities, server software, default configuration, and init.d scripts.
percona-server-mongodb-34-dbg - Debugging package for Percona Server for MongoDB
percona-server-mongodb-34-mongos - This package contains mongos - the Percona Server for MongoDB sharded cluster query router
percona-server-mongodb-34-server - This package contains the Percona Server for MongoDB server software, default configuration files and init.d scripts
percona-server-mongodb-34-shell - This package contains the Percona Server for MongoDB shell
percona-server-mongodb-34-tools - Mongo tools for high-performance MongoDB fork from Percona
percona-server-mongodb-36 - This metapackage will install the mongo shell, import/export tools, other client utilities, server software, default configuration, and init.d scripts.
percona-server-mongodb-36-dbg - Debugging package for Percona Server for MongoDB
percona-server-mongodb-36-mongos - This package contains mongos - the Percona Server for MongoDB sharded cluster query router
percona-server-mongodb-36-server - This package contains the Percona Server for MongoDB server software, default configuration files and init.d scripts
percona-server-mongodb-36-shell - This package contains the Percona Server for MongoDB shell
percona-server-mongodb-36-tools - Mongo tools for high-performance MongoDB fork from Percona
percona-server-mongodb-dbg - Debugging package for Percona Server for MongoDB
percona-server-mongodb-mongos - This package contains mongos - the Percona Server for MongoDB sharded cluster query router
percona-server-mongodb-server - This package contains the Percona Server for MongoDB server software, default configuration files and init.d scripts
percona-server-mongodb-shell - This package contains the Percona Server for MongoDB shell
percona-server-mongodb-tools - Mongo tools for high-performance MongoDB fork from Percona
percona-server-rocksdb-5.7 - MyRocks storage engine plugin for Percona Server
percona-server-server-5.5 - Percona Server database server binaries
percona-server-server-5.7 - Percona Server database server binaries
percona-server-source-5.5 - Percona Server 5.5 source
percona-server-source-5.7 - Percona Server 5.7 source
percona-server-test-5.5 - Percona Server database test suite
percona-server-test-5.7 - Percona Server database test suite
percona-server-tokudb-5.6 - TokuDB engine plugin for Percona Server
percona-server-tokudb-5.7 - TokuDB engine plugin for Percona Server
percona-toolkit - Advanced MySQL and system command-line tools
percona-xtrabackup - Open source backup tool for InnoDB and XtraDB
percona-xtrabackup-24 - Open source backup tool for InnoDB and XtraDB
percona-xtrabackup-dbg-24 - Debug symbols for Percona XtraBackup
percona-xtrabackup-test-24 - Test suite for Percona XtraBackup
percona-xtradb-cluster-5.6-dbg - Debugging package for Percona XtraDB Cluster
percona-xtradb-cluster-5.7-dbg - Debugging package for Percona XtraDB Cluster
percona-xtradb-cluster-56 - Percona XtraDB Cluster with Galera
percona-xtradb-cluster-57 - Percona XtraDB Cluster with Galera
percona-xtradb-cluster-client-5.6 - Percona XtraDB Cluster database client binaries
percona-xtradb-cluster-client-5.7 - Percona XtraDB Cluster database client binaries
percona-xtradb-cluster-common-5.6 - Percona XtraDB Cluster database common files (e.g. /etc/mysql/my.cnf)
percona-xtradb-cluster-common-5.7 - Percona XtraDB Cluster database common files (e.g. /etc/mysql/my.cnf)
percona-xtradb-cluster-full-56 - Percona XtraDB Cluster with Galera
percona-xtradb-cluster-full-57 - Percona XtraDB Cluster with Galera
percona-xtradb-cluster-galera-3 - Metapackage for latest version of galera3.
percona-xtradb-cluster-galera-3.x - Galera components of Percona XtraDB Cluster
percona-xtradb-cluster-galera-3.x-dbg - Debugging package for Percona XtraDB Cluster Galera 3.
percona-xtradb-cluster-galera3-dbg - Metapackage for latest version of debug packages.
percona-xtradb-cluster-garbd-3 - Metapackage for latest version of garbd3.
percona-xtradb-cluster-garbd-3.x - Garbd components of Percona XtraDB Cluster
percona-xtradb-cluster-garbd-3.x-dbg - Debugging package for Percona XtraDB Cluster Garbd 3.
percona-xtradb-cluster-garbd-5.7 - Garbd components of Percona XtraDB Cluster
percona-xtradb-cluster-garbd-debug-5.7 - Debugging package for Percona XtraDB Cluster Garbd.
percona-xtradb-cluster-server-5.7 - Percona XtraDB Cluster database server binaries
percona-xtradb-cluster-server-debug-5.6 - Percona XtraDB Cluster database server UNIV_DEBUG binaries
percona-xtradb-cluster-server-debug-5.7 - Percona XtraDB Cluster database server UNIV_DEBUG binaries
percona-xtradb-cluster-source-5.6 - Percona XtraDB Cluster 5.6 source
percona-xtradb-cluster-source-5.7 - Percona XtraDB Cluster 5.7 source
percona-xtradb-cluster-test-5.6 - Percona XtraDB Cluster database test suite
percona-xtradb-cluster-test-5.7 - Percona XtraDB Cluster database test suite
percona-zabbix-templates - Percona Monitoring Plugins for Zabbix
pmm-client - Percona Monitoring and Management Client

可以发现,有很多软件包可以选择,由于建立多节点读写结构的集群需要用到galera插件,所以我们不如一步到位安装完整版本,这样安装大小虽然会有点大,但是不用费脑筋去研究每个包的功能和依赖了,方法如下

apt-get install percona-xtradb-cluster-full-57

这样也是官方手册上推荐的方案,大概有下面这些软件包需要安装

The following additional packages will be installed:
  bzip2 debsums ifupdown iproute iproute2 isc-dhcp-client isc-dhcp-common krb5-locales libaio1 libasn1-8-heimdal
  libatm1 libboost-program-options1.58.0 libbsd0 libcurl3 libdbd-mysql-perl libdbi-perl libdns-export162 libdpkg-perl
  libev4 libffi6 libfile-fcntllock-perl libfile-fnmatch-perl libgdbm3 libgmp10 libgnutls30 libgssapi-krb5-2
  libgssapi3-heimdal libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal libhogweed4 libhx509-5-heimdal
  libisc-export160 libk5crypto3 libkeyutils1 libkrb5-26-heimdal libkrb5-3 libkrb5support0 libldap-2.4-2 libmecab2
  libmnl0 libmysqlclient20 libnettle6 libnuma1 libp11-kit0 libperl5.22 libpopt0 libroken18-heimdal librtmp1 libsasl2-2
  libsasl2-modules libsasl2-modules-db libtasn1-6 libwind0-heimdal libwrap0 libxtables11 lsof mysql-common netbase
  netcat-openbsd percona-xtrabackup-24 percona-xtradb-cluster-5.7-dbg percona-xtradb-cluster-client-5.7
  percona-xtradb-cluster-common-5.7 percona-xtradb-cluster-garbd-5.7 percona-xtradb-cluster-garbd-debug-5.7
  percona-xtradb-cluster-server-5.7 percona-xtradb-cluster-server-debug-5.7 percona-xtradb-cluster-test-5.7 perl
  perl-modules-5.22 psmisc qpress rename rsync socat tcpd ucf xz-utils
Suggested packages:
  bzip2-doc ppp rdnssd iproute2-doc resolvconf avahi-autoipd isc-dhcp-client-ddns apparmor libclone-perl libmldbm-perl
  libnet-daemon-perl libsql-statement-perl debian-keyring gcc | c-compiler binutils patch gnutls-bin krb5-doc
  krb5-user libsasl2-modules-otp libsasl2-modules-ldap libsasl2-modules-sql libsasl2-modules-gssapi-mit
  | libsasl2-modules-gssapi-heimdal tinyca pv perl-doc libterm-readline-gnu-perl | libterm-readline-perl-perl make
  openssh-client openssh-server
The following NEW packages will be installed:
  bzip2 debsums ifupdown iproute iproute2 isc-dhcp-client isc-dhcp-common krb5-locales libaio1 libasn1-8-heimdal
  libatm1 libboost-program-options1.58.0 libbsd0 libcurl3 libdbd-mysql-perl libdbi-perl libdns-export162 libdpkg-perl
  libev4 libffi6 libfile-fcntllock-perl libfile-fnmatch-perl libgdbm3 libgmp10 libgnutls30 libgssapi-krb5-2
  libgssapi3-heimdal libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal libhogweed4 libhx509-5-heimdal
  libisc-export160 libk5crypto3 libkeyutils1 libkrb5-26-heimdal libkrb5-3 libkrb5support0 libldap-2.4-2 libmecab2
  libmnl0 libmysqlclient20 libnettle6 libnuma1 libp11-kit0 libperl5.22 libpopt0 libroken18-heimdal librtmp1 libsasl2-2
  libsasl2-modules libsasl2-modules-db libtasn1-6 libwind0-heimdal libwrap0 libxtables11 lsof mysql-common netbase
  netcat-openbsd percona-xtrabackup-24 percona-xtradb-cluster-5.7-dbg percona-xtradb-cluster-client-5.7
  percona-xtradb-cluster-common-5.7 percona-xtradb-cluster-full-57 percona-xtradb-cluster-garbd-5.7
  percona-xtradb-cluster-garbd-debug-5.7 percona-xtradb-cluster-server-5.7 percona-xtradb-cluster-server-debug-5.7
  percona-xtradb-cluster-test-5.7 perl perl-modules-5.22 psmisc qpress rename rsync socat tcpd ucf xz-utils
0 upgraded, 80 newly installed, 0 to remove and 2 not upgraded.
Need to get 262 MB of archives.
After this operation, 960 MB of additional disk space will be used.

如果网速好的话,等待三五分钟就能安装完毕,然后我们只需简单配置一下配置文件一个pxc集群就搭建好了。

在安装快要结束的时候会需要你输入数据库登陆的root密码

Configuring percona-xtradb-cluster-server-5.7
---------------------------------------------

Data directory found when no Percona Server package is installed

A data directory '/var/lib/mysql' is present on this system when no MySQL server package is currently installed on the
system. The directory may be under control of server package received from third-party vendors. It may also be an
unclaimed data directory from previous removal of mysql packages.

It is highly recommended to take data backup. If you have not done so, now would be the time to take backup in another
shell. Once completed, press 'Ok' to continue.

Please provide a strong password that will be set for the root account of your MySQL database. Leave it blank to enable
password less login using UNIX socket based authentication.

Enter root password:

Now that you have selected a password for the root account, please confirm by typing it again. Do not share the
password with anyone.

Re-enter root password:

在安装完毕之后,percona数据库会不自觉的开启,所以我们首先要做的就是关闭

service mysql stop

到这里为止,主从节点都是一样的,下面要根据不同节点写不同的配置文件,并使用不同的启动方式

通过deb包安装的percona数据库不要试图修改/etc/mysql/my.cnf,而要把和节点有关的配置写到/etc/mysql/percona-xtradb-cluster.conf.d/wsrep.cnf里面,这个文件已经给了模板,我们只需稍加修改即可


[mysqld]
# Path to Galera library
wsrep_provider=/usr/lib/galera3/libgalera_smm.so  #这里是galera框架的库地址,需要保证你的磁盘上有这个文件

# 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.17.0.2,172.17.0.3,172.7.0.4 #在这里记录集群里所有节点的信息,但不是所有节点都需要开启

# In order for Galera to work correctly binlog format should be ROW
binlog_format=ROW #只能填ROW

# MyISAM storage engine has only experimental support
default_storage_engine=InnoDB

# 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

# Node IP address
wsrep_node_address=172.17.0.2 #填写当前节点的IP地址
# Cluster name
wsrep_cluster_name=pxc-cluster #填写集群的名字,系群里所有节点都要填的一样

#If wsrep_node_name is not specified,  then system hostname will be used
wsrep_node_name=pxc-cluster-node-1 #当前节点的名称,随便填

#pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING,MASTER
pxc_strict_mode=ENFORCING #开启严格强一致模式,没有主键的表将不能操作

# SST method
wsrep_sst_method=xtrabackup-v2

#Authentication for SST method
wsrep_sst_auth=sstuser:123456 #设置一个用户名和密码,这个一会开启mysql后还需要手动再配置一遍

主节点和从节点基本配置都是一样的,区别就两行

  • For the second node:

    wsrep_node_name=pxc2
    wsrep_node_address=172.17.0.3
  • For the third node:

    wsrep_node_name=pxc3
    wsrep_node_address=172.17.0.4

节点的启动是有讲究的,第一个节点要建立上面配置文件里面写的sstuser用户,并且使用bootstrap启动,其余两个节点都可以简单的启动mysql即可。其中在第一个节点要建立如下用户

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

然后就可以开启第一个节点了

/etc/init.d/mysql bootstrap-pxc

然后可以执行一个命令查看当前节点的工作状态,注意另外两个节点不开启也不妨碍当前节点正常工作,在另外两个节点开启后,已经插入的数据会同步到另外两个节点上去。

mysql> show status like 'wsrep%';
+----------------------------+--------------------------------------+
| Variable_name              | Value                                |
+----------------------------+--------------------------------------+
| wsrep_local_state_uuid     | 39e4729d-6345-11e8-8c52-0b4b3546a2be |
| ...                        | ...                                  |
| wsrep_local_state          | 4                                    |
| wsrep_local_state_comment  | Synced                               |
| ...                        | ...                                  |
| wsrep_cluster_size         | 1                                    |
| wsrep_cluster_status       | Primary                              |
| wsrep_connected            | ON                                   |
| ...                        | ...                                  |
| wsrep_ready                | ON                                   |
+----------------------------+--------------------------------------+
40 rows in set (0.01 sec)


开启从节点就简单的多了,只需要把配置文件按照主节点写好,然后启动一下就可以了

/etc/init.d/mysql start

然后在从库上就可以查看当前工作状态

mysql> show status like 'wsrep%';
+----------------------------------+--------------------------------------+
| Variable_name                    | Value                                |
+----------------------------------+--------------------------------------+
| wsrep_local_state_uuid           | 39e4729d-6345-11e8-8c52-0b4b3546a2be |
| wsrep_protocol_version           | 8                                    |
| wsrep_last_applied               | 3                                    |
| wsrep_last_committed             | 3                                    |
| wsrep_replicated                 | 0                                    |
| wsrep_replicated_bytes           | 0                                    |
| wsrep_repl_keys                  | 0                                    |
| wsrep_repl_keys_bytes            | 0                                    |
| wsrep_repl_data_bytes            | 0                                    |
| wsrep_repl_other_bytes           | 0                                    |
| wsrep_received                   | 3                                    |
| wsrep_received_bytes             | 240                                  |
| wsrep_local_commits              | 0                                    |
| wsrep_local_cert_failures        | 0                                    |
| wsrep_local_replays              | 0                                    |
| wsrep_local_send_queue           | 0                                    |
| wsrep_local_send_queue_max       | 1                                    |
| wsrep_local_send_queue_min       | 0                                    |
| wsrep_local_send_queue_avg       | 0.000000                             |
| wsrep_local_recv_queue           | 0                                    |
| wsrep_local_recv_queue_max       | 1                                    |
| wsrep_local_recv_queue_min       | 0                                    |
| wsrep_local_recv_queue_avg       | 0.000000                             |
| wsrep_local_cached_downto        | 0                                    |
| wsrep_flow_control_paused_ns     | 0                                    |
| wsrep_flow_control_paused        | 0.000000                             |
| wsrep_flow_control_sent          | 0                                    |
| wsrep_flow_control_recv          | 0                                    |
| wsrep_flow_control_interval      | [ 141, 141 ]                         |
| wsrep_flow_control_interval_low  | 141                                  |
| wsrep_flow_control_interval_high | 141                                  |
| wsrep_flow_control_status        | OFF                                  |
| wsrep_cert_deps_distance         | 0.000000                             |
| wsrep_apply_oooe                 | 0.000000                             |
| wsrep_apply_oool                 | 0.000000                             |
| wsrep_apply_window               | 0.000000                             |
| wsrep_commit_oooe                | 0.000000                             |
| wsrep_commit_oool                | 0.000000                             |
| wsrep_commit_window              | 0.000000                             |
| wsrep_local_state                | 4                                    |
| wsrep_local_state_comment        | Synced                               |
| wsrep_cert_index_size            | 0                                    |
| wsrep_cert_bucket_count          | 22                                   |
| wsrep_gcache_pool_size           | 1456                                 |
| wsrep_causal_reads               | 0                                    |
| wsrep_cert_interval              | 0.000000                             |
| wsrep_ist_receive_status         |                                      |
| wsrep_ist_receive_seqno_start    | 0                                    |
| wsrep_ist_receive_seqno_current  | 0                                    |
| wsrep_ist_receive_seqno_end      | 0                                    |
| wsrep_incoming_addresses         | 172.17.0.2:3306,172.17.0.3:3306      |
| wsrep_desync_count               | 0                                    |
| wsrep_evs_delayed                |                                      |
| wsrep_evs_evict_list             |                                      |
| wsrep_evs_repl_latency           | 0/0/0/0/0                            |
| wsrep_evs_state                  | OPERATIONAL                          |
| wsrep_gcomm_uuid                 | 84fe5351-6346-11e8-9080-ea323a394028 |
| wsrep_cluster_conf_id            | 2                                    |
| wsrep_cluster_size               | 2                                    |
| wsrep_cluster_state_uuid         | 39e4729d-6345-11e8-8c52-0b4b3546a2be |
| wsrep_cluster_status             | Primary                              |
| wsrep_connected                  | ON                                   |
| wsrep_local_bf_aborts            | 0                                    |
| wsrep_local_index                | 1                                    |
| wsrep_provider_name              | Galera                               |
| wsrep_provider_vendor            | Codership Oy <info@codership.com>    |
| wsrep_provider_version           | 3.26(rac090bc)                       |
| wsrep_ready                      | ON                                   |
+----------------------------------+--------------------------------------+
68 rows in set (0.00 sec)

可以从wsrep_incoming_addresses这一项发现当前有几个激活的了的节点

主库和从库的区别就在于启动方式不一样,谁以bootstrap方式启动谁就是主库,一个从库可以前后隶属于不同的主库,比如一开始跟A是集群,然后我把从库停掉,修改从库的配置文件,把从库归到B集群里,那么在启动过程中就会自动的把从库的数据全部替换为B集群的数据,非常方便,不需要手动干预。

此时我们就可以在主库和从库里写东西,看看两边是否同步了。

像第二个一样,开启第三个节点后,可以在第三个节点上观察集群的运行情况

mysql> show status like 'wsrep%';
+----------------------------------+-------------------------------------------------+
| Variable_name                    | Value                                           |
+----------------------------------+-------------------------------------------------+
| wsrep_local_state_uuid           | 39e4729d-6345-11e8-8c52-0b4b3546a2be            |
| wsrep_protocol_version           | 8                                               |
| wsrep_last_applied               | 4                                               |
| wsrep_last_committed             | 4                                               |
| wsrep_replicated                 | 0                                               |
| wsrep_replicated_bytes           | 0                                               |
| wsrep_repl_keys                  | 0                                               |
| wsrep_repl_keys_bytes            | 0                                               |
| wsrep_repl_data_bytes            | 0                                               |
| wsrep_repl_other_bytes           | 0                                               |
| wsrep_received                   | 3                                               |
| wsrep_received_bytes             | 320                                             |
| wsrep_local_commits              | 0                                               |
| wsrep_local_cert_failures        | 0                                               |
| wsrep_local_replays              | 0                                               |
| wsrep_local_send_queue           | 0                                               |
| wsrep_local_send_queue_max       | 1                                               |
| wsrep_local_send_queue_min       | 0                                               |
| wsrep_local_send_queue_avg       | 0.000000                                        |
| wsrep_local_recv_queue           | 0                                               |
| wsrep_local_recv_queue_max       | 1                                               |
| wsrep_local_recv_queue_min       | 0                                               |
| wsrep_local_recv_queue_avg       | 0.000000                                        |
| wsrep_local_cached_downto        | 0                                               |
| wsrep_flow_control_paused_ns     | 0                                               |
| wsrep_flow_control_paused        | 0.000000                                        |
| wsrep_flow_control_sent          | 0                                               |
| wsrep_flow_control_recv          | 0                                               |
| wsrep_flow_control_interval      | [ 173, 173 ]                                    |
| wsrep_flow_control_interval_low  | 173                                             |
| wsrep_flow_control_interval_high | 173                                             |
| wsrep_flow_control_status        | OFF                                             |
| wsrep_cert_deps_distance         | 0.000000                                        |
| wsrep_apply_oooe                 | 0.000000                                        |
| wsrep_apply_oool                 | 0.000000                                        |
| wsrep_apply_window               | 0.000000                                        |
| wsrep_commit_oooe                | 0.000000                                        |
| wsrep_commit_oool                | 0.000000                                        |
| wsrep_commit_window              | 0.000000                                        |
| wsrep_local_state                | 4                                               |
| wsrep_local_state_comment        | Synced                                          |
| wsrep_cert_index_size            | 0                                               |
| wsrep_cert_bucket_count          | 22                                              |
| wsrep_gcache_pool_size           | 1456                                            |
| wsrep_causal_reads               | 0                                               |
| wsrep_cert_interval              | 0.000000                                        |
| wsrep_ist_receive_status         |                                                 |
| wsrep_ist_receive_seqno_start    | 0                                               |
| wsrep_ist_receive_seqno_current  | 0                                               |
| wsrep_ist_receive_seqno_end      | 0                                               |
| wsrep_incoming_addresses         | 172.17.0.4:3306,172.17.0.2:3306,172.17.0.3:3306 |
| wsrep_desync_count               | 0                                               |
| wsrep_evs_delayed                |                                                 |
| wsrep_evs_evict_list             |                                                 |
| wsrep_evs_repl_latency           | 0/0/0/0/0                                       |
| wsrep_evs_state                  | OPERATIONAL                                     |
| wsrep_gcomm_uuid                 | 0e5b5865-6348-11e8-8a4c-b370847054fd            |
| wsrep_cluster_conf_id            | 3                                               |
| wsrep_cluster_size               | 3                                               |
| wsrep_cluster_state_uuid         | 39e4729d-6345-11e8-8c52-0b4b3546a2be            |
| wsrep_cluster_status             | Primary                                         |
| wsrep_connected                  | ON                                              |
| wsrep_local_bf_aborts            | 0                                               |
| wsrep_local_index                | 0                                               |
| wsrep_provider_name              | Galera                                          |
| wsrep_provider_vendor            | Codership Oy <info@codership.com>               |
| wsrep_provider_version           | 3.26(rac090bc)                                  |
| wsrep_ready                      | ON                                              |
+----------------------------------+-------------------------------------------------+
68 rows in set (0.01 sec)

同时,第三个节点开启之前前两个节点写入的数据都成功同步到了第三节点。

同时,不光从节点可以自由的切换自己所在的集群,主节点也是一样。可以通过启动上的区别加入别的集群成为一个从节点,或者组织新的集群。

如果想使用数据库中间件实现读写分离,那么可以参考我的另外两篇博客

PXC+Replication多主多从MySQL集群搭建

MYCAT轻松实现mysql读写分离

MySQL5.7.18基于事务的主从复制和读写分离



 类似资料: