Minimum number of config servers needed for Mongo Cluster - mongodb

I am trying to test sharding in MongoDB cluster.
I am folllowing MongoDB documentation .
They suggest to use 3 config servers. Can I set up a cluster with 1 or 2 servers? Or I need 3 or more config servers?

From the MongoDB docs:
The config server processes are mongod instances that store the cluster’s metadata. You designate a mongod as a config server using the --configsvr option. Each config server stores a complete copy of the cluster’s metadata.
Hence for test setup 1 config server should be fine , but for production it is recommended to use replicated 3 config servers.

Related

How to configure the configuration file for MONGOS?

I am not able to cofigure the configuration file for mongos. How do i set the configurations?
Step 1) Create a separate database for the config server.
mkdir /data/configdb
Step 2) Start the mongodb instance in configuration mode. Suppose if we have a server named Server D which would be our configuration server, we would need to run the below command to configure the server as a configuration server.
mongod –configdb ServerD: 27019
Step 3) Start the mongos instance by specifying the configuration server
mongos –configdb ServerD: 27019
Step 4) From the mongo shell connect to the mongo's instance
mongo –host ServerD –port 27017
Step 5) If you have Server A and Server B which needs to be added to the cluster, issue the below commands
sh.addShard("ServerA:27017")
sh.addShard("ServerB:27017")
Step 6) Enable sharding for the database. So if we need to shard the Employeedb database, issue the below command
sh.enableSharding(Employeedb)
Step 7) Enable sharding for the collection. So if we need to shard the Employee collection, issue the below command
Sh.shardCollection("db.Employee" , { "Employeeid" : 1 , "EmployeeName" : 1})

setting up config server setup for mongo query router

I am using mongo v3.2 - I already have the config replica set as well as two shard replica sets running. When I try to launch the mongos (query router) with the test config file setting below, I get the error copied below - any ideas on how to fix this?
sharding:
configDB: config-set0/127.0.0.1:27019,127.0.0.1:27020,127.0.0.1:27021
error
Unrecognized option: sharding.configDB
I can see this setting in the mongodb docs at the URL below:
https://docs.mongodb.com/manual/tutorial/deploy-shard-cluster/
Ensure that the process is being launched as mongos and not mongod if the intent is to run the process as a query router (and not a config server or a shard).
Use this command to start the mongos.
sudo mongos -f <-- location of conf file -->

What's the proper way of running a mongos client for a sharded cluster?

I have a mongodb cluster up and running. I want to setup a client (mongos) to connect to the config servers from ubuntu. Most instructions just say to run this command:
mongos --configdb cfg0.example.net:27019,cfg1.example.net:27019,cfg2.example.net:27019
Is this command running as a service? Will the process still be running when I exit the shell? What happens if the process goes down? What is the proper way of running this client as a service?
You would use --fork or an init script to make this run as a service post terminal session shut down.
If the process goes down then your application cannot connect to the sharded set. It will be unable to connect at all to your DB. This is (not the only reason) why you should have good redundancy in mongos instances.
I tend to have one mongos per app server personally, however, it is all down to preference. Another option is to have a load balanced set of mongos instances.

Start Mongo with a flag

Is it possible to start mongod (using systemctl) with --master flag?
I want to use the oplog file to watch for data changes. I know this should be used with replicas set, but on my development machine I don't need any replicas set.
Yes, there is an option to enable oplog on standalone mongod. All you need to do is start mongod with --master option. Or if you have a config file add the entry master=true.
This option will ensure that oplog will be created, but unlike a replica set there will not be any secondary instances of mongod which will read it and apply it to their local databases.

mongo shard config server high CPU

We are running a sharded mongodb (v2.2) cluster with four replset shards and three shard config servers, all set up in accordance with 10gen's documentation.
We run this cluster on AWS EC2, with the three config machines as t1.micro.
We run mongos on client machines like so:
mongos --fork --logpath /mnt/log/mongodb.log --configdb cfg1,cfg2,cfg3
According to the documentation, every instance of the mongos daemon should be started with the same ordering of the config servers (e.g. cfg1, cfg2, cfg3).
Our problem is that the machine cfg1 has been getting very slow-- slowing down all of our client connections in turn. We recently added a large number of client connections and soon after started to notice that the CPU on cfg1 was constantly maxed out at 100% while the other two machines did not have problems.
Anyone experience anything similar to this? We have tried to upgrade cfg1 to a m1.medium but our fear is that this is just avoiding the problem and not solving it.