Lab - Configure a Sharded Cluster

Hi can we remove a shard from a Sharded Cluster if we wrongly added a sharded cluster
When i am validating the lab it is giving me the error that
Mongos not configured correctly - make sure you have only added one shard to your cluster.
Here’s my shard status when i run sh.status()
{ “_id” : “m103-example”, “host” : “m103-example/,m103:27012,m103:27013”, “state” : 1, “draining” : true } { “_id” : “m103-repl”, “host” : “m103-repl/,m103:27002,m103:27003”, “state” : 1 }

As i have two entries in my sharded cluster. Is there a way we can remove a sharded cluster. In my case I want to remove m103-example cluster. Please help.

Also I have tried using
db.adminCommand( { removeShard: “m103-example” } ) but it is returns
“draining started successfully”. Now the shard is in draining state and is taking a lot of time.

Now running sh.status() gives
{ “_id” : “m103-example”, “host” : “m103-example/,m103:27012,m103:27013”, “state” : 1, “draining” : true } { “_id” : “m103-repl”, “host” : “m103-repl/,m103:27002,m103:27003”, “state” : 1 }

Yes it will take time to drain
Depends on the size of sharded collection
Is it still draining?
If it does not work you have to repeat the lab from begin
kill mongods,remove all datafiles,dirs start fresh

Its taking too long. Instead of doing that i have done following steps

  1. use config
  2. db.shards.find() - this query will list all the shards in your cluster then
  3. db.shards.deleteOne("_id":“m103-example”)
    Restart the server and the validate script works fine for me

It is not recommended to touch config as there may be other dependencies
Please check our forum/documentation

Hi @Vishal_01357,

I would plus one to what @Ramachandra_37567 said regarding not touching the config data.

~ Shubham

Yeah completely agree with @Ramachandra_37567. It could create problems, even though the shard is no longer there but it would still point to m103-example in chunks and it is not completely removed. Therefore, I could understand how it would be problematic in a real time application.

Hello, I’ve an issue when running my first config server:

When I run the process with the fork configuration disabled (false), there are no messages, no results

I’ve checked my config file and it seems ok:
config file

I’ve also made sure the folders are created and permissions granted (chmod 777)

When you ran first time with --fork it would have given additional details in mongod.log.Did you check that?

Please paste screenshot of second run without --fork
Did you check if process came up by ps -ef|grep mongo
error 1 means most likely missing dir or wrong path or missing permissions or wrong permissions

Why chmod 777.This is not recommended.Please give just the required permissions

I’ve solved it. Thanks for the hints.
The log was pointing out the permissions of the keyfile were vulnerable

I used the following commands to solve the issue:
chown -R vagrant /var/mongodb/
chmod 700 -R /var/mongodb/

Hi @Ricardo_35642,

You just need read permission for the keyfile. I guess 400 would have been sufficient.

~ Shubham