免费试用MongoDB云数据库 (MongoDB Atlas)教程

  众所周知,MongoDB包括社区版和企业版,但不止如此,MongoDB公司还有MongoDB Atlas:Database as a Service.

  MongoDB Atlas delivers the world’s leading database for modern applications as a fully automated cloud service with the operational and security best practices built in. Easily deploy, operate, and scale your databases across the leading cloud platforms.

  MongoDB Atlas提供的是云端的数据库服务,大家都知道,使用数据库很简单,但数据库的运维很麻烦:部署、容灾、备份、监控。云数据库使得开发者只需关注业务本身的开发,国内似乎也有阿里云数据库,但事实上有多少用户就不得而知了。不过。话说回来,数据这么敏感的东西也不能随便放,而且放在别处也怕丢失,比如前些天腾讯云“数据丢失”事件。

  但出于学习、尝试的目的,免费的云数据库还是很有吸引力的,对于MongoDB等分布式数据库,要搭建一个集群(sharded cluster)是相对耗时耗力的,也许尝试一个新的feature只需5分钟,但环境搭建就得两小时。我之前也写过文章如何搭建sharded cluster,不过是基于MongoDB3.0,存储引擎是MmapV1,感兴趣的朋友可以参考。在MongoDB3.6即以上,一些feature依赖sharding环境,且3.6的shard必须是replica set,不能再是standalone mongod instance,所以更加麻烦。本文记录了如何使用MongoDB Atlas云数据库。

  本文地址:https://www.cnblogs.com/xybaby/p/9460634.html

第一步:注册或登陆

  在MongoDB atlas首页,如果有账号,那就点击登陆。否则点击Get Started here 来注册,注册页面都是必填项:

  

第二步:创建新的Cluster

  登陆之后,如果尚未创建任何Cluster,那么会提示创建一个新的Cluster,如下所示:

  

  注意 只有M0是免费的,这个里面很多选项都是针对M0以上的,不过M0对于学习也足够了。下面是M0可以设置的选项:

  Cloud Provider & Region:集群部署的位置

    

  选一个亚洲节点好了。

  Cluster Tier:服务套餐

  

    

  当然是M0啦,共享内存 CPU,512M存储也够了,M0包含一个3个节点组成的replica set。

  Additional settings 设置,不过M0没有啥可以设置的

    

  可以看到,默认是WT引擎,这也表明,MongoDB官方在慢慢放弃Mmapv1存储引擎,大多数新的feature都支持WT引擎。

 Cluster Name: 集群的名字

    

  点击Create Cluster 开始创建(可能还需要人机校验)

第三步: 创建用户,设置白名单 

  创建新的Cluster需要几分钟时间,在这个等待时间内,可以按提示创建user和设置白名单:

  

   为了方便访问,白名单IP就设置为0.0.0.0好了

  

  回到overview界面,集群创建好了,有一些基本的监控:Operation、 Connections、Logical Size

  

 第四步: 连接试用Cluster

  集群是有了,那怎么连接使用呢,最左边有很多按钮,可以每个点点看看。docatlas文档的链接, support里面有文档介绍如何链接cluster。

  

   可以用mongoshell,也可以用mongo driver连接。这里用Mongo shell试试

step4.1:获取连接URL

  在clusters这个view点击 CONNECT按钮,出现如下

  

    点击第一个,然后会提示,没有mongodb3.6的话就得装一个

  

     我本地有mongod3.6 那么点击第二项,这样会给出一个链接的url

    

step4.2: 用Mongoshell 连接

  使用mongo shell连接。mongo "mongodb+srv://free-yc5um.mongodb.net/test" --username try

  如下所示:

 1 mongo "mongodb+srv://free-yc5um.mongodb.net/test" --username try
 2 MongoDB shell version v3.6.6
 3 Enter password:
 4 connecting to: mongodb+srv://free-yc5um.mongodb.net/test
 5 2018-08-10T13:51:29.072+0800 I NETWORK  [thread1] Starting new replica set monitor for free-shard-0/free-shard-00-00-yc5um.mongodb.net.:27017,free-shard-00-01-yc5um.mongodb.net.:27017,free-shard-00-02-yc5um.mongodb.net.:27017
 6 2018-08-10T13:51:30.389+0800 I NETWORK  [ReplicaSetMonitor-TaskExecutor-0] Successfully connected to free-shard-00-02-yc5um.mongodb.net.:27017 (1 connections now open to free-shard-00-02-yc5um.mongodb.net.:27017 with a 5 second timeout)
 7 2018-08-10T13:51:30.594+0800 I NETWORK  [thread1] Successfully connected to free-shard-00-00-yc5um.mongodb.net.:27017 (1 connections now open to free-shard-00-00-yc5um.mongodb.net.:27017 with a 5 second timeout)
 8 2018-08-10T13:51:30.811+0800 I NETWORK  [ReplicaSetMonitor-TaskExecutor-0] Successfully connected to free-shard-00-01-yc5um.mongodb.net:27017 (1 connections now open to free-shard-00-01-yc5um.mongodb.net:27017 with a 5 second timeout)
 9 2018-08-10T13:51:30.890+0800 I NETWORK  [ReplicaSetMonitor-TaskExecutor-0] changing hosts to free-shard-0/free-shard-00-00-yc5um.mongodb.net:27017,free-shard-00-01-yc5um.mongodb.net:27017,free-shard-00-02-yc5um.mongodb.net:27017 from free-shard-0/free-shard-00-00-yc5um.mongodb.net.:27017,free-shard-00-01-yc5um.mongodb.net.:27017,free-shard-00-02-yc5um.mongodb.net.:27017
10 2018-08-10T13:51:30.995+0800 I NETWORK  [thread1] Successfully connected to free-shard-00-01-yc5um.mongodb.net.:27017 (1 connections now open to free-shard-00-01-yc5um.mongodb.net.:27017 with a 5 second timeout)
11 2018-08-10T13:51:31.191+0800 I NETWORK  [ReplicaSetMonitor-TaskExecutor-0] Successfully connected to free-shard-00-02-yc5um.mongodb.net:27017 (1 connections now open to free-shard-00-02-yc5um.mongodb.net:27017 with a 5 second timeout)
12 2018-08-10T13:51:31.395+0800 I NETWORK  [thread1] Successfully connected to free-shard-00-00-yc5um.mongodb.net:27017 (1 connections now open to free-shard-00-00-yc5um.mongodb.net:27017 with a 5 second timeout)
13 MongoDB server version: 3.6.6
14 MongoDB Enterprise free-shard-0:PRIMARY> show dbs
15 admin  0.000GB
16 local  7.142GB

   回到MongoDB Atlas管理界面,可以看到,已经有连接了

  

  至此,就可以免费试用MongoDB3.6了。

references

猜你喜欢

转载自www.cnblogs.com/xybaby/p/9460634.html