How can I install two versions of mongodb parallely in Ubuntu 12.04 ? - mongodb

I have mongod 3.0.4 installed. I followed the steps from here. I also want to install mongo 2.6.10 as one of my project uses it. How can I have two versions installed so that I can use either one ?

You can run multiple mongoDB version on the same host as long as these version are not in the same Replica Set as a general rule (which judging by your question will not be a problem).
Deploy 2 installation paths.
Start the application using:
mongod --port 12345
(where 12345 is the port you specified)
To start the exe on a different port.
Default port is 27017 if port not specified in the command.
See http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/
Example:
Deploy:
C:\mongo1\bin\mongod.exe
C:\mongo1\data\
C:\mongo2\bin\mongod.exe
C:\mongo2\data\
Execute:
start /b c:\mongo1\bin\mongod --dbpath "c:\mongo1\data" --port 27017
start /b c:\mongo2\bin\mongod --dbpath "c:\mongo2\data" --port 27050
When connecting using MONGO.exe be sure to specify port to connect to correct instance.

Related

MongoDB - startup automatically with right config on different ports

I have two mongoDBs running on port 27017 and 27018 and now it happened twice, that someone patched the server (Red Hat Enterprise Linux Server release 7.8 Maipo ) and the configuration of mongodb has been lost, so I had to fix it manually by
mongod -port 27017 -config /etc/mongod.conf
mongod -port 27018 -config /etc/mongod_second.conf
Can you tell me who is responsible for that issue, so that this configuration is set automatically?
Do I need to
enable the mongod as a service, so it start up with the right configuration after every patch of the server?
an sudo systemctl enable mongod is not working for me
or
tell the admin who is patching the server to run this mongod -port 27018 - config ... everytime he is restarting the server
Thanks for your help
MongoDB provides installation instructions. Follow them to get the database properly installed. Then edit the configuration file instead of passing arguments when starting mongod.

How to run multiple mongod instances in windows?

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

Mongo Shell couldn't connect to the local server

I'm starting MongoDB using the following command:
sumeet#sumeet-acer:~$ sudo service mongod start
I get a reply as:
mongod start/running, process 7209
sumeet#sumeet-acer:~$
But when I try to enter MongoDB shell by typing mongo I get the following error:
sumeet#sumeet-acer:~$ mongo
MongoDB shell version: 2.0.4
connecting to: test
Fri Jun 12 14:01:59 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
By default, mongod and mongos use the 27017 port. Without any option, the client will try to connect to a server running on localhost and listening at that port.
A few general advices here:
check if the mongod server is really running (ps -edf | grep mongod);
check if it uses the default port (look in the config file1, or use nmap localhost -p0-65535 or netstat | grep 27017);
if mongod is not running, check in the log2 for clues about what goes wrong.
1 /etc/mongodb.conf (on Debian-like systems at least)
2 /var/log/mongodb (on Debian-like systems at least)
The default IP and Port for MongoDB is 127.0.0.1 & 27017.
If you are using config file for specifying settings than re-verify IP & Port mentioned in it.
If you are going with default option than mongod should function as expected.
try mongo 127.0.0.1:27017
this worked for me
For MongoDB 2.2.2 running on Ubuntu 12.10, it's in /var/lib/mongodb/mongod.lock
and after that running the repair command
sudo -u mongodb mongod --repair --dbpath /var/lib/mongodb/
courtesy: https://stackoverflow.com/a/13700262/4907105

Cannot connect to mongod running in Ubuntu machine

I would like to connect with mongo from a cmd shell in windows to a mongod database running in a Ubuntu virtual machine.
mongo is running fine in the Ubuntu terminal and from a putty shell
When I use mongo from a windows cmd shell, I got this error:
mongo.exe --host 192.168.1.6 --port 27017
MongoDB shell version: 2.4.6
connecting to: 192.168.1.6:27017/test
Sat Feb 01 14:45:32.181 Error: couldn't connect to server 192.168.1.6:27017 at src/mongo/shell/mongo.js:147
exception: connect failed
What should I do to be able to connect?
My goal is to use MongoVue to connect to the mongod database in the Ubuntu machine (by the way, MongoVue is not connecting even using its SSH options).
I am trying to connect to the mongod instance of a meteorjs application.
The meteor application is up and running and I can connect to the mongod instance running on the Ubuntu machine at port 3002, both in the Ubuntu terminal and with a putty shell.
stefano#MeteorDeploy:~$ mongo --port 3002
MongoDB shell version: 2.0.4
connecting to: 127.0.0.1:3002/test
PRIMARY> show dbs
local 0.0625GB
meteor 0.0625GB
I would like to connect to the mongod instance using MongoVue as alternative of the putty shell.
I did as in the docs.mongodb.org/manual/tutorial/configure-linux-iptables-firewall/ but without success.
Meteor runs it's own instance of mongo per app. As you note since your edit, when you ssh into your VM you use --port 3002 to connect.
Now you could add that port to your mongo shell launch except for one problem
ps -ef | grep mongo
on your VM will show you the running instance of mongo along with it's startup options. By default this will be bound to 127.0.0.1 which is the loopback adaptor and not accessible outside of the VM.
So what you need to do is either change the startup options in your project, or use another instance on mongo installed on the local machine.
export MONGO_URL=mongodb://localhost:27017/your_db
By default mongod insllation on Ubuntu only listen to localhost, so you can't connect from Windows.
Edit /etc/mongodb.conf and change the bind_ip line (add your windows IP adress on the local network) so it will accept connection.
Be aware that by default mongod does not require authentification so you would maybe want to settup one.
Doc is here :
http://docs.mongodb.org/manual/reference/configuration-options/#bind_ip
For quick and dirty solution (not for Production):
Edit /etc/mongodb.conf and change the bind_ip to 0.0.0.0

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