Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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

3 Answers
3

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 -

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 -

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.

I ran into a problem with the above answer where stop-start-daemon doesn't start a new process with the same name more than once. However, there is a --name argument that allows you to change the line in your upstart script in /etc/init/ to include a new name so it'll start. Something like this:

thnx , there is a mongodb.conf but it is default conf file for default running instance
–
e2burnerJun 10 '12 at 1:00

I've just had a look at my mongodb.conf it sources /etc/default/mongodb presumably for configuration and then starts mongodb using start-stop-daemon
–
jjwchoyJun 10 '12 at 1:04

you could copy this file and modify the command to start mongodb with a different port. you probably want to specify a completely new config file though so you can change log files etc
–
jjwchoyJun 10 '12 at 1:05