Docs 菜单
Docs 主页
/ /
Atlas CLI
/

创建并配置 Atlas 集群

在此页面上

  • 先决条件
  • 配置 Atlas 集群
  • 采取后续步骤

本教程演示如何使用 atlas 安装命令:

  1. 在 Atlas 项目中创建一个集群。

  2. 样本数据加载到 Atlas 集群。

  3. 将您的 IP 地址添加到项目的 IP 访问列表中。

  4. 为 Atlas 集群创建 MongoDB 用户。

  5. 使用 MongoDB Shell mongosh连接到新集群。

要在创建新 Atlas 帐户的同时执行所有这些步骤,请参阅Atlas 入门。

要使用配置文件创建Atlas 集群,请使用--file选项而不是atlas setup运行Atlas 集群 create命令。要了解有关 Atlas 集群配置文件的更多信息,请参阅集群配置文件。

您还可以使用atlas setup创建 Atlas 帐户并通过 Atlas 进行身份验证。 要了解更多信息,请参阅Atlas 入门。

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

使用atlas setup命令在 Atlas 中创建M0集群。 M0集群存在一些操作限制。

可以通过以下方式运行该命令:

  • 默认设置模式:该命令使用默认设置创建示例共享层级集群。

  • 交互模式:该命令会提示您输入集群设置并提供默认值。

  • 非交互模式:使用选项运行命令。

单击该标签页可查看适合您首选模式的命令。

该命令将创建一个示例共享层集群,其默认设置如下:

  • 集群名称: Cluster<number>

  • 服务提供商: AWS

  • 提供商地区: US_EAST_1

  • 集群层: M0

  • 磁盘大小: 0.5 GB

  • 数据库用户名: Cluster<number>

  • 数据库用户密码: abcdef12345

  • 允许来自以下 IP 地址的连接: <YourIPAddress>

  • 加载样本数据: Yes

  • 打开shell : No

注意

密码是自动生成的随机值。 abcdef12345是一个示例值。

atlas setup --force
We are deploying Cluster9876543...
Please store your database authentication access details in a secure location
Database User Username: Cluster9876543
Database User Password: abcdef12345
Creating your cluster... [Its safe to 'Ctrl + C']
Cluster created.
Your connection string: mongodb+srv://cluster9876543.example.mongodb.net
Loading sample data into your cluster... [Its safe to 'Ctrl + C']
Now you can connect to your Atlas cluster with: mongosh -u Cluster9876543 -p abcdef12345 mongodb+srv://cluster9876543.example.mongodb.net

该命令会提示您进行集群设置并提供默认选项。出现提示时,按 Y ,然后按Enter接受默认设置。

atlas setup
Press [Enter] to use the default values.
Enter [?] on any option to get help.
[Default Settings]
Cluster Name: Cluster9876543
Cloud Provider and Region: AWS - US_EAST_1
Database User Username: Cluster9876543
Load sample data: Yes
Allow connections from (IP Address): <your-IP>
? Do you want to set up your first free database in Atlas with default settings (it's free forever)? Yes
We are deploying Quickstart-9876543...
Please store your database authentication access details in a secure location:
Database User Username: Cluster9876543
Database User Password: abcdef12345
Creating your cluster... [Its safe to 'Ctrl + C']
Cluster created.
Your connection string: mongodb+srv://cluster9876543.example.mongodb.net
Loading sample data into your cluster... [Its safe to 'Ctrl + C']
Now you can connect to your Atlas cluster with: mongosh -u Cluster9876543 -p abcdef12345 mongodb+srv://cluster9876543.example.mongodb.net

该命令将创建具有以下设置的示例共享层级集群:

  • 集群名称: getStarted

  • 服务提供商: AWS

  • 提供商地区: US_EAST-1

  • 集群层: M0

  • 磁盘大小: 2 GB

  • MongoDB 版本: 5.0

  • 副本集节点: 3

atlas setup --clusterName getStarted --provider AWS --region US_EAST_1 --username testUser --password changeMe --accessListIp 192.0.2.15 --skipSampleData --force
We are deploying getStarted...
Please store your database authentication access details in a secure location:
Database User Username: testUser
Database User Password: changeMe
Creating your cluster... [Its safe to 'Ctrl + C']
Now you can connect to your |service| cluster with: mongosh -u testUser -p changeMe mongodb+srv://getStarted.example.mongodb.net

恭喜!您已成功创建了一个可托管数据的集群。

使用连接string通过mongosh或应用程序连接到集群。

要查看集群的状态,请执行以下操作:

后退

开始使用 Atlas