MySQL 高可用架构之 PXC集群

MySQL 高可用架构之 PXC 集群

之前发过一个架构MHA架构~
https://blog.csdn.net/qq_43681593/article/details/104669921

Mha主从架构,vip高可用,用起来麻烦,宕机需要手动添加数据,mha管理机会停止!
Pxc不需要同步,数据强一致性,没有主从,支持节点自动加入,无需手动拷贝。

实验环境

10.0.2.7           PXC1
10.0.2.17          PXC2
10.0.2.27          PXC3
10.0.2.37          PXC4
#目前还没有对centos8主机的镜像源

当然SELinux,防火墙都得关闭,并且需要主机之间时间同步
时间同步实现详解:
https://blog.csdn.net/qq_43681593/article/details/104615240
实验前期准备
配置yum源注意:安装percona不能安装mariadb

#pxc1  清华大学的镜像站
[root@pxc1 ~]#cat /etc/yum.repos.d/pxc.repo
[percona]
name=percona_repo
baseurl=https://mirrors.tuna.tsinghua.edu.cn/percona/release/$releasever/RPMS/$basearch
enabled=1
gpgcheck=0

[root@pxc1 ~]#yum install Percona-XtraDB-Cluster-57 -y
[root@pxc1 ~]#scp /etc/yum.repos.d/pxc.repo 10.0.2.17:/etc/yum.repos.d
[root@pxc1 ~]#scp /etc/yum.repos.d/pxc.repo 10.0.2.27:/etc/yum.repos.d

#pxc2
[root@pxc2 ~]#yum install Percona-XtraDB-Cluster-57 -y


#pxc3
[root@pxc3 ~]#yum install Percona-XtraDB-Cluster-57 -y

实验过程
1、改配置文件

#10.0.2.7
[root@pxc1 ~]#vim  /etc/percona-xtradb-cluster.conf.d/mysqld_safe.cnf 
[mysqld]
server-id=7  

[root@pxc1 ~]#vim  /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
# 前面数字是行号~
8 wsrep_cluster_address=gcomm://10.0.2.7,10.0.2.17,10.0.2.27 
25 #wsrep_node_address=192.168.70.63
26 wsrep_node_address=10.0.2.7
28 wsrep_cluster_name=pxc-zxr-cluster
31 wsrep_node_name=pxc-cluster-node-1
40 wsrep_sst_auth="sstuser:xiurong" 

[root@pxc1 ~]#mkdir /data/logbin/;chown -R mysql.mysql /data/logbin/



#10.0.2.17
[root@pxc2 ~]#vim  /etc/percona-xtradb-cluster.conf.d/mysqld_safe.cnf 
[mysqld]
server-id=17


[root@pxc2 ~]#vim  /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
8 wsrep_cluster_address=gcomm://10.0.2.7,10.0.2.17,10.0.2.27 
25 #wsrep_node_address=192.168.70.63
26 wsrep_node_address=10.0.2.17
28 wsrep_cluster_name=pxc-zxr-cluster
31 wsrep_node_name=pxc-cluster-node-2
40 wsrep_sst_auth="sstuser:xiurong" 






#10.0.2.27
[root@pxc3 ~]#vim  /etc/percona-xtradb-cluster.conf.d/mysqld_safe.cnf 
[mysqld]
server-id=27

[root@pxc3 ~]#vim  /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
8 wsrep_cluster_address=gcomm://10.0.2.7,10.0.2.17,10.0.2.27 
25 #wsrep_node_address=192.168.70.63
26 wsrep_node_address=10.0.2.27
28 wsrep_cluster_name=pxc-zxr-cluster
31 wsrep_node_name=pxc-cluster-node-3
40 wsrep_sst_auth="sstuser:xiurong" 


2、启动PXC第一个节点

[root@pxc1 ~]#grep "temporary password" /var/log/mysqld.log 
2020-03-05T12:05:21.714550Z 1 [Note] A temporary password is generated for root@localhost: Cu?Iq!f,D5*d
[root@pxc1 ~]#mysql -uroot -p'Cu?Iq!f,D5*d'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.28-31-57-log

