Mongodb 无法在本地主机上创建分片mongo db
我正在尝试使用MongoDB4.0.1社区在本地主机上创建简单的MongoDB集群(作为POC)。 此群集由一个碎片和单成员副本集组成。我一直在学习这个教程,但是我被卡住了 作为第一步,我使用以下配置启动了mongod As配置服务器:Mongodb 无法在本地主机上创建分片mongo db,mongodb,Mongodb,我正在尝试使用MongoDB4.0.1社区在本地主机上创建简单的MongoDB集群(作为POC)。 此群集由一个碎片和单成员副本集组成。我一直在学习这个教程,但是我被卡住了 作为第一步,我使用以下配置启动了mongod As配置服务器: sharding: clusterRole: configsvr replication: replSetName: configServerTestReplicaSet net: bindIp: localhost sharding: clu
sharding:
clusterRole: configsvr
replication:
replSetName: configServerTestReplicaSet
net:
bindIp: localhost
sharding:
clusterRole: shardsvr
replication:
replSetName: shardServerReplicaSet
net:
bindIp: localhost
sharding:
configDB: configServerTestReplicaSet/localhost:27019
net:
bindIp: localhost
然后,我已连接到此配置服务器并通过
rs.initiate()
之后,我移动到具有以下配置的碎片副本集:
sharding:
clusterRole: configsvr
replication:
replSetName: configServerTestReplicaSet
net:
bindIp: localhost
sharding:
clusterRole: shardsvr
replication:
replSetName: shardServerReplicaSet
net:
bindIp: localhost
sharding:
configDB: configServerTestReplicaSet/localhost:27019
net:
bindIp: localhost
我再次连接到此实例并运行
rs.initiate()
下一步是将mongos连接到分片集群。
因此,我使用以下配置启动了mongos:
sharding:
clusterRole: configsvr
replication:
replSetName: configServerTestReplicaSet
net:
bindIp: localhost
sharding:
clusterRole: shardsvr
replication:
replSetName: shardServerReplicaSet
net:
bindIp: localhost
sharding:
configDB: configServerTestReplicaSet/localhost:27019
net:
bindIp: localhost
当我启动mongos时,我看到以下日志
2018-09-04T08:59:00.378+0200 I NETWORK [mongosMain] waiting for connections on port 27017
所以我通过
mongo.exe --host localhost --port 27017
作为下一步,我尝试将碎片添加到集群中
sh.addShard( "localhost:27017")
这将导致以下错误:
sh.addShard( "localhost:27018")
{
"ok" : 0,
"errmsg" : "no such command: 'addShard'",
"code" : 59,
"codeName" : "CommandNotFound"
}
从帮助中可以清楚地看到addShard是一个有效的命令,我已经尝试了使用双引号/单引号和空格等多种语法组合
我做错了什么?配置过程中是否遗漏了一些内容
感谢您的建议…只有当您连接到
mongos
实例时,sh.addShard()
命令才可用。我怀疑你可能意外地连接到了一个碎片服务器。如果您连接到mongos
,默认情况下,mongo
shell提示符应该是mongos>
。您还可以运行mongo
shell命令db.isMaster().msg
,如果您连接到mongos
,则该命令应返回isdbgrid
(如果您没有连接,则无结果)。如果您确实连接到mongos
,并且sh.addShard()
返回“无此类命令”,请编辑您的问题,将version()
和db.isMaster()
@Stennie的输出包括在内,谢谢您的评论。您让我意识到我已连接到mongo服务,该服务在我机器的同一端口上运行。。。我能够连接到mongos并在关闭该服务后立即添加碎片。。。