对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。

配置 Ops Manager 资源以使用远程模式

在默认配置中, MongoDB Agent MongoDB , MongoDB

您可以将MongoDB Ops Manager配置为在远程模式下运行,以便备份守护程序和托管MongoDB资源仅从MongoDB Ops Manager下载安装存档,MongoDB Ops Manager 将下载请求代理到本地 Web服务器或 S3 兼容存储上的HTTP端点部署到Kubernetes集群。

部署MongoDB Ops Manager资源。

以下过程将 Nginx HTTP服务器部署到Kubernetes集群,以托管MongoDB安装存档。

1

如果您尚未执行,请运行以下命令,执行所创建命名空间的所有 kubectl 命令。

注意

MongoDB Ops Manager如果要在多 Kubernetes 集群 部署中部署MongoDB 资源:

  • 将 context 设置为中心集群的名称,例如:kubectl config set context "$MDB_CENTRAL_CLUSTER_FULL_NAME"。

  • 将--namespace设置为您用于多 Kubernetes 集群 MongoDB 部署的相同范围,例如: kubectl config --namespace "mongodb" 。

kubectl config set-context $(kubectl config current-context) --namespace=<metadata.namespace>
2

本教程中的 ConfigMap 将 Nginx 配置为:

  • 运行名为localhost的 HTTP 服务器,侦听 Kubernetes 集群中节点上的端口80 ,然后

  • 将对特定资源的 HTTP 请求路由到提供 MongoDB Server 和 MongoDB Database Tools 安装存档的位置。

  1. 将以下示例 Nginx ConfigMap 粘贴到文本编辑器中:

    ---apiVersion: v1kind: ConfigMapmetadata: name: nginx-confdata: nginx.conf: | events {} http { server { server_name localhost; listen 80; location /linux/ { alias /mongodb-ops-manager/mongodb-releases/linux/; } location /tools/ { alias /tools/; } } }...
  2. 以 .yaml 文件扩展名保存此文件。

  3. 通过对您创建的 ConfigMap 文件调用以下kubectl命令来创建 Nginx ConfigMap:

    kubectl apply -f <nginix-configmap>.yaml
3

本教程中的 Nginx 资源配置:

  • 部署一个 Nginx 副本,

  • 创建卷挂载以存储 MongoDB Server 和 MongoDB database Tools 安装存档,以及

  • 定义init 容器,该容器使用 curl 命令将 Nginx 提供的安装存档下载到您在Kubernetes集群中部署的MongoDB数据库资源。

  1. 将以下示例 Nginx 资源配置粘贴到文本编辑器中:

    ---apiVersion: apps/v1kind: Deploymentmetadata: name: nginx-deploymentspec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - image: nginx:1.14.2 imagePullPolicy: IfNotPresent name: nginx ports: - containerPort: 80 volumeMounts: - mountPath: /mongodb-ops-manager/mongodb-releases/linux name: mongodb-versions - mountPath: /tools/db/ name: mongodb-tools - name: nginx-conf mountPath: /etc/nginx/nginx.conf subPath: nginx.conf initContainers: - name: setting-up-rhel-mongodb image: curlimages/curl:latest command: - curl - -L - https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-8.0.0.tgz - -o - /mongodb-ops-manager/mongodb-releases/linux/mongodb-linux-x86_64-rhel80-8.0.0.tgz volumeMounts: - name: mongodb-versions mountPath: /mongodb-ops-manager/mongodb-releases/linux - name: setting-up-rhel-mongodb-tools image: curlimages/curl:latest command: - curl - -L - https://fastdl.mongodb.org/tools/db/mongodb-database-tools-rhel80-x86_64-100.6.0.tgz - -o - /tools/db/mongodb-database-tools-rhel80-x86_64-100.6.0.tgz volumeMounts: - name: mongodb-tools mountPath: /tools/db/ restartPolicy: Always terminationGracePeriodSeconds: 30 volumes: - name: mongodb-versions emptyDir: {} - name: mongodb-tools emptyDir: {} - configMap: name: nginx-conf name: nginx-conf...
  2. 修改示例中突出显示的行以指定要安装的 MongoDB Server 版本。

    例如,要将 MongoDB 版本8.0.0替换为不同的数据库版本,请更新以下区块:

    - name: setting-up-rhel-mongodb image: curlimages/curl:latest command: - curl - -L - https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-8.0.0.tgz - -o - /mongodb-ops-manager/mongodb-releases/linux/mongodb-linux-x86_64-rhel80-8.0.0.tgz

    更新此区块以修改 MongoDB database Tools 版本:

    - name: setting-up-rhel-mongodb-tools image: curlimages/curl:latest command: - curl - -L - https://fastdl.mongodb.org/tools/db/mongodb-database-tools-rhel80-x86_64-100.6.0.tgz - -o - /tools/db/mongodb-database-tools-rhel80-x86_64-100.6.0.tgz
  3. 要加载多个版本,请附加curl命令

    到您希望 Nginx 提供服务的每个版本的相应 initContainer。

    例如,要配置 Nginx 来提供 MongoDB 8.0.0 :

    - name: setting-up-rhel-mongodb image: curlimages/curl:latest command: - curl - -L - https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-8.0.0.tgz - -o - /mongodb-ops-manager/mongodb-releases/linux/mongodb-linux-x86_64-rhel80-8.0.0.tgz
  4. 以 .yaml 文件扩展名保存此文件。

  5. 通过对您创建的 Nginx 资源文件调用以下kubectl命令来部署 Nginx:

    kubectl apply -f <nginix>.yaml
