0x0034's Blog.

percona-xtradb-cluster-operator 集群安装

字数统计: 843阅读时长: 3 min
2022/04/02

Prepare

安装Helm

1
2
3
4
5
6
7
cd /tmp
rm -rf linux-amd64
wget https://get.helm.sh/helm-v3.8.1-linux-amd64.tar.gz
tar xzvf helm-v3.8.1-linux-amd64.tar.gz
cd linux-amd64
mv helm /usr/local/bin/
chmod 755 /usr/local/bin/helm

克隆percona-helm-charts这个项目

1
2
3
cd /opt/
git clone https://github.com/percona/percona-helm-charts.git
cd percona-helm-charts

安装pxc-operator

1
2
3
4
5
6
cd charts/pxc-operator
# 替换镜像为自己仓库的镜像
sed -i 's/^operatorImageRepository.*/operatorImageRepository: registry.cn-hangzhou.aliyuncs.com\/lcc-middleware\/percona-xtradb-cluster-operator/g' values.yaml

# Helm 安装Operator
helm install pxc-operator .

安装pxc-db

Note: MySQL 5.7 Binlog 不可用

MySQL 5.7 和 MySQL 8.0 根据业务形态和需求选择安装即可.
其中haproxy.enabledproxysql.enabled 字段不能同时为true,原因参见官方文档.

更换私有仓库

1
2
cd /opt/percona-helm-charts/pxc-db/
sed -i 's/^operatorImageRepository.*/operatorImageRepository: registry.cn-hangzhou.aliyuncs.com\/lcc-middleware\/percona-xtradb-cluster-operator/g' production-values.yaml

选择MySQL版本

  • 安装MySQL 5.7集群

安装MySQL 5.7 需要修改production-values.yaml文件中如下的几个键值对:

Note: 其中的镜像地址,为个人仓库地址,可以从官方拉回到自己的仓库中做私有化部署

1
2
3
4
5
6
7
8
9
10
11
...
pxc:
# 这个根据集群规模决定
size: 1
image:
repository: registry.cn-hangzhou.aliyuncs.com/lcc-middleware/percona-xtradb-cluster
# 使用MySQL 5.7
tag: 5.7.36-31.55
# imagePullPolicy: Always
autoRecovery: true
...
  • 安装MySQL 8.0 集群
1
2
3
4
5
6
7
8
9
10
11
...
pxc:
# 这个根据集群规模决定
size: 1
image:
repository: registry.cn-hangzhou.aliyuncs.com/lcc-middleware/percona-xtradb-cluster
# 使用MySQL 8.0
tag: 8.0.23-14.1
# imagePullPolicy: Always
autoRecovery: true
...

(可选) 开启pmm-client

Note: 开启Pmm-client需要先安装pmm-server, 安装文档参考Docker安装pmm-server https://0x0034.github.io/2022/04/02/pmm-server%E5%AE%89%E8%A3%85/

修改production-values.yaml文件中的pmm部分, 修改内容及注释如下所示.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
pmm:
# 打开pmm功能
enabled: true
image:
repository: registry.cn-hangzhou.aliyuncs.com/lcc-middleware/pmm-client
tag: 2.23.0
# 填入pmm-server的地址, 如果你是按照Noto中操作的话,填入宿主机的IP,如果有修改端口记得修改端口, .eq: 192.168.1.111:443
serverHost: xx.xx.xx.xx
# 建议填写admin@localhost
serverUser: admin@localhost
resources:
requests:
memory: 150M
cpu: 300m
limits: {}
...
secrets:
passwords:
# 这里写入pmmserver的admin@localhost的用户密码
pmmserver: entry-your-password
...

密码及其他配置

备份配置

Note: 备份的话默认做PV本地备份,这里不做赘述(家境贫寒,用不起S3)

密码配置

修改production-values.yamlsecrets部分, 内容如下所示:

Note: 建议密码使用同一份, 别给自己找麻烦.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
...
secrets:
## You should be overriding these with your own.
passwords:
# 记得修改自己的密码
root: entry-your-password
xtrabackup: entry-your-password
monitor: entry-your-password
clustercheck: entry-your-password
proxyadmin: entry-your-password
pmmserver: entry-your-password
operator: entry-your-password
replication: entry-your-password
...

安装集群

1
helm install prod -f production-values.yaml /opt/percona-helm-charts/pxc-db/

集群启动, 校验集群

查看集群资源状态

1
kubectl get pods -A -l app.kubernetes.io/managed-by=percona-xtradb-cluster-operator

连接MySQL

1
2
3
4
5
# 获取endpoint
export mysqlHost=$(kubectl get pxc|grep production |awk '{print $2}')
# 需要自行安装MySQL-client
# password: 这个就需要写为自己定义的密码
mysql -u root -h $mysqlHost -pentry-your-password

容灾验证

待定

CATALOG
  1. 1. Prepare
    1. 1.1. 安装Helm
    2. 1.2. 克隆percona-helm-charts这个项目
  2. 2. 安装pxc-operator
  3. 3. 安装pxc-db
    1. 3.1. 更换私有仓库
    2. 3.2. 选择MySQL版本
    3. 3.3. (可选) 开启pmm-client
    4. 3.4. 密码及其他配置
      1. 3.4.1. 备份配置
      2. 3.4.2. 密码配置
    5. 3.5. 安装集群
    6. 3.6. 集群启动, 校验集群
      1. 3.6.1. 查看集群资源状态
      2. 3.6.2. 连接MySQL
  4. 4. 容灾验证