欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

MongoDB集群搭建及Sharding的实现思路

程序员文章站 2022-05-04 21:35:13
...

MongoDB集群搭建MongoDB的复制集群类型:·主从模式(master/slave)·副本集模式(replicaset)副本及模式至少3个节点(一主二从),从节点负责复制主节点的oplog






进入admin库,,激活collection分片并配置shard key唯一

>use admin

mongos> db.runCommand( { shardcollection : "test11.testcoll",key : {_id : 1 } , unique : true } )
{ "collectionsharded" : "test11.testcoll", "ok" :1 }

查看分片状态信息

mongos> db.printShardingStatus();
--- Sharding Status ---
sharding version: {
"_id" : 1,
"version" : 3,
"minCompatibleVersion" : 3,
"currentVersion" : 4,
"clusterId" :ObjectId("532fa07065574826130abfbf")
}
shards:
{ "_id" : "rs0", "host" :"rs0/172.23.214.47:27017,172.23.214.50:27017,172.23.215.61:27017" }
databases:
{ "_id" : "admin", "partitioned" : false, "primary" : "config"}
{ "_id" : "test11", "partitioned" : true, "primary" : "rs0" }
test11.testcoll
shard key: { "_id" : 1 }
chunks:
rs0 1
{ "_id" : { "$minKey" : 1 } } -->> { "_id": { "$maxKey" : 1 } } on : rs0 Timestamp(1, 0)
{ "_id" : "testdb", "partitioned" : true, "primary" : "rs0" }
{ "_id" : "test", "partitioned" : false, "primary" : "rs0" }



本文出自 “心情依旧” 博客,请务必保留此出处