将数据从 Zalando 迁移至 Linux on Power ( ppc64le ) 集群上的 CloudNativePG
您可以在以副本模式运行的集群中,通过引导 pg_basebackup 模式将数据从 Zalando 迁移至 CloudNativePG。 要传输数据,您需要创建一个 CloudNativePG 副本集群(目标),该集群将复制 Zalando 数据存储(源)。
先决条件
要从实时集群引导,请完成以下步骤:
- 确保目标和源具有相同的主 PostgreSQL 版本。
- 在 ZalandoPostgreSQL 数据库中,为用户
streaming_replica配置复制和登录角色。
为数据迁移修改 Zalando Postgres 数据存储
要修改 Zalando Postgres 数据存储以进行数据迁移,请完成以下步骤:
连接到 Zalando pod:
查看主 pod 的详细信息:
kubectl get pods -o jsonpath={.items..metadata.name} -l application=spilo,spilo-role=master -n instana-postgres直接在 pod 中运行命令
kubectl exec -it <primary_pod_name> -n instana-postgres连接Postgres数据库:
psql -U postgres列出角色,并在 Zalando 数据库中创建一个具有复制和登录
streaming_replica角色的用户:\du CREATE ROLE streaming_replica WITH REPLICATION; ALTER ROLE streaming_replica WITH LOGIN PASSWORD '<password_retrived_from_zalando>';退出PostgreSQL交互式终端:
\q
在所有 pod 上的
pgdata目录中创建两个名为custom.conf和override.conf的空文件,这些文件与postgresql.conf文件一起存在。列出 pod:
kubectl get pods -n instana-postgres直接在 pod 上运行命令 在所有 pod 上运行以下命令
kubectl exec -it <pod_name> -n instana-postgrescd /var/lib/postgresql/data/pgdata touch -f custom.conf touch -f override.conf
从 pod 终端退出:
exit
使用 CloudNativePG Postgres 操作员创建 Postgres 数据存储以进行数据迁移
在线安装 Postgres 操作员
要在线部署 CloudNativePG Postgres 操作器,请完成以下步骤:
创建
instana-postgres-01名称空间:kubectl create namespace instana-postgres-01确定 Red Hat OpenShift上的文件系统组标识。
Red Hat OpenShift 要求文件系统组在特定于名称空间的值范围内。 在部署了 CloudNativePG Kubernetes 操作器的群集上,运行以下命令:
kubectl get namespace instana-postgres-01 -o yaml对于该命令,将显示类似于以下示例的输出:
apiVersion: v1 kind: Namespace metadata: annotations: ....... openshift.io/sa.scc.uid-range: 1000750000/10000 creationTimestamp: "2024-01-14T07:04:59Z" labels: kubernetes.io/metadata.name: instana-postgres-01 ....... name: instana-postgres-01openshift.io/sa.scc.supplemental-groups注释包含允许的标识范围。 范围1000750000/10000指示以标识1000750000开头的 10,000 个值,因此它指定从1000750000到1000760000的标识范围。 在此示例中,值1000750000可用作文件系统组标识。运行以下 Helm 命令,安装 CloudNativePG Postgres 操作器:
helm repo add instana https://artifact-public.instana.io/artifactory/rel-helm-customer-virtual --username=_ --password=<AGENT_KEY>helm repo updatehelm install cnpg instana/cloudnative-pg --set image.repository=artifact-public.instana.io/self-hosted-images/3rd-party/operator/cloudnative-pg --set image.tag=v1.29.1_v0.34.0 --version=0.28.2 --set imagePullSecrets[0].name=instana-registry --set containerSecurityContext.runAsUser=<UID from namespace> --set containerSecurityContext.runAsGroup=<UID from namespace> -n instana-postgres-01
为
instana-postgres-01名称空间创建映像拉取私钥:kubectl create secret docker-registry instana-registry -n instana-postgres-01 \ --docker-username=_ \ --docker-password=<AGENT_KEY> \ --docker-server=artifact-public.instana.io注: 在创建私钥之前,请使用您自己的代理程序密钥更新 <AGENT_KEY> 值。创建文件 (例如
postgres-secret.yaml) 以进行外部集群访问:kind: Secret apiVersion: v1 metadata: name: instanaadmin type: Opaque stringData: username: instanaadmin password: <user_generated_password_from_zalando>应用 "
postgres-secret.yaml文件:kubectl apply -f postgres-secret.yaml -n instana-postgres-01以
replica模式创建 CloudNativePGCluster资源:创建文件,例如
cnpg-postgres.yaml,如下所示:apiVersion: postgresql.cnpg.io/v1 kind: Cluster metadata: name: postgres spec: instances: 3 imageName: artifact-public.instana.io/self-hosted-images/3rd-party/cnpg-containers:15_v0.39.0 imagePullPolicy: IfNotPresent imagePullSecrets: - name: instana-registry enableSuperuserAccess: true replicationSlots: highAvailability: enabled: true managed: roles: - name: instanaadmin login: true superuser: true createdb: true createrole: true replication: true passwordSecret: name: instanaadmin postgresql: pg_hba: - local all all trust - host replication postgres all trust - host replication streaming_replica 0.0.0.0/0 trust - host all all 0.0.0.0/0 trust - local replication standby trust - hostssl replication standby all md5 - hostnossl all all all reject - hostssl all all all md5 bootstrap: pg_basebackup: source: zalando-postgres replica: enabled: true source: zalando-postgres externalClusters: - name: zalando-postgres connectionParameters: host: postgres.instana-postgres.svc user: postgres password: name: instanaadmin key: password superuserSecret: name: instanaadmin storage: size: 20Gi storageClass: nfs-client通过运行以下命令来应用
cnpg-postgres.yaml文件:kubectl apply -f cnpg-postgres.yaml -n instana-postgres-01
SSH 进入第一个 CloudNativePG pod 的调试容器,修改
postgresql.conf。在以副本方式初始化集群之后,初始 Pod (
postgres-1-pgbasebackup) 状态将为Completed。 随后尝试启动第一个 CloudNativePG Pod (postgres-1)将失败。 这是预期的行为。要确保成功初始化
Cluster并随后启动 Pod ,请完成以下步骤:运行以下命令以确定初始 Pod , SSH 到其中,然后转至包含
pgdata卷的目录:kubectl debug pod/postgres-1 --as-root -n instana-postgres-01cd /var/lib/postgresql/data/pgdata/修改每个 pod 中
postgresql.conf文件内的pg_hba和pg_ident路径:将
pg_hba路径从/var/lib/postgresql/15/main/pg_hba.conf更改为以下路径:/var/lib/postgresql/data/pgdata/pg_hba.conf将
pg_ident路径从/var/lib/postgresql/15/main/pg_ident.conf更改为以下路径:/var/lib/postgresql/data/pgdata/pg_ident.conf
在文件末尾添加
include 'custom.conf'和include 'override.conf':echo "include 'custom.conf'" >> postgresql.conf echo "include 'override.conf'" >> postgresql.conf
重新启动 pod。 豆荚启动后,所有豆荚都从第一个豆荚开始复制。
使用新的 cnpg-cluster。
禁用副本集群:
修改
cnpg-postgres.yaml文件:........ replica: enabled: false source: zalando-postgres ..........重新应用
cnpg-postgres.yaml文件:kubectl apply -f cnpg-postgres.yaml -n instana-postgres-01
连接到数据库:
psql -U postgres更新整理版本:
ALTER DATABASE template1 REFRESH COLLATION VERSION;
更新核心规范配置:
在您的 Instana Core 文件中,请按照以下示例更新配置
postgresConfig:..................... postgresConfigs: - authEnabled: true hosts: - postgres-rw.instana-postgres-01 .....................重新应用
core.yaml文件:kubectl apply -f core.yaml -n instana-core