Installing two dhis2 instances on same server

Hello team,
I wish to install two dhis2 instances on the same server, how do I go about it.
Kindly advise where necessary. @bobj

You can use docker to setup multiple instances in the same server.

Or you can have two tomcat running but it is really annoying to setup.

I am also really interested by such feature because docker has also its limits. There is a technical solution that I proposed in a pull request and Jira ticket: [DHIS2-10264] - Jira

if it is approved at some point then two DHIS2 instances should be able to run on a single Tomcat.

br

Hi @Kenyuri, you can simply run two instances of tomcat at different port. To run multiple instances of DHIS2 you can define necessary path in setenv file in the bin directory of tomcat.

This is how I’m using setenv.bat (windows)
set “DHIS2_HOME=C:\DHIS2_HOME”
set “JAVA_HOME=C:\Program Files\Java\jdk1.8.0_151”
set “JRE_HOME=C:\Program Files\Java\jdk1.8.0_151\jre”
set “JAVA_OPTS=-Xmx7500m -Xms4000m”
exit /b 0

1 Like

that works but if you need to setup services it can be a mess, on one of my servers, despite having 2 setenv scripts both DHIS2 took the same config file at reboot, in that sense Docker is better for the tomcat part (Postgres can be the host)

This is easy. You can set up as many tomcat instances as you wish on a single server if you have enough resources to support your use case.

  1. You start by installing a servlet container (tomcat9-user or 8-user) that will provide the catalina_home for all the instances you later create

  2. Create the instances you need;

sudo tomcat9-instance-create tomcat-dhis1
sudo tomcat9-instance-create tomcat-dhis2
sudo tomcat9-instance-create tomcat-dhis3

etc
3. Create separate config files for each tomcat instance created.

/home/dhis/config1
/home/dhis/config2
/home/dhis/config3
  1. Modify setenv.sh for each tomcat instance to point to the right configuration file

for instance 1

export JAVA_HOME='/usr/lib/jvm/java-8-openjdk-amd64/'
export JAVA_OPTS='-Xmx6144m -Xms2048m'
export DHIS2_HOME='/home/dhis/config1'

for instance 2

export JAVA_HOME='/usr/lib/jvm/java-8-openjdk-amd64/'
export JAVA_OPTS='-Xmx6144m -Xms2048m'
export DHIS2_HOME='/home/dhis/config2'

for instance 3

export JAVA_HOME='/usr/lib/jvm/java-8-openjdk-amd64/'
export JAVA_OPTS='-Xmx6144m -Xms2048m'
export DHIS2_HOME='/home/dhis/config3'

A bit of work but gives you much control. You can start and stop which ever instance you need, adjust memory basing on need etc.

This has worked for me with upto 8 instances.

3 Likes

I did a PR that was accepted so on 2.38 you will be able to define the DHIS2_HOME in the tomcat “context”

Solution inspired from How can I specify system properties in Tomcat configuration on startup? - Stack Overflow

Example of context file to put on TOMCAT_HOME/conf/Catalina/localhost/[warname].xml when using Catalina engine and no specific host configured

<Context>

  <Environment name="dhis2-home" value="/home/dhis/config-2"
         type="java.lang.String" override="false"/>

</Context>

I tested the solution, DHIS2 detect the right value

2 Likes