How to run multiple mongod instances in windows? - mongodb

I am trying to run mongod instances on port 27018 and 27019, while port 27017 already running using windows command line. However,I am unable to start as it is terminating saying, already a mongod instance is running. How do i achieve running multiple instances ?

You just need to create another folders
MongoDB2
MongoDB3
dbpath for the second and third instance,
and run it in different port(27018,27019)
The dbPath value controls the location of the mongod instance’s data directory. Ensure that each database has a distinct and well labeled data directory.
Also Refer doc
mongod --dbpath /usr/local/var/MongoDB2 --port 27018

Related

Start replSet automatically

I am pretty new to installing MongoDB on Server. It was for a MERN stack project. And in order to use a library Pusher. I need to convert the Stand Alone Server to Replication set.
So I used the script sudo mongod --port 27017 --dbpath /var/lib/mongodb --replSet rs1 --bind_ip localhost,<my server ip> and the terminal will start logging. And then I can use another terminal to access the MongoDB database. But the problem is the moment I close the logging terminal (where I used the --replSet script) I will be prevented from accessing the MongoDB database.
So is there any way to automatically execute the --replSet script as soon as the server starts and keep it running?

Mongo db not start

i am new to mongo db. And i do not understand why my monggo db is not starting, and instead it is shutting down.
I have an image below, that shows what is going on at the cmd
cmd, mongo db
Kill all other mongod instance before starting a new instance. The problem is clearly written in the cmd.
Or try to start mongo on another port using
mongod --port 27010 --dbpath c:\data\newDb
Also, make sure you have c:\data\newDb and c:\data\db folders created before starting the server.

How to disable remote connections to MongoDB?

Normally the answer to question is to set:
bindIp: 127.0.0.1
I have this set in /etc/mongod.conf. Unfortunately I am still allowed access to this database remotely. I have restarted the Mongo service a couple times, to no avail.
Does anyone have an idea as to why my database is still accessible remotely?
I'm using MongoDB version 3.0.9
Remoting in to mongod clients using bindIp = 127.0.0.1 is possible through an SSH tunnel because the shell session is seen as 127.0.0.1.
Enabling bind_ip = 127.0.0.1 should be sufficient. Restart MongoDB server after the changes are done.
References:
http://greenwireit.com/it-tech-support-articles/enable-remote-access-default-mongodb-installation/
https://www.mkyong.com/mongodb/mongodb-allow-remote-access/
http://wptrafficanalyzer.in/blog/enabling-and-disabling-remote-access-to-a-mongodb-server/
Perhaps you must specify the mongodb.conf file when loading your mongod instance. Like so:
mongod --fork --config /etc/mongodb.conf --logpath mongodblogs/mongodb.log --dbpath mongod
This is best variant in security aspect:
su <NOTROOTUSER>
mongod --dbpath data --bind_ip localhost
Create new user on you server then log in.
Root is not recommended for running mongo server.

Is it possible to run both mongod and mongos at a time in mongodb?

I am new to mongodb,I would like to know is it possible to run both mongod and mongos instance at a time.
Yes, it is possible, but you'll need to use different tcp ports as both mongod and mongos are using the same 27017 by default. You can specify ports using --port <port> flag as noted in mongod and mongos docs.

Configuring Master Slave config for MongoDB on single Ubuntu Machine

I want to setup Master Slave config for Mongo DB on my Ubuntu Machine. I can see the setting to do this in /etc/mongodb.conf but that would make my DB either Master or Slave.
Is there any way I can run two different server on same machine and use one as Master and other as slave. I want to do this for testing purpose.
The best way would be to not use /etc/init.d/* scripts and use the good old command line. Make sure mongodb is not running on your machine. Locate the folder where binaries are installed, and then from command line run:
./mongod --dbpath /path_to_master_db_files --master --logpath /path_to_logs/master.log --port 27017 --fork
Then open up another terminal, navigate to the same folder and run this:
./mongod --dbpath /path_to_slave_db_files --slave --logpath /path_to_logs/slave.log --port 27018 --source=localhost:27017 --fork
And there you go - you should have a master running on 27017, and slave running on 27018. Hope this helps.
BTW, I am assuming you are not running this configuration in production, and only want to try it out on your local instance.
For testing purposes you can start both instances manually, take a look at this link. Quoting from the docs:
IMPORTANT
Replica sets replace master-slave replication for most use cases. If possible, use replica sets rather than master-slave replication for all new production deployments. This documentation remains to support legacy deployments and for archival purposes only.
Locate the folder where the MongoDB binaries are located:
mkdir -p ../master
./mongod --dbpath ../master --master --logpath ../master/master.log --port 27017
Then open up another terminal, navigate to the same folder and run this:
mkdir -p ../slave
./mongod --dbpath ../slave --slave --logpath ../slave/slave.log --port 27018 --source=localhost:27017