Install and configure MongoDB for EMG

EMG can use MongoDB as the data store for queues, delivery report etc in an active-active configuration.

MongoDB needs to be installed on 3 nodes to function properly.

In this article we will install MongoDB 2.6.4 (Linux 64-bit) on three Linux servers with ip addresses 192.168.0.1, 192.168.0.2 and 192.168.0.3.

Installation will be done under directory /opt giving the installation directory /opt/mongodb-linux-x86_64-2.6.4.

The data files will be placed in /opt/mongodb-data. All paths etc can of course be adjusted if needed in your environment.

We assume EMG has already been installed in directory “/home/emg” and configured to be run by user “emg”.

Installing MongoDB

  • Login as root on first node (192.168.0.1 in this example), download and extract MongoDB.
    cd /opt
    curl -OL "https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.4.tgz"
    tar xvzf mongodb-linux-x86_64-2.6.4.tgz
    mkdir mongodb-data
    chown -R emg.emg mongodb-data mongodb-linux-x86_64-2.6.4
  • Now switch to user “emg” and create a script to start up mongo (or we actually provide one for your convenience.
    su - emg
    cd /opt/mongodb-linux-x86_64-2.6.4
    curl -OL http://www.nordicmessaging.se/files/emg/mongodb-run.sh.txt
    mv mongodb-run.sh.txt run.sh
    chmod 700 run.sh
  • Review the “run.sh” script to ensure it matches your environment and then run it to start mongod
  • Repeat the process on the other two nodes (192.168.0.2 and 192.168.0.3)

Checking mongod status

In /opt/mongodb-data/server.log on each node you can see the mongod server log. Until all three nodes are up and running there will be messages similar to this one:

replSet can't get local.system.replset config from self or any seed (EMPTYCONFIG)

When mongod has been started on all three nodes the messages will change to something like this:

[conn41] end connection 192.168.0.2:53648 (1 connection now open)
[initandlisten] connection accepted from 192.168.0.2:53650 #43 (2 connections now open)

This indicates that all is ok.

EMG configuration

To make EMG use MongoDB as data store add the following to the EMG server.cfg (a suitable place may be just before first connector configuration):

BACKEND=mongo

DB mongo <
TYPE=MONGODB
REPLICANAME=emg
INSTANCES=10
ADDRESS=192.168.0.1:17037
ADDRESS=192.168.0.2:17037
ADDRESS=192.168.0.3:17037
# 1 - Acknowledge when primary node has applied transaction
# 2 - Acknowledge when primary and one secondary node have applied transaction
WRITE_CONCERN=2
>

Make this change on all three nodes and you should then be able to start emgd.

If you place a message in queue on a connector all of the nodes will see it and any of the nodes can pick it up and deliver it.

Managing MongoDB

It is possible to get information from MongoDB and manage a running instance using the mongo shell instance to run javascript commands.

Sample session checking if local MongoDB instance is the master in the replica set:

cd /opt/mongodb-linux-x86_64-2.6.4
bin/mongo --quiet --host 127.0.0.1 --port 17037
emg:SECONDARY> print("ismaster=" + rs.isMaster().ismaster);
ismaster=false
emg:SECONDARY> exit

More information:
http://docs.mongodb.org/manual/core/server-side-javascript/