首页 > 数据库 > > 使用 PD Recover 恢复 PD 集群
PD Recover 是对 PD 进行灾难性恢复的工具,用于恢复无法正常启动或服务的 PD 集群。
下载 TiDB 官方安装包:
wget https://download.pingcap.org/tidb-${version}-linux-amd64.tar.gz
${version} 是 TiDB 集群版本,例如,v4.0.0-rc。
解压安装包:
tar -xzf tidb-${version}-linux-amd64.tar.gz
pd-recover 在 tidb-${version}-linux-amd64/bin 目录下。
本小节详细介绍如何使用 PD Recover 来恢复 PD 集群。
kubectl get tc ${cluster_name} -n ${namespace} -o='go-template={{.status.clusterID}}{{"\n"}}'
示例:
kubectl get tc test -n test -o='go-template={{.status.clusterID}}{{"\n"}}'
6821434242797747735
使用 pd-recover 恢复 PD 集群时,需要指定 alloc-id。alloc-id 的值需要是一个比当前已经分配的最大的 Alloc ID 更大的值。
参考访问监控数据打开 TiDB 集群的 Prometheus 访问页面。
在输入框中输入 pd_cluster_id 并点击 Execute 按钮查询数据,获取查询结果中的最大值。
将查询结果中的最大值乘以 100,作为使用 pd-recover 时指定的 alloc-id。
删除 PD 集群 Pod。
通过如下命令设置 spec.pd.replicas 为 :
kubectl edit tc ${cluster_name} -n ${namespace}
由于此时 PD 集群异常,TiDB Operator 无法将上面的改动同步到 PD StatefulSet,所以需要通过如下命令设置 PD StatefulSet spec.replicas 为 :
kubectl edit sts ${cluster_name}-pd -n ${namespace}
通过如下命令确认 PD Pod 已经被删除:
kubectl get pod -n ${namespace}
确认所有 PD Pod 已经被删除后,通过如下命令删除 PD Pod 绑定的 PVC:
kubectl delete pvc -l app.kubernetes.io/component=pd,app.kubernetes.io/instance=${cluster_name} -n ${namespace}
PVC 删除完成后,扩容 PD 集群至一个 Pod。
通过如下命令设置 spec.pd.replicas 为 1:
kubectl edit tc ${cluster_name} -n ${namespace}
由于此时 PD 集群异常,TiDB Operator 无法将上面的改动同步到 PD StatefulSet,所以需要通过如下命令设置 PD StatefulSet spec.replicas 为 1:
kubectl edit sts ${cluster_name}-pd -n ${namespace}
通过如下命令确认 PD Pod 已经启动:
kubectl get pod -n ${namespace}
通过 port-forward 暴露 PD 服务:
kubectl port-forward -n ${namespace} svc/${cluster_name}-pd 2379:2379
打开一个新终端标签或窗口,进入到 pd-recover 所在的目录,使用 pd-recover 恢复 PD 集群:
./pd-recover -endpoints http://127.0.0.1:2379 -cluster-id ${cluster_id} -alloc-id ${alloc_id}
${cluster_id} 是获取 Cluster ID 步骤中获取的 Cluster ID,${alloc_id} 是获取 Alloc ID 步骤中获取的 pd_cluster_id 的最大值再乘以 100。
pd-recover 命令执行成功后,会打印如下输出:
recover success! please restart the PD cluster
回到 port-forward 命令所在窗口,按 Ctrl+C 停止并退出。
删除 PD Pod:
kubectl delete pod ${cluster_name}-pd-0 -n ${namespace}
Pod 正常启动后,通过 port-forward 暴露 PD 服务:
kubectl port-forward -n ${namespace} svc/${cluster_name}-pd 2379:2379
打开一个新终端标签或窗口,通过如下命令确认 Cluster ID 为获取 Cluster ID 步骤中获取的 Cluster ID:
curl 127.0.0.1:2379/pd/api/v1/cluster
回到 port-forward 命令所在窗口,按 Ctrl+C 停止并退出。
通过如下命令设置 spec.pd.replicas 为期望的 Pod 数量:
kubectl edit tc ${cluster_name} -n ${namespace}
kubectl delete pod -l app.kubernetes.io/component=tidb,app.kubernetes.io/instance=${cluster_name} -n ${namespace} &&
kubectl delete pod -l app.kubernetes.io/component=tikv,app.kubernetes.io/instance=${cluster_name} -n ${namespace}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31537575/viewspace-3118390/ ,如需转载,请注明出处,否则将追究法律责任。