MongoDB replica set initialisation - mongodb

I am trying to create a replica set with two replicas and one arbiter. All members are launched using:
mongod --port 25670 --dbpath /data --replSet rs0
The data directory is an empty directory.
On one of the replicas I run rs.initiate but I get the error
replSetReconfig should only be run on PRIMARY, but my state is STARTUP2
I have tried waiting for a PRIMARY to be elected but even after two minutes, I see no indication that an election has taken place.
How do I force the replica set to elect a PRIMARY? Or is there a way to predict the PRIMARY?

The only solution that I found to work consistently is as follows:
Shutdown all servers.
Launch the first replica server.
rs.initiate the replica set with only the first server.
Launch the second replica.
Add it to the replica set.
Finally launch and add the arbiter. For the arbiter it did not matter if I did addArb even before launching the arbiter instance.

Related

starting mongodb single server as replica set to enable oplog through supervisord

I want to start a single mongod instance with command
mongod --config config/mongod.conf
Once above process starts running I also have to call
mongodb/bin/mongo --eval rs.initiate()
Now the issue is I am starting mongod through supervisord
I want to perform both of the above operation one after another.
supervisord takes just 1 command to start the process which is first command. I have no other place to run the rs.initiate().
If I put both the command in shell script even then the control will be stuck with the first command itself.
Perhaps you could combine the commands into a single command. I.e.,
mongod --config config/mongod.conf && sleep 5 && mongodb/bin/mongo --eval rs.initiate()
The sleep command assumes 5 seconds is enough for the mongod to come up and be available for an rs.initiate(). Given you are initiating a replica set I assume you have no data? If so, startup should be relatively quickly. Also if you are attempting to make a single node replica set you might want to consider...
rs.initiate (
{
_id: "somereplicasetname",
version: 1,
members:
[
{ _id: 0, host: "somehostname:27017" }
]
}
)
... so that you don't need to configure the initiated replicaset any further. The _id value (currently showing as somereplicasetname) is expected to match the replica set name in the config file mongod.conf and the somehostname is expected to resolve to the current host.
By the way, I assume you recognize you only need to initialize a replica set once, not every time you start the mongod process..

Start mongod with overrided configuration for replSet

I have few mongoDB instances running as replication set. For each of them, I have prepared configuration file with replSetName, so starting mongo by mongod without -replSet is still adding it to replication set. But, to maintenance instance, I need to run it with replSet disabled - is it possible to override replSetName from configuration by some mongod parameter (like mongod -port, which overrides port: from conf file)
Simple answer is no...
When I need to start node to maintenance mode, I have "ready made string" on my "notepad++" what includes all needed parameters as command line parameters (of course different port number) to bring node up without --replSet..

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.