Copyright (c) 2009-2019 Percona LLC and/or its affiliates
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> alter user 'root'@'localhost' identified by 'xiurong';
Query OK, 0 rows affected (0.00 sec)

#用来实现数据库之间的复制
mysql> create user 'sstuser'@'localhost' identified by 'xiurong';
#授权
mysql> grant reload,lock tables,process,replication client on *.* to 'sstuser'@'localhost';
#查看相关变量
mysql> show variables like 'wsrep%'\G
#查看相关状态变量
mysql> show status like 'wsrep%'\G

#重点关注下面内容
mysql> show status like 'wsrep%';
+----------------------------------+--------------------------------------+
| Variable_name                    | Value                                |
+----------------------------------+--------------------------------------+
| wsrep_local_state_uuid           | 9cb83131-5ed9-11ea-9623-5a294bcbd882 |
| wsrep_local_state                | 4                                    |
| wsrep_local_state_comment        | Synced                               |
| wsrep_cluster_size               | 1                                    |
| wsrep_cluster_state_uuid         | 9cb83131-5ed9-11ea-9623-5a294bcbd882 |
| wsrep_cluster_status             | Primary                              |
| wsrep_connected                  | ON                                   |
| wsrep_ready                      | ON                                   |
+----------------------------------+--------------------------------------+

mysql> show status like 'wsrep_cluster_size';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 1     |
+--------------------+-------+
1 row in set (0.00 sec)

3、在其他节点直接登录验证

[root@pxc2 ~]#systemctl start mysql
[root@pxc2 ~]#ss -ntl
State       Recv-Q Send-Q          Local Address:Port                         Peer Address:Port              
LISTEN      0      128                         *:4567                                    *:*                  
LISTEN      0      128                         *:22                                      *:*                  
LISTEN      0      80                       [::]:3306                                 [::]:*                  
LISTEN      0      128                      [::]:22                                   [::]:* 

[root@pxc2 ~]#mysql -uroot -pxiurong
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.7.28-31-57-log Percona XtraDB Cluster (GPL), Release rel31, Revision ef2fa88, WSREP version 31.41, wsrep_31.41

Copyright (c) 2009-2019 Percona LLC and/or its affiliates
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

#这时候看pxc1节点,如果启动了pxc3节点,以下值就会变成3
mysql> show status like 'wsrep_cluster_size';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 2     |
+--------------------+-------+
1 row in set (0.00 sec)

这个时候这个实验就告一段落了,三个节点都已经启动成功,这样在任意一个节点上面,执行一条DML语句的操作,都会同步到另外两个节点。

4、在PXC集群中加入新的节点

#配置yum源省略
[root@pxc4 ~]#yum install Percona-XtraDB-Cluster-57 -y
[root@pxc4 ~]#vim /etc/percona-xtradb-cluster.conf.d/mysqld.cnf
[mysqld]
server-id=17

[root@pxc4 ~]#vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
8 wsrep_cluster_address=gcomm://10.0.2.7,10.0.2.17,10.0.2.27,10.0.2.37 
25 #wsrep_node_address=192.168.70.63
26 wsrep_node_address=10.0.2.37
28 wsrep_cluster_name=pxc-zxr-cluster
31 wsrep_node_name=pxc-cluster-node-4
40 wsrep_sst_auth="sstuser:xiurong" 


#在其他节点配置

[root@pxc1 ~]#vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
8 wsrep_cluster_address=gcomm://10.0.2.7,10.0.2.17,10.0.2.27,10.0.2.37
[root@pxc2 ~]#vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
8 wsrep_cluster_address=gcomm://10.0.2.7,10.0.2.17,10.0.2.27,10.0.2.37
[root@pxc3 ~]#vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
8 wsrep_cluster_address=gcomm://10.0.2.7,10.0.2.17,10.0.2.27,10.0.2.37


#在PXC4启动服务
[root@pxc4 ~]#systemctl start mysql


#在pxc1节点查看cluster——size的值变为了4。
mysql> show status like 'wsrep_cluster_size';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 4     |
+--------------------+-------+
1 row in set (0.00 sec)

你可能感兴趣的:(linux,centos,mysql)