简体   繁体   English

Mongodb Sharding - 没有这样的命令:'addShard'

[英]Mongodb Sharding - no such command: 'addShard'

I'm trying to configure sharding in one machine and I keep getting an error message when trying to add shards. 我正在尝试在一台计算机上配置分片,并在尝试添加分片时不断收到错误消息。 I'm using the following website as a reference: http://www.javahotchocolate.com/notes/mongodb-sharding.html 我使用以下网站作为参考: http//www.javahotchocolate.com/notes/mongodb-sharding.html

I'm using a single machine and using different ports to simulate the different IPs. 我正在使用一台机器并使用不同的端口来模拟不同的IP。

I have a configuration as follows: 我的配置如下:

Replica set members: 副本集成员:

mongod --dbpath \rs1_p\db --port 27017 --replSet rs1
mongod --dbpath \rs1_s1\db --port 27018 --replSet rs1
mongod --dbpath \rs1_s2\db --port 27019 --replSet rs1
mongod --dbpath \rs1_p\db --port 47017 --replSet rs2
mongod --dbpath \rs1_s1\db --port 47018 --replSet rs2
mongod --dbpath \rs1_s2\db --port 47019 --replSet rs2

Configuring replica sets in MongoDB shell: 在MongoDB shell中配置副本集:

config =
{
    _id:"rs1",
    members:
    [
        { _id:0, host:"computerName:27017" },
        { _id:1, host:"computerName:27018" },
        { _id:2, host:"computerName:27019" }
    ]
}
rs.initiate( config )

config =
{
    _id:"rs2",
    members:
    [
        { _id:0, host:"computerName:47017" },
        { _id:1, host:"computerName:47018" },
        { _id:2, host:"computerName:47019" }
    ]
}
rs.initiate( config )

Launching configuration servers: 启动配置服务器:

mongod --dbpath \c1\db --configsvr --port 37017
mongod --dbpath \c2\db --configsvr --port 37018
mongod --dbpath \c3\db --configsvr --port 37019

Launching sharding routers: 启动分片路由器:

mongos --port 27077 --configdb computerName:37017, computerName:37018, computerName:37019
mongos --port 27078 --configdb computerName:37017, computerName:37018, computerName:37019

All okay until here, but In getting an error message in the next step 一切都好,直到这里,但在下一步收到错误信息

sh.addShard('rs1/computerName:27017')

I'm getting the follow error: 我收到了以下错误:

{
    "ok" : 0.0,   
    "errmsg" : "no such command: 'addShard', bad cmd: '{ addShard: \"rs1/computerName:27017\" }'",
"code" : 59
}

I can not seem to get around from this error message. 我似乎无法解决此错误消息。

Any ideas on what am I missing. 关于我缺少什么的任何想法。

Thanks 谢谢

as per documentation 根据文件

Run addShard when connected to a mongos instance. 连接到mongos实例时运行addShard。 The command takes the following form when adding a single database instance as a shard 将单个数据库实例添加为分片时,该命令采用以下形式

when you run this connected to mongo shell you will get that error, so you need to connect to let say mongo --port 27078 and issue that command. 当你运行这个连接到mongo shell时你会得到那个错误,所以你需要连接让我们说mongo --port 27078并发出该命令。

mongo --host <hostname of machine running mongos> --port <port mongos listens on>

manaual manaual

more here and here 更多这里这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM