Multiple Mongos on one server

Solution 1:

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.

Solution 2:

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 :)