免費試用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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM