免費試用MongoDB雲數據庫 (MongoDB Atlas)教程

  衆所周知,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,那麼會提示建立一個新的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

  

 第四步: 鏈接試用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

相關文章
相關標籤/搜索