Docs 菜单
Docs 主页
/ /

创建本地 Atlas 部署

本教程向您展示如何使用 atlas deployments 命令创建本地Atlas部署。在本教程中,我们将在本地计算机上部署单节点副本集。然后,您可以管理部署,并使用MongoDB Search 和MongoDB Vector Search。

操作系统
操作系统版本
架构
最低 CPU 核心数
最低可用RAM (GB)

macOS

13.2 及更高版本

x86-64、ARM

2

2

Red Hat Enterprise Linux/CentOS

8, 9

x86-64、ARM

2

2

Ubuntu

22.04 、 24.04

x86-64、ARM

2

2

Debian

11, 12

x86-64、ARM

2

2

Amazon Linux

2023

x86-64、ARM

2

2

Windows

10, 11

x86

2

2

在开始之前,请完成以下步骤以满足先决条件:

重要

有关依赖项列表中每个产品的兼容性信息,请参阅该产品的安装文档。

1
  1. 安装 Atlas CLI。

    如果使用 Homebrew,则可以在终端中运行以下命令:

    brew install mongodb-atlas-cli

    有关其他操作系统上的安装说明,请参阅安装或更新Atlas CLI。

  2. 安装 Docker。

    Docker需要网络连接来拉取和缓存MongoDB映像。

  3. (可选)安装mongosh版本 2.0或更高版本。

    brew install mongosh

    有关其他操作系统上的安装说明,请参阅安装mongosh。

  4. (可选)安装Compass版本1.39.4或更高版本。

    brew install mongodb-compass

    有关其他操作系统上的安装说明,请参阅下载和安装Compass。

  5. (可选)安装Visual Studio CodeMongoDB for VS Code扩展。

    要学习;了解更多信息,请参阅安装MongoDB for VS Code扩展。

2

如果您还没有Atlas帐户,请在终端中运行atlas setup 或创建一个新帐户。

使用 atlas deployments 命令创建本地 Atlas 部署。

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

  • 交互模式(默认):该命令会提示您进行部署设置并提供默认值。

  • 交互模式(自定义):该命令会提示您进行部署设置,并允许您提供自定义值。

  • 非交互模式:使用指定选项运行该命令。该命令不会提示您提供其他值。要学习;了解atlas deployments 支持的所有操作,请参阅 atlas-deployments

请单击以下标签页之一,查看首选模式的命令。

1
atlas deployments setup

要使用自己的数据和索引初始化本地Atlas部署,请执行以下操作:

  1. 复制以下命令:

    atlas deployments setup --initdb {folder}
  2. {folder} 占位符替换为包含要在本地容器内按字母数字顺序运行的.js.sh 文件的目录。

  3. 运行命令。

2

示例:

指定local - Local Database并按 Enter ..

? What would you like to deploy? [Use arrows to move, type to filter, ? for more help]
> local - Local Database
atlas - Atlas Database
[Default Settings]
Deployment Name local50
MongoDB Version 7.0
Port 27017
3

示例:

指定 default - With default settings 并按 Enter..

? How do you want to setup your local MongoDB database? [Use arrows to move, type to filter]
> default - With default settings
custom - With custom settings
cancel - Cancel set up
Creating your deployment local50 [this might take several minutes]
1/4: Downloading and completing configuration...
2/4: Starting your local environment...
3/4: Downloading MongoDB binaries to your local environment...
4/4: Creating your deployment local50...
Deployment created!
Connection string: mongodb://localhost:27017/?directConnection=true
1
atlas deployments setup

要使用自己的数据和索引初始化本地Atlas部署,请执行以下操作:

  1. 复制以下命令:

    atlas deployments setup --initdb {folder}
  2. {folder} 占位符替换为包含要在本地容器内按字母数字顺序运行的.js.sh 文件的目录。

  3. 运行命令。

2

指定 local - Local Database 并按 Enter..

示例:

? What would you like to deploy? [Use arrows to move, type to filter, ? for more help]
> local - Local Database
atlas - Atlas Database
[Default Settings]
Deployment Name local50
MongoDB Version 7.0
Port 27017
3

示例:

指定 custom - With custom settings 并按 Enter..

? How do you want to setup your local MongoDB database? [Use arrows to move, type to filter]
default - With default settings
> custom - With custom settings
cancel - Cancel set up
4

示例:

指定 myLocalRs 并按 Enter..

? Deployment Name [This can't be changed later] (local3612) myLocalRs
5

示例:

指定 7.0 并按 Enter..

? MongoDB Version [Use arrows to move, type to filter]
> 7.0
6.0
6

示例:

指定 37018 并按 Enter..

? Specify a port (49469) 37018
Creating your deployment myLocalRs
1/2: Starting your local environment...
2/2: Creating your deployment myLocalRs...
Deployment created!
Connection string: mongodb://localhost:37018/?directConnection=true
1

示例:

atlas deployments setup myLocalRs1 --type local --force
[Default Settings]
Deployment Name myLocalRs1
MongoDB Version 7.0
Port 49684
Creating your deployment myLocalRs1
1/2: Starting your local environment...
2/2: Creating your deployment myLocalRs1...
Deployment created!
Connection string: mongodb://localhost:49684/?directConnection=true
connection skipped

要使用自己的数据和索引初始化本地Atlas部署,请执行以下操作:

  1. 复制以下命令:

    atlas deployments setup myLocalRs1 --type local --force --initdb {folder}
  2. {folder} 占位符替换为包含要在本地容器内按字母数字顺序运行的.js.sh 文件的目录。

  3. 运行命令。

使用 atlas deployments 命令管理本地 Atlas 部署。您可以对本地和云端 Atlas 部署使用以下命令。您可以分别使用 --type local--type atlas 来对本地或云端 Atlas 部署运行该命令。

1

示例:

atlas deployments list
NAME TYPE MDB VER STATE
local50 LOCAL 7.0.1 IDLE
local62 LOCAL 7.0.1 IDLE
myLocalRs LOCAL 7.0.1 IDLE
myLocalRs1 LOCAL 7.0.1 IDLE
2
  1. 执行以下命令以下载示例数据。

    curl https://atlas-education.s3.amazonaws.com/sampledata.archive -o sampledata.archive
  2. 将以下命令复制并粘贴到终端,然后将 {port-number} 替换为部署端口:

    mongorestore --archive=sampledata.archive --port={port-number}
3
  1. 运行以下命令以连接到部署:

    atlas deployments connect
  2. 指定要连接的部署并按 Enter..

  3. 指定您希望连接到部署的方式,然后按 Enter..

    您可以检索连接字符串或连接到以下客户端:连接字符串:

4
  1. 运行以下命令以暂停部署:

    atlas deployments pause
  2. 指定要暂停的部署并按 Enter..

5
  1. 运行以下命令以启动部署:

    atlas deployments start
  2. 指定要启动的部署并按 Enter..

6
  1. 运行以下命令以返回部署的日志:

    atlas deployments logs
  2. 指定要返回日志的部署并按 Enter..

  1. 运行以下命令以删除部署:

    atlas deployments delete
  2. 指定要删除的部署并按 Enter..

  3. 指定y并按Enter 。以确认。

您可以使用DockerMongoDB Database Tools将本地Atlas部署迁移到云Atlas部署。

1
atlas deployments setup --type atlas
2
atlas deployments setup --type local

要使用自己的数据和索引初始化本地Atlas部署,请执行以下操作:

  1. 复制以下命令:

    atlas deployments setup --type local --initdb {folder}
  2. {folder} 占位符替换为包含要在本地容器内按字母数字顺序运行的.js.sh 文件的目录。

  3. 运行命令。

3
  1. 复制以下命令:

    docker exec -u root -it {local_deployment_name} sh -c "mkdir -p /data/dump && chown -R mongod:mongod /data/dump && mongodump --archive=/data/dump/dump.archive"
  2. {local-deployment-name} 占位符替换为本地Atlas部署的名称。

  3. 运行命令。

4
  1. 复制以下命令:

    docker cp <local deployment name>:/data/dump/dump.archive .
  2. {local-deployment-name} 占位符替换为本地Atlas部署的名称。

  3. 运行命令。

5
atlas deployments connect --type atlas --connectWith connectionString
6
  1. 复制以下命令:

    mongorestore --uri={connection-string} --archive=./dump.archive
  2. {connection-string} 占位符替换为连接字符串。

  3. 运行命令。

7
atlas deployments delete --type local

您可以使用DockerMongoDB Database Tools将本地Atlas部署更新到较新版本的映像。

1
atlas deployments setup --type local

要使用自己的数据和索引初始化本地Atlas部署,请执行以下操作:

  1. 复制以下命令:

    atlas deployments setup --type local --initdb {folder}
  2. {folder} 占位符替换为包含要在本地容器内按字母数字顺序运行的.js.sh 文件的目录。

  3. 运行命令。

2
  1. 复制以下命令:

    docker exec -u root -it {old-local-deployment-name} sh -c "mkdir -p /data/dump && chown -R mongod:mongod /data/dump && mongodump --archive=/data/dump/dump.archive"
  2. {old-local-deployment-name} 占位符替换为旧的本地Atlas部署的名称。

  3. 运行命令。

3
  1. 复制以下命令:

    docker cp {old-local-deployment-name}:/data/dump/dump.archive .
  2. {old-local-deployment-name} 占位符替换为旧的本地Atlas部署的名称。

  3. 运行命令。

4
atlas deployments connect --type local --connectWith connectionString
5
  1. 复制以下命令:

    mongorestore --uri={connection-string} --archive=./dump.archive
  2. {connection-string} 占位符替换为连接环。

  3. 运行命令。

6
atlas deployments delete --type local

使用 atlas deployments search indexes create 命令创建MongoDB Search搜索索引。然后,您可以运行MongoDB Search 查询。要学习;了解更多信息,请参阅MongoDB Search。

您可以在本地和云Atlas部署中运行此命令。有关详细步骤,请参阅创建MongoDB搜索索引并运行查询。

使用 atlas deployments search indexes create 命令可使用MongoDB 向量搜索。要学习;了解更多信息,请参阅如何为向量搜索的向量嵌入创建索引。

您可以在本地和云Atlas部署中运行此命令。有关详细步骤,请参阅在Atlas部署中使用MongoDB Vector Search。

重要

要将Atlas CLI与MongoDB Vector Search 结合使用,您必须使用MongoDB 7.0.5 或更高版本创建Atlas部署。如果使用早期MongoDB版本创建了本地Atlas部署,则不会自动获取最新的MongoDB版本。您必须删除早期的映像和部署。然后,您必须创建新的Atlas部署。

要学习;了解atlas deployments 支持的所有操作,请参阅 atlas-deployments

要学习;了解有关解决本地Atlas部署问题的更多信息,请参阅解决本地Atlas部署问题。

后退

本地部署和云部署

在此页面上