MongoDB:由于分片套接字异常而无法在本地主机上分片 [英] MongoDB: can't shard on localhost because of shard socket exception
问题描述
我正在尝试MongoDB的碎片教程,简单的测试(概念验证项目).
I'm trying the MongoDB's shard tutorial, for some simple testing (proof-of-concept project).
我想在单台机器上尝试分片.这可能和/或有意义吗?
I want to try sharding on a single machine. Is this possible and/or does it make any sense?
当我按照指导步骤操作时,它不起作用.
When I follow the guide steps, it does not work.
首先,我在计算机上启动mongod configsrv数据库实例:
First, I start the mongod configsrv database instances on my machine:
bin/mongod --configsvr --dbpath $BASEDIR/data/configdb --port 27019 &
bin/mongod --configsvr --dbpath $BASEDIR/data/configdb1 --port 27020 &
bin/mongod --configsvr --dbpath $BASEDIR/data/configdb2 --port 27021 &
然后,我启动mongos实例,以便它们绑定"到配置服务器:
Then, I start the mongos instances so that they "bind" to the config servers:
HOST=$(uname -n) # my machine's name
# starts on default poort 27017
bin/mongos --configdb $HOST:27019,$HOST:27020,$HOST:27021
直到这里,一切看起来都很好.
Until here, everything looks good.
现在我想向集群添加碎片:
Now I want to add a Shard to the cluster:
bin/mongo --host $(uname -n)
它进入MongoDB shell.
It enters the MongoDB shell.
连接到:my.machine.name:27017/test
connecting to: my.machine.name:27017/test
但是当我尝试添加新的分片时,出现以下错误:
But when I try to add a new shard, I have the following error:
mongos> sh.addShard( "rs1/my.machine.name:27017" )
{
"ok" : 0,
"errmsg" : "couldn't connect to new shard socket exception [CONNECT_ERROR] for rs1/my.machine.name:27017"
}
我尝试使用ip,机器的别名,本地主机...似乎没有任何作用.
I have tried with ip, machine's alias, localhost ... nothing seems to work.
有人可以帮助我吗?也许我遗漏了一点.
Anyone could help me on this? Maybe I'm missing a point.
预先感谢
推荐答案
我遇到了同样的问题,必须运行
I had the same problem, you have to run
mongod&
mongod &
在每个分片上
然后您可以致电
sh.addShard("rs1/my.machine.name:27017")
sh.addShard( "rs1/my.machine.name:27017" )
这篇关于MongoDB:由于分片套接字异常而无法在本地主机上分片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!