PXC介绍

全称percona-xtradb-cluster,提供了MySQL高可用的一种实现方法。PXC集群以节点组成(推荐至少3节点,便于故障恢复),每个节点都是基于常规的 MySQL Server,意味着你可以从集群中分离出某节点单独使用,集群中每个节点都包含完整的数据。

PXC特性

  • 同步复制
  • 支持多主复制
  • 支持并行复制
  • 作为高可用方案,实施相对简单

架构图如下所示

部署PXC集群到kubernetes

1、下载部署文件

git clone -b v1.5.0 https://github.com/percona/percona-xtradb-cluster-operator

2、创建CRD

[root@k8s-master001 deploy]# kubectl  apply -f crd.yaml
Warning: apiextensions.k8s.io/v1beta1 CustomResourceDefinition is deprecated in v1.16+, unavailable in v1.22+; use apiextensions.k8s.io/v1 CustomResourceDefinition
customresourcedefinition.apiextensions.k8s.io/perconaxtradbclusters.pxc.percona.com created
customresourcedefinition.apiextensions.k8s.io/perconaxtradbclusterbackups.pxc.percona.com created
customresourcedefinition.apiextensions.k8s.io/perconaxtradbclusterrestores.pxc.percona.com created
customresourcedefinition.apiextensions.k8s.io/perconaxtradbbackups.pxc.percona.com created

3、创建namespace

[root@k8s-master001 deploy]# kubectl create namespace pxc
namespace/pxc created
[root@k8s-master001 deploy]# kubectl config set-context $(kubectl config current-context) --namespace=pxc
Context "kubernetes-admin@kubernetes" modified.

4、创建RBAC

[root@k8s-master001 deploy]# kubectl apply -f rbac.yaml
Warning: rbac.authorization.k8s.io/v1beta1 Role is deprecated in v1.17+, unavailable in v1.22+; use rbac.authorization.k8s.io/v1 Role
role.rbac.authorization.k8s.io/percona-xtradb-cluster-operator created
serviceaccount/percona-xtradb-cluster-operator created
serviceaccount/percona-xtradb-cluster-operator-workload created
Warning: rbac.authorization.k8s.io/v1beta1 RoleBinding is deprecated in v1.17+, unavailable in v1.22+; use rbac.authorization.k8s.io/v1 RoleBinding
rolebinding.rbac.authorization.k8s.io/service-account-percona-xtradb-cluster-operator created

5、创建operator

[root@k8s-master001 deploy]# kubectl  apply -f operator.yaml
deployment.apps/percona-xtradb-cluster-operator created [root@k8s-master001 deploy]# kubectl get po -n pxc
NAME READY STATUS RESTARTS AGE
percona-xtradb-cluster-operator-54d9b7c858-hkmsp 1/1 Running 0 2m19s

6、创建secrets

创建root密码,并修改secrets.yaml中的root字段为新生成的密码
[root@k8s-master001 deploy]# echo -n 'pxcadmin' | base64
cHhjYWRtaW4= [root@k8s-master001 deploy]# kubectl apply -f secrets.yaml
secret/my-cluster-secrets created

7、创建Percona XtraDB Cluster

修改配置

 updateStrategy: OnDelete

指定存储类和存储大小
rook-ceph是k8s的存储类,可以通过kubectl get sc获取
persistentVolumeClaim:
storageClassName: rook-ceph
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 6Gi

执行部署

[root@k8s-master001 deploy]# kubectl  apply -f cr.yaml
perconaxtradbcluster.pxc.percona.com/cluster1 created [root@k8s-master001 deploy]# kubectl get po -n pxc
NAME READY STATUS RESTARTS AGE
cluster1-haproxy-0 2/2 Running 0 17m
cluster1-haproxy-1 2/2 Running 0 15m
cluster1-haproxy-2 2/2 Running 0 13m
cluster1-pxc-0 1/1 Running 0 17m
cluster1-pxc-1 1/1 Running 0 6m28s
cluster1-pxc-2 1/1 Running 0 3m33s

8、验证:

