Database sh.isBalancerRunning():false
我正在尝试Database sh.isBalancerRunning():false,database,mongodb,sharding,replicaset,Database,Mongodb,Sharding,Replicaset,我正在尝试shardamongodb数据库如下: 1-启动碎片副本集的每个成员 mongod --shardsvr --port 27100 --replSet r1 --dbpath <some_path>\shardsvr\shardsvr1 mongod --shardsvr --port 27200 --replSet r2 --dbpath <some_path>\shardsvr\shardsvr2 mongod --configsvr --port 27
shard
amongodb数据库
如下:
1-启动碎片副本集的每个成员
mongod --shardsvr --port 27100 --replSet r1 --dbpath <some_path>\shardsvr\shardsvr1
mongod --shardsvr --port 27200 --replSet r2 --dbpath <some_path>\shardsvr\shardsvr2
mongod --configsvr --port 27020 --replSet cfg1 --dbpath <some_path>\configsvr\configsvr1
mongo --port 27020
3-连接到配置服务器副本集
mongod --shardsvr --port 27100 --replSet r1 --dbpath <some_path>\shardsvr\shardsvr1
mongod --shardsvr --port 27200 --replSet r2 --dbpath <some_path>\shardsvr\shardsvr2
mongod --configsvr --port 27020 --replSet cfg1 --dbpath <some_path>\configsvr\configsvr1
mongo --port 27020
4-启动副本集
conf = {
_id: "cfg1",
members: [
{
_id:0,
host: "localhost:27020"
}
]
}
rs.initiate(conf)
5-启动mongos
并指定--configdb
参数
mongos --configdb cfg1/localhost:27020 --port 28000
6-启动每个碎片的副本集
mongo --port 27100
var config = {_id: "r1", members: [{_id:0, host:"localhost:27100"}]}
rs.initiate(config)
exit
mongo --port 27200
var config = {_id: "r2", members: [{_id:0, host:"localhost:27200"}]}
rs.initiate(config)
exit
7-连接到mongos
以添加shard
mongo --port 28000
sh.addShard("r1/localhost:27100")
sh.addShard("r2/localhost:27200")
8-添加一些数据
use sharddb
for (i = 10000; i < 30000; i++){
db.example.insert({
author: "author" + i,
post_title: "Blog Post by Author " + i,
date: new Date()
});
}
db.example.count()
10-创建索引
,作为sh.shardCollection()的一部分
11-检查平衡器是否正在运行
sh.isBalancerRunning()
然而,在这一步中,我得到了一个false
作为响应,我不知道我做错了什么。我遵循了教程的步骤,每个文档只有20000个,大约100字节,可能只有1个块
核对
use sharddb
db.printShardingStatus()
我重复了上面列出的步骤,得到了以下结果:
{ "_id" : "sharddb", "primary" : "shard02", "partitioned" : true }
sharddb.example
shard key: { "author" : 1 }
unique: false
balancing: true
chunks:
shard02 1
{ "author" : { "$minKey" : 1 } } -->> { "author" : { "$maxKey" : 1 } } on : shard02 Timestamp(1, 0)
<> > MangOS将监视它添加到每个块中的内容,并通知配置服务器在看到足够的数据添加时考虑拆分。然后,当一个碎片比另一个碎片包含多个块时,将自动激活平衡器
如果插入足够多的文档以触发自动拆分,或手动拆分区块,则平衡器将开始执行其操作。由于只有20000个文档(每个文档约100字节),可能只有一个区块
核对
use sharddb
db.printShardingStatus()
我重复了上面列出的步骤,得到了以下结果:
{ "_id" : "sharddb", "primary" : "shard02", "partitioned" : true }
sharddb.example
shard key: { "author" : 1 }
unique: false
balancing: true
chunks:
shard02 1
{ "author" : { "$minKey" : 1 } } -->> { "author" : { "$maxKey" : 1 } } on : shard02 Timestamp(1, 0)
<> > MangOS将监视它添加到每个块中的内容,并通知配置服务器在看到足够的数据添加时考虑拆分。然后,当一个碎片比另一个碎片包含多个块时,将自动激活平衡器
如果插入足够的文档以触发自动拆分,或手动拆分区块,则平衡器将开始执行其操作。使用sh.split
、sh.splitFind
或sh.splitAt
命令。请参见使用sh.split
、sh.splitFind
或sh.splitAt
命令。看见