PXC搭建
1. 基本环境搭建
实验环境
主机名 | IP | 系统版本 | 软件版本 |
---|---|---|---|
mysql01 | 192.168.101.101 | centos7 | 5.7.28 |
mysql02 | 192.168.101.102 | centos7 | 5.7.28 |
mysql03 | 192.168.101.103 | centos7 | 5.7.28 |
# 1. 关闭Selinux 修改主机名 同步时间
# 临时关闭
setenforce 0
# 永久关闭
$ cat /etc/selinux/config
SELINUX=disabled
# 2. 修改主机名
$ hostnamectl set-hostname mysql01
$ hostnamectl set-hostname mysql02
$ hostnamectl set-hostname mysql03
# 3. 配置主机名解析
$ vim /etc/hosts
192.168.101.101 mysql01
192.168.101.102 mysql02
192.168.101.103 mysql03
# 4. 防火墙放行以下端口
$ firewall-cmd --add-port=3306/tcp --permanent
success
$ firewall-cmd --add-port=4444/tcp --permanent
success
$ firewall-cmd --add-port=4567/tcp --permanent
success
$ firewall-cmd --add-port=4568/tcp --permanent
success
$ firewall-cmd --reload
success
$ firewall-cmd --list-all
卸载mysql或mariadb
# 查看并卸载 MySQL
$ rpm -qa | grep mysql
mysql-community-common-8.0.22-1.el7.x86_64
mysql-community-libs-8.0.22-1.el7.x86_64
mysql-community-server-8.0.22-1.el7.x86_64
mysql-community-client-plugins-8.0.22-1.el7.x86_64
mysql-community-client-8.0.22-1.el7.x86_64
# 停止服务再卸载
$ systemctl stop mysqld
$ rpm -e --nodeps mysql-community-common-8.0.22-1.el7.x86_64 mysql-community-libs-8.0.22-1.el7.x86_64 mysql-community-server-8.0.22-1.el7.x86_64 mysql-community-client-plugins-8.0.22-1.el7.x86_64 mysql-community-client-8.0.22-1.el7.x86_64
# 删除残留文件
$ rm -rf /var/lib/mysql /var/lib/mysql-keyring /var/lib/mysql-files
# 查看并卸载 MariaDB
$ rpm -qa | grep mariadb
$ rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
$ rpm -qa | grep mariadb
2. 搭建PXC集群
2.1 下载解压工具,qpress,PXC安装包
2.1.1 下载qpress
为了方便后期对PXC集群操作中的使用,需下载qpress,下载地址:https://pkgs.org/download/qpress
2.1.2 PXC安装包下载
下载Percona XtraDB 集群5.7
下载地址:https://www.percona.com/downloads/Percona-XtraDB-Cluster-57/LATEST/
依赖关系提示:“需要:percona-xtrabackup-24 >= 2.4.21”
所以,继续下载了 【Percona-XtraBackup-2.4】
2.1.3 下载Percona-XtraBackup-2.4
下载地址:https://www.percona.com/downloads/Percona-XtraBackup-2.4/
将所有安装包上传至centos7 服务器上在三个服务器上分别安装PXC
2.2 安装
2.2.1 创建安装目录
$ mkdir ./pxc
$ cd ./pxc
2.2.2 解压
$ tar -xvf Percona-XtraBackup-2.4.21-r5988af5-el7-x86_64-bundle.tar
$ tar -xvf Percona-XtraDB-Cluster-5.7.28-31.41-r514-el7-x86_64-bundle.tar
$ rm -rf Percona-XtraBackup-2.4.21-r5988af5-el7-x86_64-bundle.tar Percona-XtraDB-Cluster-5.7.28-31.41-r514-el7-x86_64-bundle.tar
2.2.3 执行命令安装
在三个虚拟机上分别安装 PXC 程序
$ yum localinstall *.rpm
......
Dependency Updated:
e2fsprogs.x86_64 0:1.42.9-19.el7 e2fsprogs-libs.x86_64 0:1.42.9-19.el7 krb5-libs.x86_64 0:1.15.1-50.el7
libcom_err.x86_64 0:1.42.9-19.el7 libselinux.x86_64 0:2.5-15.el7 libselinux-python.x86_64 0:2.5-15.el7
libselinux-utils.x86_64 0:2.5-15.el7 libss.x86_64 0:1.42.9-19.el7 openssl.x86_64 1:1.0.2k-21.el7_9
openssl-libs.x86_64 1:1.0.2k-21.el7_9 zlib.x86_64 0:1.2.7-19.el7_9
Replaced:
mariadb-libs.x86_64 1:5.5.64-1.el7
Complete!
注意,如果提示还有其他需要使用的依赖包,进行下载后再操作一遍命令!
2.2.4 启动mysql
$ systemctl restart mysql
2.2.5 修改root密码
# mysql01节点
$ grep 'temporary password' /var/log/mysqld.log
2021-02-28T04:52:38.657963Z 1 [Note] A temporary password is generated for root@localhost: nuI=n(-7w1ji
# 进入数据库
# 上面的密码为临时密码
$ mysql -uroot -p'nuI=n(-7w1ji'
> alter user 'root'@'localhost' identified by 'Ytl@2032734117';
Query OK, 0 rows affected (0.02 sec)
# 注意:MySQL的 validate_password 插件默认安装。这将要求密码包含至少一个大写字母,一个小写字母,一个数字和一个特殊字符,并且密码总长度至少为8个字符。
# mysql02 节点
$ grep 'temporary password' /var/log/mysqld.log
2021-02-28T04:52:38.418280Z 1 [Note] A temporary password is generated for root@localhost: umhUIkeHo3+1
$ mysql -uroot -p'umhUIkeHo3+1'
> alter user 'root'@'localhost' identified by 'Ytl@2032734117';
Query OK, 0 rows affected (0.03 sec)
# mysql03 节点
$ grep 'temporary password' /var/log/mysqld.log
2021-02-28T04:52:36.897626Z 1 [Note] A temporary password is generated for root@localhost: /;?waoON;0C>
$ mysql -uroot -p'/;?waoON;0C>'
> alter user 'root'@'localhost' identified by 'Ytl@2032734117';
Query OK, 0 rows affected (0.03 sec)
2.3 为写集复制配置相关请求
2.3.1 创建SST同步账号并授权:
> create user 'sstuser'@'localhost' identified by 's3cretPass';
Query OK, 0 rows affected (0.01 sec)
# 必须拥有reload权限,才可以执行flush [tables | logs | privileges]
# 必须拥有lock tables权限,才可以使用lock tables
# process 通过这个权限,用户可以执行SHOW PROCESSLIST和KILL命令。默认情况下,每个用户都可以执行SHOW PROCESSLIST命令,但是只能查询本用户的进程。
# replication client 拥有此权限可以查询master server、slave server状态。
> grant reload,lock tables, process, replication client on *.* to'sstuser'@'localhost';
Query OK, 0 rows affected (0.00 sec)
2.3.2 停止服务
$ systemctl stop mysqld
2.3.3 设置配置文件如下
2.3.3.1 mysql01 配置
$ grep -v '^#' /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
[mysqld]
# 指定galera库路径
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
# 指定群集中节点的IP地址。节点加入群集至少需要一个,但建议列出所有节点的地址。
wsrep_cluster_address=gcomm://192.168.101.101,192.168.101.102,192.168.101.103
# Galera只支持行级复制
binlog_format=ROW
# Galera完全支持InnoDB存储引擎。它与MyISAM或任何其他非事务性存储引擎一起时将不工作
default_storage_engine=InnoDB
# 要使用的从属线程
wsrep_slave_threads= 8
# 通过wsrep_log_conflicts和cert.log_conflicts启用冲突日志记录功能。
# 这些参数在数据库服务器上启用不同形式的冲突日志记录。启用后,节点会记录有关其遇到的冲突的其他信息,例如发生冲突的表和架构的名称以及产生冲突的键的实际值。
wsrep_log_conflicts
# 主键自增长不锁表 只能设置为2,设置为0或1时会无法正确处理死锁问题
# autoinc //,ɔːtoʊ'wɪnk// 自增
innodb_autoinc_lock_mode=2
# 节点IP地址
wsrep_node_address=192.168.101.101
# 指定群集的逻辑名称。集群中的所有节点都必须相同。
wsrep_cluster_name=pxc-cluster
# 为每个节点指定逻辑名称。如果未指定此变量,则主机名将会被使用。
wsrep_node_name=mysql01
# 同步严厉模式 限制PXC启用正在试用阶段的功能,ENFORCING是默认值。
# ENFORCING [ɪnˈfɔːrsɪŋ] 强制执行
pxc_strict_mode=ENFORCING
# 设置SST同步方法,默认情况下,Percona XtraDB集群使用Percona XtraBackup进行状态快照传输(SST)
wsrep_sst_method=xtrabackup-v2
# 设置SST同步用户和密码,此用户必须要创建
wsrep_sst_auth="sstuser:s3cretPass"
# 另外两个节点做相同的配置,不同之处就是名称和IP地址,还有数据库的server_id也不能相同
2.3.3.2 mysql02 配置
$ grep -v '^#' /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
[mysqld]
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
wsrep_cluster_address=gcomm://192.168.101.101,192.168.101.102,192.168.101.103
binlog_format=ROW
default_storage_engine=InnoDB
wsrep_slave_threads= 8
wsrep_log_conflicts
innodb_autoinc_lock_mode=2
wsrep_node_address=192.168.101.102
wsrep_cluster_name=pxc-cluster
wsrep_node_name=mysql02
pxc_strict_mode=ENFORCING
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth="sstuser:s3cretPass"
2.3.3.2 mysql03 配置
$ grep -v '^#' /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
[mysqld]
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
wsrep_cluster_address=gcomm://192.168.101.101,192.168.101.102,192.168.101.103
binlog_format=ROW
default_storage_engine=InnoDB
wsrep_slave_threads= 8
wsrep_log_conflicts
innodb_autoinc_lock_mode=2
wsrep_node_address=192.168.101.103
wsrep_cluster_name=pxc-cluster
wsrep_node_name=mysql03
pxc_strict_mode=ENFORCING
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth="sstuser:s3cretPass"
2.4 第一节点自举启动,初始化集群
配置完所有PXC节点后,通过引导第一个节点来初始化集群。
$ systemctl start mysql@bootstrap.service
确保集群已经初始化
> show status like 'wsrep%';
+----------------------------------+--------------------------------------+
| Variable_name | Value |
+----------------------------------+--------------------------------------+
| wsrep_local_state_uuid | cf11c679-7980-11eb-ab40-97ee879c522c |
| wsrep_protocol_version | 9 |
| wsrep_last_applied | 11 |
| wsrep_last_committed | 11 |
| 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 | 2 |
| wsrep_received_bytes | 146 |
| 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 | 2 |
| wsrep_local_recv_queue_min | 0 |
| wsrep_local_recv_queue_avg | 0.500000 |
| 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 | [ 100, 100 ] |
| wsrep_flow_control_interval_low | 100 |
| wsrep_flow_control_interval_high | 100 |
| 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 | 1320 |
| wsrep_causal_reads | 0 |
| wsrep_cert_interval | 0.000000 |
| wsrep_open_transactions | 0 |
| wsrep_open_connections | 0 |
| 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 | 192.168.101.101:3306 |
| wsrep_cluster_weight | 1 |
| 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 | 36f1d159-7988-11eb-a20b-ee7badefda56 |
| wsrep_cluster_conf_id | 1 |
| wsrep_cluster_size | 1 |
| wsrep_cluster_state_uuid | cf11c679-7980-11eb-ab40-97ee879c522c |
| 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.41(rb3295e6) |
| wsrep_ready | ON |
+----------------------------------+--------------------------------------+
71 rows in set (0.00 sec)
监控
# 1. cluster完整性检测
# cluster中的所有node的该变量的值必须一样, 不一样表示node没有连接到cluster。
wsrep_local_state_uuid
# 表示node是否在它相应的cluster中。cluster中所有node的该变量值应该一样, 不一样则表示nodes被分隔开了, node恢复的时候该变量也会恢复。
wsrep_cluster_conf_id
# 表示cluster中有多少node节点, 等于预期的数量则表示所有node连接到了cluster。
wsrep_cluster_size
# 正常情况下值为Primary, 如果不为Primay,则该node当前不能操作(归咎于多成员关系的改变和quorum([ˈkwɔːrəm] quorum法定人数)的缺失), 同时也可能是产生了脑裂(split-brain[splɪt breɪn] 分裂的大脑)。
# 如果不能Reset quorum, cluster则必须手动进行重引导(rebootstrapped),如下:
# a.关闭所有node节点;
# b.从最近更新(most advanced node)的node节点开始重启所有的nodes(检查 wsrep_last_committed状态变量找到最近更新的node节点)。
wsrep_cluster_status
# 2. 节点状态检查
# 准备状态,该状态变量为On(Ture)时,该node可以接受SQL,否则所有sql query返回 'Unknown Command Error'
wsrep_ready
# 值为OFF,表示该node没有连接到任何cluster 部分。
wsrep_connected
# 节点当前状态
wsrep_local_state
# 状态解释
# 包括Joining, Waiting for SST, Joined, Synced或者Donor
# 在wsrep_ready = OFF时, 且wsrep_local_state_comment为Joining, Waiting for SST,或者Joined时,该node仍然在和cluster同步(syncing);在non-primay部分里,节点的wsrep_local_state_comment状态应该是Initialized。
wsrep_local_state_comment
# 3. 复制健康检查
# 该变量值的范围是0.0 ~ 1.0, 表示复制从上次 show status命令后停止的时间。1.0为完全停止(complete stop). 该变量的值应该接近0.0。保证该值的主要方式包括增加wsrep_slave_threads的数量和从cluster移除执行慢的节点。
wsrep_flow_control_paused
# 表示平均有多少事务可以并发的执行。wsrep_slave_threads的值不应该超过该变量的值。
wsrep_cert_deps_distance
# 4. 检测网络延迟问题
# 该变量的值较高的话, 网络链接可能存在延迟。如果是这个原因,原因可能分布在多层,包括从物理到系统方面的层次。
wsrep_local_send_queue_avg
2.5 将其他节点添加至集群
$ systemctl start mysql
服务器启动后,应自动接收SST。
要检查第二个节点的状态,请运行以下命令 :
$ mysql -uroot -pYtl@2032734117
> show status like 'wsrep%';
+----------------------------------+---------------------------------------------------+
| Variable_name | Value |
+----------------------------------+---------------------------------------------------+
| wsrep_local_state_uuid | cf11c679-7980-11eb-ab40-97ee879c522c |
| wsrep_protocol_version | 9 |
| wsrep_last_applied | 11 |
| wsrep_last_committed | 11 |
| 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 | 228 |
| 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_open_transactions | 0 |
| wsrep_open_connections | 0 |
| 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 | 192.168.101.101:3306,192.168.101.102:3306 |
| wsrep_cluster_weight | 2 |
| wsrep_desync_count | 0 |
| wsrep_evs_delayed | |
| wsrep_evs_evict_list | |
| wsrep_evs_repl_latency | 0.000305493/0.000504777/0.000928415/0.000219778/5 |
| wsrep_evs_state | OPERATIONAL |
| wsrep_gcomm_uuid | 36f8f6ed-7989-11eb-ae9d-874a8dd5c579 |
| wsrep_cluster_conf_id | 2 |
| wsrep_cluster_size | 2 |
| wsrep_cluster_state_uuid | cf11c679-7980-11eb-ab40-97ee879c522c |
| 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.41(rb3295e6) |
| wsrep_ready | ON |
+----------------------------------+---------------------------------------------------+
71 rows in set (0.00 sec)
使用同样的方法加入第三个节点即可:
$ systemctl start mysql
> show status like 'wsrep%';
+----------------------------------+----------------------------------------------------------------+
| Variable_name | Value |
+----------------------------------+----------------------------------------------------------------+
| wsrep_local_state_uuid | cf11c679-7980-11eb-ab40-97ee879c522c |
| wsrep_protocol_version | 9 |
| wsrep_last_applied | 11 |
| wsrep_last_committed | 11 |
| 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 | 302 |
| 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_open_transactions | 0 |
| wsrep_open_connections | 0 |
| 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 | 192.168.101.101:3306,192.168.101.102:3306,192.168.101.103:3306 |
| wsrep_cluster_weight | 3 |
| 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 | 62ad5f6f-7989-11eb-b545-6b459221b6ea |
| wsrep_cluster_conf_id | 3 |
| wsrep_cluster_size | 3 |
| wsrep_cluster_state_uuid | cf11c679-7980-11eb-ab40-97ee879c522c |
| wsrep_cluster_status | Primary |
| wsrep_connected | ON |
| wsrep_local_bf_aborts | 0 |
| wsrep_local_index | 2 |
| wsrep_provider_name | Galera |
| wsrep_provider_vendor | Codership Oy <info@codership.com> |
| wsrep_provider_version | 3.41(rb3295e6) |
| wsrep_ready | ON |
+----------------------------------+----------------------------------------------------------------+
71 rows in set (0.00 sec)
2.6 检查复制
将所有节点添加到群集时,可以通过运行查询和操作节点上的数据来验证复制,以查看这些更改是否在集群中同步。
在第二个节点上创建一个数据库
> create database percona;
Query OK, 1 row affected (0.01 sec)
在所有节点上查看是否成功创建库
> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| percona |
| performance_schema |
| sys |
+--------------------+
在第三个节点上创建一张表
> use percona
Database changed
mysql> create table example (node_id int primary key, node_name varchar(30));
Query OK, 0 rows affected (0.01 sec)
在第一个节点上插入数据
> insert into percona.example values (1,'percona1');
Query OK, 1 row affected (0.01 sec)
从第二个节点上的表中检索行
> select * from percona.example;
+---------+-----------+
| node_id | node_name |
+---------+-----------+
| 1 | percona1 |
+---------+-----------+
1 row in set (0.00 sec)
至此集群搭建完毕