运行一个percona-client
kubectl run -i --rm --tty percona-client --image=percona:5.7 --restart=Never -- bash -il 查看3306代理,这里官方用的是haproxy
sh-4.2$ env|grep 3306
CLUSTER1_HAPROXY_SERVICE_PORT=3306
CLUSTER1_HAPROXY_REPLICAS_PORT_3306_TCP_PORT=3306
CLUSTER1_HAPROXY_PORT=tcp://10.106.76.114:3306 连接数据库,查看集群信息,wsrep_cluster_size=3,表示现在集群有3个节点 ,更多信息自己查看输出信息
sh-4.2$ mysql -h10.106.76.114 -uroot -ppxcadmin
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> show status like 'wsrep%';
+----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Variable_name | Value |
+----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| wsrep_local_state_uuid | 703296d1-f72b-11ea-93ec-5267957b341b |
| wsrep_cluster_capabilities | |
| wsrep_cluster_conf_id | 5 |
| wsrep_cluster_size | 3 |
| wsrep_cluster_state_uuid | 703296d1-f72b-11ea-93ec-5267957b341b |
| wsrep_cluster_status | Primary |
| wsrep_connected | ON |
| wsrep_local_bf_aborts | 0 |
| wsrep_local_index | 2 |
| wsrep_provider_capabilities | :MULTI_MASTER:CERTIFICATION:PARALLEL_APPLYING:TRX_REPLAY:ISOLATION:PAUSE:CAUSAL_READS:INCREMENTAL_WRITESET:UNORDERED:PREORDERED:STREAMING:NBO: |
| wsrep_provider_name | Galera |
| wsrep_provider_vendor | Codership Oy <info@codership.com> |
| wsrep_provider_version | 4.3(r752664d) |
| wsrep_ready | ON |
| wsrep_thread_count | 3 |
+----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
75 rows in set (0.01 sec)

9、说明

kubectl  get po -n pxc
NAME READY STATUS RESTARTS AGE
cluster1-haproxy-0 2/2 Running 0 39m
cluster1-haproxy-1 2/2 Running 0 36m
cluster1-haproxy-2 2/2 Running 0 35m
cluster1-pxc-0 1/1 Running 1 39m
cluster1-pxc-1 1/1 Running 0 28m
cluster1-pxc-2 1/1 Running 0 25m
percona-client 1/1 Running 0 16m
percona-xtradb-cluster-operator-54d9b7c858-hkmsp 1/1 Running 0 65m NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/cluster1-haproxy ClusterIP 10.106.76.114 <none> 3306/TCP,3309/TCP 43m
service/cluster1-haproxy-replicas ClusterIP 10.104.239.57 <none> 3306/TCP 43m
service/cluster1-pxc ClusterIP None <none> 3306/TCP 43m
service/cluster1-pxc-unready ClusterIP None <none> 3306/TCP 43m
  1. 从以上输出可以看到,运行了三个pxc节点,这里可以视为物理机三个mysql节点,除此之外,还有三个haproxy。说明使用haproxy来为pxc集群提供代理服务,进入到cluster1-haproxy-0 可以看到如下信息
server cluster1-pxc-0 cluster1-pxc-0.cluster1-pxc.pxc.svc.cluster.local:3306 check inter 10000 rise 1 fall 2 weight 1
server cluster1-pxc-1 cluster1-pxc-1.cluster1-pxc.pxc.svc.cluster.local:3306 check inter 10000 rise 1 fall 2 weight 1
server cluster1-pxc-2 cluster1-pxc-2.cluster1-pxc.pxc.svc.cluster.local:3306 check inter 10000 rise 1 fall 2 weight 1
  1. 再来看service,创建了cluster1-haproxy,如果在kubernetes集群内部,可以直接通过CLUSTER-IP+PORT访问到数据库

  2. 如果想在集群外部访问到数据库,可以使用前文介绍的Ingress来暴露TCP服务,如果测试,也可使创建一个NodePort来暴露服。务下一篇我们就来就使用前文介绍过的Ingress来把mysql的服务暴露出去,顺便介绍Nginx-Ingress。

Tips: 更多好文章,请关注首发微信公众号“菜鸟运维杂谈”!!!

