Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm not talking about sharding. We had a testing server (linux) and there is already one mongo which belongs to another project/subteam. Is it possible to run multiple, isolated instances of mongodb on one machine? How can I do it?

share|improve this question
add comment

2 Answers

up vote 13 down vote accepted

Yes, you can do this by specifying different port numbers and data directories for the other instances of mongod, and then specifying the new port number in the client.

For example:

./mongod --dbpath /foo/bar/otherpath --port some_other_port

You can also change the shard server and config server port numbers if you need to.

share|improve this answer
    
Thanks a lot, that was what i looked for. –  om-nom-nom Aug 1 '11 at 12:34
1  
Is it possible to specify this within mongodb.conf? Or would I have to create a script to do that? (on *nix) –  Justin Aug 23 '11 at 22:22
    
@Justin, you can certainly specify these options within a config file - see mongodb.org/display/DOCS/File+Based+Configuration. But then you still need to pass different config files to the different instances. –  dsolimano Aug 24 '11 at 1:10
    
Thanks @dsolimano, I've got two scripts in rc.d for two instances of Mongo. I've specified different paths for the db, pid, logging and given them different ports to listen on. It's also being forked, and when the second script runs it fails as mongo is already running (the first instance). So I guess my real question was (I I haven't had much luck finding this on the web) is can you have two forked instances running at the same time? Thanks –  Justin Aug 24 '11 at 14:25
    
@Justin, I think this probably rises to the level of a new question, perhaps you should ask it on this site? It sounds like there is something about the way you're starting Mongo that is causing a problem. –  dsolimano Aug 24 '11 at 21:09
add comment

The steps I've taken are:

  1. Copy conf file /etc/mongod.conf to mongod2.conf and also to mongod3.conf
  2. Edit conf files to have different ports and different database paths
  3. Copy init.d start script /etc/init.d/mongod to mongod2 and also to mongod3
  4. Copy binary mongod /usr/bin/mongod to /usr/bin/mongod2 and also to /usr/bin/mongod3
  5. Edit init.d start scripts and changed the following:

    CONFIGFILE="/etc/mongod2.conf" (mongod3.conf, respectively)

    ....

    mongod=${MONGOD-/usr/bin/mongod2} (mongod3, respectively)

Replaced /var/lock/subsys/mongod with /var/lock/subsys/mongod2 (mongod3, respectively) wherever I found it.

Resist the temptation to replace mongod.lock with mongod2.lock (or to mongod3.lock, respectively). They are in different folders (database folders are different) and won't conflict.

Now I can

service mongod start|stop|status

service mongod2 start|stop|status

service mongod3 start|stop|status

and also

mongo --port <port_number> 

for each mongo instance (remember the port settings from the conf files)

I am not aware of any side effect of renaming the mongod binary..

Hope this helps.

[Later edit] To start the instances automatically, just ln -s /etc/init.d/mongod2 /etc/rc.d/rc3.d/S86mongod and ln -s /etc/init.d/mongod3 /etc/rc.d/rc3.d/S87mongod :)

share|improve this answer
    
Ah Nice one! did exactly the same without much luck before because I didn't think we should also duplicate the mongod executable itself. All good now. –  Bach Feb 11 '13 at 8:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.