热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

MongoDB运行时添加分片复制集

基于Mongodb集群配置(shardingwithreplicaset)的集群,尝试在Mongodb集群运行时动态添加分片复制集。(1)启动复制集节点分别执行如下3个批处理文件来启动3个Mongod进程,127.0.0.1:36000和127.0.0.1:36001以及127.0.0.1:36002.批处理文件sta

基于"Mongodb集群配置(sharding with replica set)"的集群,尝试在Mongodb集群运行时动态添加分片复制集。

(1)启动复制集节点

分别执行如下3个批处理文件来启动3个Mongod进程,127.0.0.1:36000和127.0.0.1:36001以及127.0.0.1:36002.

批处理文件startShardD_0.bat:

cd d:/mongodb-win32-i386-1.8.0/bin
call mongod.exe --logpath d:/mongodb-win32-i386-1.8.0/logs/d/r0.log --logappend --dbpath d:/mongodb-win32-i386-1.8.0/data/d/r0 --port 36000 --shardsvr --replSet setD --rest  --oplogSize 64

批处理文件startShardD_1.bat:

cd d:/mongodb-win32-i386-1.8.0/bin
call mongod.exe --logpath d:/mongodb-win32-i386-1.8.0/logs/d/r1.log --logappend --dbpath d:/mongodb-win32-i386-1.8.0/data/d/r1 --port 36001 --shardsvr --replSet setD --rest  --oplogSize 64

批处理文件startShardD_2.bat:

cd d:/mongodb-win32-i386-1.8.0/bin
call mongod.exe --logpath d:/mongodb-win32-i386-1.8.0/logs/d/r2.log --logappend --dbpath d:/mongodb-win32-i386-1.8.0/data/d/r2 --port 36002 --shardsvr --replSet setD --rest  --oplogSize 64

(2)配置复制集
D:/mongodb-win32-i386-1.8.0/cmd>cd d:/mongodb-win32-i386-1.8.0/bin

D:/mongodb-win32-i386-1.8.0/bin>call mongo.exe 127.0.0.1:36000/admin
MongoDB shell version: 1.8.0
connecting to: 127.0.0.1:36000/admin
> cfg = { _id:'setD', members:[
{ _id:0, host:'127.0.0.1:36000' },
{ _id:1, host:'127.0.0.1:36001' },
{ _id:2, host:'127.0.0.1:36002' }...
]};
{
        "_id" : "setD",
        "members" : [
{
"_id" : 0,
"host" : "127.0.0.1:36000"
},
{
"_id" : 1,
"host" : "127.0.0.1:36001"
},
{
"_id" : 2,
"host" : "127.0.0.1:36002"
}
        ]
}
> rs.initiate(cfg)
{
        "info" : "Config now saved locally.  Should come online in about a minute.",
        "ok" : 1
}
>

(3)添加到集群

cd d:/mongodb-win32-i386-1.8.0/bin
call mongo.exe 127.0.0.1:50000/admin

> db.runCommand({addshard:'setD/127.0.0.1:36000,127.0.0.1:36001,127.0.0.1:36002'})
{ "shardAdded" : "setD", "ok" : 1 }

(4)查看集群分片信息

> db.printShardingStatus()
--- Sharding Status ---
  sharding version: { "_id" : 1, "version" : 3 }
  shards:
      {
        "_id" : "ShardSetA",
        "host" : "setA/127.0.0.1:10000,127.0.0.1:10001,127.0.0.1:10002"
}
      {
        "_id" : "ShardSetB",
        "host" : "setB/127.0.0.1:20000,127.0.0.1:20001,127.0.0.1:20002"
}
      {
        "_id" : "ShardSetC",
        "host" : "setC/127.0.0.1:30000,127.0.0.1:30001,127.0.0.1:30002"
}
      {
        "_id" : "setD",
        "host" : "setD/127.0.0.1:36000,127.0.0.1:36001,127.0.0.1:36002"
}
  databases:
        { "_id" : "admin", "partitioned" : false, "primary" : "config" }
        { "_id" : "wlb", "partitioned" : true, "primary" : "ShardSetA" }
wlb.wlb_orders chunks:
ShardSetB       5
ShardSetA       4
ShardSetC       5
{ "order_id" : { $minKey : 1 } } -->> { "order_id" : NumberLong(1) } on : ShardSetB { "t" : 5000, "i" : 1 }
{ "order_id" : NumberLong(1) } -->> { "order_id" : NumberLong(19943) } on : ShardSetA { "t" : 8000, "i" : 1 }
{ "order_id" : NumberLong(19943) } -->> { "order_id" : NumberLong(37015) } on : ShardSetC { "t" : 7000, "i" : 1 }
{ "order_id" : NumberLong(37015) } -->> { "order_id" : NumberLong(54080) } on : ShardSetB { "t" : 4000, "i" : 2 }
{ "order_id" : NumberLong(54080) } -->> { "order_id" : NumberLong(71148) } on : ShardSetB { "t" : 4000, "i" : 4 }
{ "order_id" : NumberLong(71148) } -->> { "order_id" : NumberLong(88201) } on : ShardSetA { "t" : 5000, "i" : 2 }
{ "order_id" : NumberLong(88201) } -->> { "order_id" : NumberLong(105259) } on : ShardSetC { "t" : 6000, "i" : 2 }
{ "order_id" : NumberLong(105259) } -->> { "order_id" : NumberLong(122284) } on : ShardSetC { "t" : 6000, "i" : 4 }
{ "order_id" : NumberLong(122284) } -->> { "order_id" : NumberLong(139303) } on : ShardSetC { "t" : 6000, "i" : 6 }
{ "order_id" : NumberLong(139303) } -->> { "order_id" : NumberLong(173354) } on : ShardSetC { "t" : 6000, "i" : 8 }
{ "order_id" : NumberLong(173354) } -->> { "order_id" : NumberLong(207403) } on : ShardSetA { "t" : 7000, "i" : 2 }
{ "order_id" : NumberLong(207403) } -->> { "order_id" : NumberLong(241449) } on : ShardSetA { "t" : 7000, "i" : 4 }
{ "order_id" : NumberLong(241449) } -->> { "order_id" : NumberLong(275497) } on : ShardSetB { "t" : 8000, "i" : 2 }
{ "order_id" : NumberLong(275497) } -->> { "order_id" : { $maxKey : 1 } } on : ShardSetB { "t" : 8000, "i" : 3 }
        { "_id" : "adimin", "partitioned" : false, "primary" : "ShardSetA" }

至此,复制集setD就作为一个分片加入到集群中去了。


推荐阅读
author-avatar
qqqq
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有