I am new to linux and mongodb.
I've already installed mongodb on ubuntu but I want to run one more instance on different port.
As I understood from other questions and forums , there must be upstart script.
https://stackoverflow.com/questions/7300109/ubuntu-start-upstart-second-instance-of-mongodb
But I can not find or locate an upstart script on my server.If I create a upstart script , where should I locate it to start as a service.
or is there any other proper and easy way to start another instance of mongodb on the same server but different port.
Best Answer
Are you running from the 10gen repository or from the default Debian/Ubuntu repo? I recommend using the official 10gen repository.
Check this link out - [10gen MongoDB How-To Install on Ubuntu:] http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/. It is best to uninstall the previous mongodb installation prior to this change, which will also require you to modify your repository source (in /etc/apt/source.list) but this is also detailed in the link above. I recommend using upstart over sysvinit and the processed is outlined in the How-To.
With the 10gen Ubuntu set-up, the configuration file is in /etc/mongodb.conf.
There are several ways that you can you can run a separate mongod process, one would simply be running it from the cli -
which will produce (using 'ps')
and you can connect via the cli -> mongod --port 3001
Another way is creating a copy of /etc/mongodb.conf -
I have changed the dbpath (where the mongodb files are stored) from /var/lib/mongodb to /var/lib/mongodbnew; the log path has changed from mongodb.log to mongodbnew.log and the port has changed from the default of 27017 to 27018 (you will also have to remove the # to uncomment the line).
I also changed the top line to reflect the new name of this configuration file.
You will also have to create the data directory because it won't exist and without it, the mongod process won't start and ensure that the owner and group is mongodb -
Additionally, create and change the persmissions of your log file -
To start your new mongod process (in the background) from the cli, type
which send the following to the screen -
"all output going to: /var/log/mongodb/mongodbnew.log"
Check that the mongod processes are running with "ps" -
To verify that you can connect, run the Mongo shell -
With lsof, you should now see your two mongod processes, the original bound to 27017 and the new one bound to 27018.
To ensure that the two processes run at start-up, copy the original init configuration file -
which should result in two files such as -
Edit the new mongodbnew.conf file using vi or whatever you prefer to look like this -
stop on runlevel [06]
end script
I have tested this on Ubuntu 12.04 and it appears to work well, including after a reboot. I haven't run it in production obviously. Apologies, if there's any typo's above but there's a lot of information and I may have missed something.
Finally, here's a link on Replica Sets that might help you as it has come examples on starting multiple mongod instances from the cli - http://www.mongodb.org/display/DOCS/Replica+Set+Tutorial.