MongoDB整理筆記の新增Shard Server

來源:互聯網
上載者:User

標籤:

    1、啟動一個新Shard Server 進程

[[email protected] ~]# mkdir /data/shard/s2[[email protected] ~]# /Apps/mongo/bin/mongod --shardsvr --port 20002 --dbpath /data/shard/s2--fork --logpath /data/shard/log/s2.log --directoryperdball output going to: /data/shard/log/s2.logforked process: 6772

    2、配置新Shard Server

[[email protected] ~]# /Apps/mongo/bin/mongo admin --port 40000MongoDB shell version: 1.8.1connecting to: 127.0.0.1:40000/admin> db.runCommand({ addshard:"localhost:20002" }){ "shardAdded" : "shard0002", "ok" : 1 }> printShardingStatus()--- Sharding Status ---sharding version: { "_id" : 1, "version" : 3 }shards:{ "_id" : "shard0000", "host" : "localhost:20000" }{ "_id" : "shard0001", "host" : "localhost:20001" }{ "_id" : "shard0002", "host" : "localhost:20002" } --新增Shard Serverdatabases:{ "_id" : "admin", "partitioned" : false, "primary" : "config" }{ "_id" : "test", "partitioned" : true, "primary" : "shard0000" }test.users chunks:shard0002 2shard0000 21shard0001 21too many chunksn to print, use verbose if you want to force printtest.users_2 chunks:shard0001 46shard0002 1shard0000 45too many chunksn to print, use verbose if you want to force print
View Code

   3、 查看分區表狀態,以驗證新Shard Server

> use testswitched to db test> db.users_2.stats(){"sharded" : true,"ns" : "test.users_2",……"shard0002" : { --新的Shard Server 已有資料"ns" : "test.users_2","count" : 21848,"size" : 2097408,"avgObjSize" : 96,"storageSize" : 2793472,"numExtents" : 5,"nindexes" : 1,"lastExtentSize" : 2097152,"paddingFactor" : 1,"flags" : 1,"totalIndexSize" : 1277952,"indexSizes" : {"_id_" : 1277952},"ok" : 1}},"ok" : 1}>
View Code

    我們可以發現,當我們新增Shard Server 後資料自動分布到了新Shard 上,這是由MongoDB內部自已實現的。

MongoDB整理筆記の新增Shard Server

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.