mongodb - mongodb 这个数据库没有启用分片,即使我确实连接到了 mongos
问题描述
我试图通过路由器将硬盘添加到 Windows 上的 2 个复制集。我已经搜索了很多类似的问题并尝试了相同的步骤。但不幸的是......以下是我的步骤:对于配置节点,配置文件:
dbpath=D:/MongoDBConfigNode/config
logpath=D:/MongoDBConfigNode/logs/config1.log
logappend=true
bind_ip=0.0.0.0
port = 17011
configsvr=true
replSet=configsvr
开始使用并使用和初始化mongod -f D:\MongoDBConfigNode\config-17011.conf
连接到它:mongo -host 127.0.0.1 --port 17011
config = { _id : "configsvr", members :[{_id : 0, host : "127.0.0.1:17011" }]}
{
"_id" : "configsvr",
"members" : [
{
"_id" : 0,
"host" : "127.0.0.1:17011"
}
]
}
> rs.initiate(config)
{
"ok" : 1,
"$gleStats" : {
"lastOpTime" : Timestamp(1622598318, 1),
"electionId" : ObjectId("000000000000000000000000")
},
"lastCommittedOpTime" : Timestamp(0, 0)
}
我有两个复制集,sharding1 和 sharding2,每个都有 3 个服务器。
端口 37018 配置文件,37017 和 37019 类似
dbpath=D:\MongoDBSharding1Slave1\data
bind_ip=0.0.0.0
port=37018
logpath=D:\MongoDBSharding1Slave1\logs\sharding1Slave1.log
replSet=Sharding1
shardsvr=true
我在端口 37017、37018、37019 上启动了 mongodb,如下所示:
mongod -f D:\MongoDBSharding1Master\config\mongo_37017.conf
mongod -f D:\MongoDBSharding1Slave1\config\mongo_37018.conf
mongod -f D:\MongoDBSharding1Slave2\config\mongo_37019.conf
使用以下连接mongo --port 37017
,并初始化如下:
config = { _id : "Sharding1", members : [{_id : 0, host : "127.0.0.1:37017"},{_id : 1, host : "127.0.0.1:37018"},{_id : 2, host : "127.0.0.1:37019", "arbiterOnly":true }]}
{
"_id" : "Sharding1",
"members" : [
{
"_id" : 0,
"host" : "127.0.0.1:37017"
},
{
"_id" : 1,
"host" : "127.0.0.1:37018"
},
{
"_id" : 2,
"host" : "127.0.0.1:37019",
"arbiterOnly" : true
}
]
}
> rs.initiate(config);
我对 Sharding2 做了同样的事情。然后我启动了路由器节点:路由器节点配置:
port=27017
bind_ip=0.0.0.0
logpath=D:/MongoDBRoute/logs/route.log
configdb=configsvr/localhost:17011
像这样启动节点:
mongos -f D:\MongoDBRoute\config\route-27017.conf
像这样连接到它:
mongo --host localhost --port 27017,
我得到了错误:
> sh.status()
printShardingStatus: this db does not have sharding enabled. be sure you are connecting to a mongos from the shell and not to a mongod.
> sh.addShard("Sharding1/127.0.0.1:37017, 127.0.0.1:37018, 127.0.0.1:37019");
{
"ok" : 0,
"errmsg" : "no such command: 'addShard'",
"code" : 59,
"codeName" : "CommandNotFound"
}
感谢你的帮助!
解决方案
看看你的服务管理器services.msc
,你应该可以停止它。
或使用
sc stop <SERVICE_NAME>
sc delete <SERVICE_NAME>
如果服务没有停止,请尝试
sc queryex <SERVICE_NAME>
taskkill /pid <SERVICE_PID> /f
如果服务是使用配置文件启动的(就像您定义的那样),您也可以像这样删除它:
mongod.exe -f D:\MongoDBConfig\config-27017.conf --remove