文档菜单
文档首页
/ /
MongoDB CLI
/

开始使用 MongoDB 云管理器

本页内容

  • 先决条件
  • 创建集群
  • 检索集群
  • 监控自动化配置状态
  • 摘要

MongoDB CLI 提供了用于管理您的MongoDB 云管理器项目和集群的命令行界面。

本教程演示了如何

  • 在您的云管理器项目中

  • 检索新集群的详细信息

本教程中提到的命令的参考页面可在MongoDB CLI 命令中找到.

在开始之前,请完成以下任务

  • 确保您的环境与兼容

  • 创建一个云管理器组织

  • 生成具有以下属性的程序性API密钥项目所有者或更高权限 - 对于您的IP地址或CIDR范围的访问列表条目CIDR范围

  • 安装或更新MongoDB CLI

  • 配置MongoDB CLI

使用mongocli cloud-manager clusters create命令创建集群云管理器.

以下命令创建了一个具有以下设置的示例集群

  • 集群名称:getStarted

  • MongoDB服务器版本:5.0.0

  • 功能兼容版本:5.0

  • 副本集成员:3

  • 成员主机名:host1host2host3

    注意

    本教程使用主机名host1host2host3。请将这些主机名替换为有效的MongoDB服务器主机名。

  • 每个mongod实例的数据目录:/data/cluster/rs1/data/cluster/rs2/data/cluster/rs3

  • 每个 mongod 实例的日志文件路径:/data/cluster/rs1/mongodb.log/data/cluster/rs2/mongodb.log/data/cluster/rs3/mongodb.log

  • 每个 mongod 进程的端口:290102902029030

  • 每个成员的投票优先级:1

  • 每个成员的投票数:1

1

有关配置文件属性的更多信息,请参阅 集群配置文件。

{
"name": "getStarted",
"version": "5.0.0",
"featureCompatibilityVersion": "5.0",
"processes": [
{
"hostname": "host1",
"dbPath": "/data/cluster/rs1",
"logPath": "/data/cluster/rs1/mongodb.log",
"priority": 1,
"votes": 1,
"port": 29010
},
{
"hostname": "host2",
"dbPath": "/data/cluster/rs2",
"logPath": "/data/cluster/rs2/mongodb.log",
"priority": 1,
"votes": 1,
"port": 29020
},
{
"hostname": "host3",
"dbPath": "/data/cluster/rs3",
"logPath": "/data/cluster/rs3/mongodb.log",
"priority": 1,
"votes": 1,
"port": 29030
}
]
}
2
mongocli cloud-manager cluster create --file getStartedCluster.json

您可以通过使用 mongocli cloud-manager clusters describe 命令检索集群详细信息来检查您的集群是否成功创建。

mongocli cloud-manager cluster describe getStarted

您的命令输出应类似于以下内容

{
"mongoURI": "mongodb://host1:29010,host2:29020,host3:29030",
"name": "getStarted",
"processes": [
{
"buildIndexes": true,
"db_path": "/data/cluster/rs1",
"featureCompatibilityVersion": "5.0",
"hostname": "host1",
"log_path": "/data/cluster/rs1/mongodb.log",
"name": "getStartedCluster",
"port": 29010,
"priority": 1,
"process_type": "mongod",
"slave_delay": 0,
"version": "5.0.0",
"votes": 1,
"arbiter_only": false,
"disabled": false,
"hidden": false
},
{
"buildIndexes": true,
"db_path": "/data/cluster/rs2",
"featureCompatibilityVersion": "5.0",
"hostname": "host2",
"log_path": "/data/cluster/rs2/mongodb.log",
"name": "getStartedCluster",
"port": 29020,
"priority": 1,
"process_type": "mongod",
"slave_delay": 0,
"version": "5.0.0",
"votes": 1,
"arbiter_only": false,
"disabled": false,
"hidden": false
},
{
"buildIndexes": true,
"db_path": "/data/cluster/rs3",
"featureCompatibilityVersion": "5.0",
"hostname": "host3",
"log_path": "/data/cluster/rs3/mongodb.log",
"name": "getStartedCluster",
"port": 29030,
"priority": 1,
"process_type": "mongod",
"slave_delay": 0,
"version": "5.0.0",
"votes": 1,
"arbiter_only": false,
"disabled": false,
"hidden": false
}
]
}

运行 mongocli cloud-manager automation watch 命令以确定集群是否已准备好使用。以下命令使用默认配置文件访问云管理器项目中

mongocli cm automation watch

恭喜!您已成功创建了一个集群来托管您的数据。您可以使用 连接字符串 连接到您的集群,使用 mongosh 或您的应用程序,或通过登录到 UI 来查看您的集群。

返回

快速开始