4

本教程中的服务通过端口80将 Nginx 暴露给来自 Kubernetes 集群中其他节点的流量。 这允许您使用 Kubernetes 操作符部署的 MongoDB database 资源 pods 从 Nginx 下载安装存档。

运行以下命令,为 Nginx 部署创建服务:

  1. 将以下示例服务粘贴到文本编辑器中:

    ---apiVersion: v1kind: Servicemetadata: name: nginx-svc labels: app: nginxspec: ports: - port: 80 protocol: TCP selector: app: nginx...
  2. 以 .yaml 文件扩展名保存此文件。

  3. 通过对创建的服务文件调用以下kubectl命令来创建服务:

    kubectl apply -f <nginix-service>.yaml
5

突出显示的部分使用以下 Ops Manager 配置设置:

  • automation.versions.source: remote 以spec.configuration远程模式。

  • automation.versions.download.baseUrl 在spec.configuration中提供为 MongoDB 安装存档提供服务的 HTTP 资源的基本 URL。

    更新此行,将<namespace>替换为您使用 Kubernetes 操作符将资源部署到的命名空间。

  • automation.versions.download.baseUrl.allowOnlyAvailableBuilds: "false" spec.configuration中,以帮助确保企业版构建没有问题。

---apiVersion: mongodb.com/v1kind: MongoDBOpsManagermetadata: name: ops-manager-localmodespec: replicas: 1 version: "8.0.0" adminCredentials: ops-manager-admin-secret configuration: # this enables remote mode in Ops Manager automation.versions.source: remote automation.versions.download.baseUrl: "http://nginx-svc.<namespace>.svc.cluster.local:8080" automation.versions.download.baseUrl.allowOnlyAvailableBuilds: "false" backup: enabled: false applicationDatabase: members: 3...
6

打开首选文本编辑器,将对象规范粘贴到资源文件中的相应位置。

7
8

对 Ops Manager 资源定义的文件名调用以下kubectl命令:

kubectl apply -f <opsmgr-resource>.yaml
9

要检查 Ops Manager 资源的状态,请调用以下命令:

kubectl get om -o yaml -w

有关资源部署状态的信息,请参阅排除 Kubernetes 操作符故障。

Ops Manager 资源完成Pending阶段后,该命令将返回类似于以下内容的输出:

status: applicationDatabase: lastTransition: "2020-05-15T16:20:22Z" members: 3 phase: Running type: ReplicaSet version: "8.0.0-ubi8" backup: phase: "" opsManager: lastTransition: "2020-05-15T16:20:26Z" phase: Running replicas: 1 url: http://ops-manager-localmode-svc.mongodb.svc.cluster.local:8080 version: "8.0.0"

复制status.opsManager.url字段的值,该字段说明资源的连接URL 。 您可以在创建 ConfigMap 时使用此值 在此过程的稍后部分中。

10
  1. 在部署 Ops Manager 的同一命名空间中部署MongoDB database 资源。确保您:

    1. 将资源的spec.opsManager.configMapRef.name与 ConfigMap 的metadata.name进行匹配。

    2. 将资源的spec.credentials与您创建的包含 Ops Manager 编程 API 密钥对的密钥名称进行匹配。

在使用MongoDB Agent Operator 创建的MongoDB数据库资源容器中运行的 MongoDB Kubernetes通过 Nginx 从MongoDB Ops Manager下载安装存档,而不是从互联网下载。