kubernetes部署Percona XtraDB Cluster集群的更多相关文章

  1. 如何搭建Percona XtraDB Cluster集群

    一.环境准备 主机IP                     主机名               操作系统版本     PXC 192.168.244.146     node1           ...

  2. Percona XtraDB Cluster集群

    官网参考地址: https://www.percona.com/doc/percona-xtradb-cluster/LATEST/configure.html 前期准备: 都用的root权限或使用s ...

  3. mysql之 Percona XtraDB Cluster集群线程模型

    Percona XtraDB集群创建一组线程来为其操作提供服务,这些线程与现有的MySQL线程无关.有三个主要线程组: 一.Applier线程 Applier线程应用从其他节点接收的写入集.写消息直接 ...

  4. Percona XtraDB Cluster集群5.7 开启SSL认证

    mysqldump -uroot -p --ssl-cert=/data/mysql/client-cert.pem --ssl-key=/data/mysql/client-key.pem -h 1 ...

  5. Kubernetes 部署 Nebula 图数据库集群

    Kubernetes 是什么 Kubernetes 是一个开源的,用于管理云平台中多个主机上的容器化的应用,Kubernetes 的目标是让部署容器化的应用简单并且高效,Kubernetes 提供了应 ...

  6. Kubernetes 部署 Nacos 1.4 集群

    文章转载自:http://www.mydlq.club/article/104/ 系统环境: Nacos 版本:1.4.1 Mysql 版本:8.0.19 Kubernetes 版本:1.20.1 一 ...

  7. 部署Percona XtraDB Cluster高可用和多Master集群

    http://www.it165.net/admin/html/201401/2306.html http://www.oschina.net/p/percona-xtradb-cluster/ ht ...

  8. Kubernetes部署SpringCloud(一) Eureka 集群,解决unavailable-replicas,available-replicas条件

    环境 k8s master: 1个 k8s node: 3个 三个eureka 指定node启动,并且使用network=host 完整pom.xml <?xml version="1 ...

  9. Percona XtraDB Cluster Strict Mode(PXC 5.7)

    在Percona XtraDB Cluster集群架构中,为了避免多主节点导致的数据异常,或者说一些不被支持的特性引发的数据不一致的情形,PXC集群可以通过配置pxc_strict_mode这个变量来 ...

随机推荐

  1. getAnnotation的一个坑

    // TableField annotation = f.getAnnotation(TableField.class); // 不建议使用这个,建议使用下面这个方法获取 TableField ann ...

  2. PowerDesigner 使用笔记

    1.将mysql数据结构导入到PowerDesigner https://blog.csdn.net/guochanof/article/details/81905616 2.设计数据库过程 http ...

  3. 计算机网络-传输层(1)UDP协议

    UDP协议基于Internet IP协议,只提供两个基础功能: 分用/复用 分用:主机接收到IP数据报(datagram),每个数据报携带源IP地址.目的IP地址且携带一个传输层的段(Segment) ...

  4. Adversarial Attack Type I: Cheat Classifiers by Significant Changes

    出于实现目的,翻译原文(侵删) Published in: IEEE Transactions on Pattern Analysis and Machine Intelligence (TPAMI ...

  5. 【转】C# 利用反射根据类名创建类的实例对象

    原文地址:https://www.cnblogs.com/feiyuhuo/p/5793606.html “反射”其实就是利用程序集的元数据信息. 反射可以有很多方法,编写程序时请先导入 System ...

  6. Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContex

    问题描述: 在idea中maven构建web项目,启动Tomcat插件时,出现Failed to start component [StandardEngine[Tomcat].StandardHos ...

  7. C# 接口的Get、Post、WebService请求方法一览,值得收藏

    C# 接口的Get.Post.WebService请求方法一览,值得收藏 public static class HttpHelper { const string DEFAULT_USER_AGEN ...

  8. py_创建文件以及写入读取数据+异常处理

    import readline import math import json ''' A: 第一行 第二行 第三行 ''' #从文件读取数据 with open("D:\A.txt&quo ...

  9. hadoop平台环境搭建

    centos01 配置静态ip vim /etc/sysconfig/network-scripts/ifcfg-eth0 见图1 修改主机名 vim /etc/sysconfig/network 见 ...

  10. zstd和zip操作6g的文本

    ssd是在固态硬盘上的时间 1.txt   7038308223 bytes 都是默认级别 ======================================== zstd-v1.4.4-w ...