I've got a standalone MongoDB server with a lot amount of data on it. Let's say, it's srv1
server. I've decided to make a sharded cluster, so I've created additional servers srv2
and srv3
.
We have:
- srv1 - existing mongodb server with data, that will be shard0001.
- srv2 - new mongodb server, that will be shard0000.
- srv3 - also new mongodb server, that will be config server with running mongos instance. Mongos instance running only on that server.
- vk - database I want to be sharded.
On srv3
I've started a mongos with --configdb rs0/127.0.0.1:27002
option and a mongod with --replSet rs0 --configsvr --dbpath /data/config --port 27002
.
After that, via the config instance i've added srv1 and srv2 as a shards with sh.addShard("srv1-2:27017")
command.
Also, on srv2
I've created an empty database and collections with the same names as on srv1
. After that on config server i've executed sh.adminCommand({enableSharding: "vk"});
command.
What I have now:
Surprisingly, it's working. When i'm trying to read/write something to my database, using srv3
as connection point, it's working perfectly! When i've did something before (using srv1
standalone), average response time was about 2 seconds, now it's 0.02 seconds.
The problem I have:
Well, the sharding is not working. Database on srv2
is empty. Here is the output of the db.printShardingStatus()
command from srv3
:
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("5d81f91bdde81f72ac4d1a0a")
}
shards:
{ "_id" : "shard0000", "host" : "srv2:27017", "state" : 1 }
{ "_id" : "shard0001", "host" : "srv1:27017", "state" : 1 }
active mongoses:
"3.6.3" : 1
autosplit:
Currently enabled: yes
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 5
Last reported error: Connection refused
Time of Reported error: Wed Sep 18 2019 14:41:13 GMT+0200 (CEST)
Migration Results for the last 24 hours:
No recent migrations
databases:
{ "_id" : "config", "primary" : "config", "partitioned" : true }
config.system.sessions
shard key: { "_id" : 1 }
unique: false
balancing: true
chunks:
shard0000 1
{ "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : shard0000 Timestamp(1, 0)
{ "_id" : "shard0000", "primary" : "shard0000", "partitioned" : true }
{ "_id" : "vk", "primary" : "shard0001", "partitioned" : true }
{ "_id" : "vk:", "primary" : "shard0000", "partitioned" : true }
Additional info:
The balancer says Connection refused
, but i've opened 27017 and 27002 port on every machine in cluster. It's still not working.
In mongos (srv3
) log there are a lot of successful connections both to srv1
and srv2
. Telnet says the same - everything is fine and opened.
I've added shards without --replSet
options. Mongod instances on srv1
and srv2
working without that options too.
I didn't created any chunk keys or something like this.
Thank you for the reading, will be very grateful for any help.
--shardsvr
?--shardsvr
. Here is the full command for srv1-2 -mongod --bind_ip 0.0.0.0 --shardsvr --port 27017 --fork --logpath /data/logs/mongod.log