Set replSet without restarting the mongod - mongodb

Is any way that I can assign the replSet without restarting the mongod? MongoDB Doc says that we should restart the mongo and assign some parameters, but I'm using MongoHQ's service (via Heroku), I can't find the way to set the replSet. How can I do it?

Related

change the mongod configuration file after mongodb replicaset started

is there a way to change mongod.conf and have it applied to a mongodb replica set after initialization. I tried restarting mongod passing in new mongod.conf however the new config was was not applied it the replica set still reflected the old mongo config
https://docs.mongodb.com/manual/reference/configuration-options/

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..

MongoDB error . rs.initate(config); Was displaying error

I am new to mongodb and am looking into the concept of replication .
Can u please help if u are aware of this error.
The error I got
The config file I am using
Thanks in advance,
Tarun
Its because you're passing in config to the rs.initiate function.
Before you run the initiate you need to start the different mongod instances which will make up the replicaset. Then run rs.initiate() on one of the nodes (without and args). You can then do rs.add(<host:port>) to add the nodes making up the rs.
There are some excellent tutorials available for setting up replicasets. This one is a good starting point:
https://docs.mongodb.com/manual/tutorial/deploy-replica-set/
It provides step-by-step instructions for starting the necessary mongod instances, and linking them as a replicaset in the mongoshell
you need to start all mongod instances with following command which include replica set name, other way is to create entries in config file and pass it to mongod process :
mongod --replSet "Tarun"
then you can initiate : rs.initiate() with your config file

oplog enable on standalone mongod not for replicaset

I am running mongod as standalone server .now i want to enable oplog for it ,i want to know whether it is possible or not ?
I knew I can do this by creating single node ReplicaSet ,but I want to do this without replica set .
I got a reply from the MongoDb Team, and it's working fine.
To enable oplog on a standalone server, start mongo with master options.
On command line start mongod --master.
For conf file append the following line:
master=true
More details here.
For mongo 2.6 or greater the /etc/mongod.conf now uses a yaml format.
To enable the oplog add something similar to the below, note the replication: line may already exist, be sure to use spaces.
replication:
replSetName: rs0
oplogSizeMB: 100
Full documentation here:
https://docs.mongodb.com/manual/reference/configuration-options/#replication-options

Issue with persistent mongoDB data on EC2

I'm trying to store data in a mongoDB database on Amazon EC2. I'm using starcluster to configure and start the EC2 instance. I have an EBS volume mounted at /root/data. I installed mongoDB following the instructions here. When I log in to the EC2 instance I am able to type mongo, which brings me to the mongo shell with the test database. I have then added some data to a database, let's say database1, with various collections in it. When I exit the EC2 instance and terminate it, using starcluster terminate mycluster, and then create a new, different instance, the database1 data is no longer shown in the mongo shell.
I have tried changing the dbpath in the /etc/mongodb.conf file to /root/data/mongodb, which is the EBS volume, and then start and stop the mongodb service using sudo service mongodb stop and sudo service mongodb start. I then try mongo again and receive
MongoDB shell version: 2.2.2
connecting to: test
Sat Jan 19 21:27:42 Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91
exception: connect failed
An additional issue is that whenever I terminate the EC2 instance any changes I made to the config file disappear.
So my basic question is: how do I change where mongoDB stores its data on EC2 so that the data will remain when I terminate one EC2 instance and then start another EC2 instance.
Edit:
In response to the first answer:
The directory does exist
I changed the owner to mongodb
I then issued the command sudo service mongodb stop
Checked to see if the port is released using netstat -anp | grep 27017. There was no output.
Restarted mongodb using sudo service mongodb start
Checked for port 27017 again and receive no output.
Tried to connect to the mongo shell and received the same error message.
Changed the mongodb.conf back to the original settings, restarted mongodb as in the above steps, and tried to connect again. Same error.
The EBS volume is configured in the starcluster config to be reattached on each startup.
For the "connect failed" after you change /etc/mongodb.conf problem, you can check the log file specified in the /etc/mongodb.conf (probably at /var/log/mongodb/mongodb.log):
Check that the directory specified by dbpath exists.
Make sure it is writable by the "mongodb" user. Perhaps it's best to chown to mongodb.
Make sure mongod actually released the 27017 port before starting it using: netstat -anp | grep 27017
Wait a couple seconds for mongod to restart before launching mongo.
It's not clear from your question if you are using Starcluster EBS volumes for Persistent Storage. Note that Ordinary EBS volumes do not automatically persist and reattach when you terminate an instance and start another. You would need to attach and mount them manually.
Once you get that working you'll probably want to create a custom Starcluster AMI with mongo properly installed and /etc/mongodb.conf appropriately modified.