众所周知,MongoDB包括社区版和企业版,但不止如此,MongoDB公司还有MongoDB Atlas:Database as a Service.html
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.python
MongoDB Atlas提供的是云端的数据库服务,你们都知道,使用数据库很简单,但数据库的运维很麻烦:部署、容灾、备份、监控。云数据库使得开发者只需关注业务自己的开发,国内彷佛也有阿里云数据库,但事实上有多少用户就不得而知了。不过。话说回来,数据这么敏感的东西也不能随便放,并且放在别处也怕丢失,好比前些天腾讯云“数据丢失”事件。mongodb
但出于学习、尝试的目的,免费的云数据库仍是颇有吸引力的,对于MongoDB等分布式数据库,要搭建一个集群(sharded cluster)是相对耗时耗力的,也许尝试一个新的feature只需5分钟,但环境搭建就得两小时。我以前也写过文章如何搭建sharded cluster,不过是基于MongoDB3.0,存储引擎是MmapV1,感兴趣的朋友能够参考。在MongoDB3.6即以上,一些feature依赖sharding环境,且3.6的shard必须是replica set,不能再是standalone mongod instance,因此更加麻烦。本文记录了如何使用MongoDB Atlas云数据库。shell
本文地址:http://www.javashuo.com/article/p-qfrhhsvp-gp.html数据库
在MongoDB atlas首页,若是有帐号,那就点击登录。不然点击Get Started here 来注册,注册页面都是必填项:app
登录以后,若是还没有建立任何Cluster,那么会提示建立一个新的Cluster,以下所示:运维
注意 只有M0是免费的,这个里面不少选项都是针对M0以上的,不过M0对于学习也足够了。下面是M0能够设置的选项:分布式
Cloud Provider & Region:集群部署的位置ide
选一个亚洲节点好了。学习
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
集群是有了,那怎么链接使用呢,最左边有不少按钮,能够每一个点点看看。doc 是 atlas文档的连接, support里面有文档介绍如何连接cluster。
能够用mongoshell,也能够用mongo driver链接。这里用Mongo shell试试
在clusters这个view点击 CONNECT按钮,出现以下
点击第一个,而后会提示,没有mongodb3.6的话就得装一个
我本地有mongod3.6 那么点击第二项,这样会给出一个连接的url
使用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了。