How make 2 DHIS2 instances on a Single Server
Hi @daniel1
You can follow the installation instructions here:
When you get to the section âCreating a user for DHIS2â and âCreating the configuration directoryâ, repeat those steps for each DHIS2 instance you want to run on the machine - in other words, create a user for each DHIS2 instance.
Similarly, for the DHIS2 configuration section, make sure you create a different configuration for each instance - one in each home directory for the user you created above.
For the Tomcat and DHIS2 installation, run the first step (sudo apt-get install tomcat8-user
), then for the next steps, follow those for each dhis2 instance user you created above.
Lastly, you can start your DHIS2 instances individually like this:
sudo -u [dhisuser1] /home/[dhis2user1]/tomcat-dhis/bin/startup.sh
sudo -u [dhisuser2] /home/[dhis2user2]/tomcat-dhis/bin/startup.sh
sudo -u [dhisuser3] /home/[dhis2user3]/tomcat-dhis/bin/startup.sh
âŚetc
Replace [dhis2userx] with your individual user accounts you created.
To automatically start them at reboot, add an entry to the crontab for each user to run the command above on reboot:
sudo su - [dhisuser1]
crontab -e
Add this to the cron file and save it:
@reboot ~/tomcat-dhis/bin/startup.sh
Repeat these commands for each user / instance of DHIS2
Itâs important to note that you must start each instance as the user account that the instance was created under - if you take shortcuts and run tomcat as sudo, the ownership of various files will be adjusted to the root user which will create problems when running it as the correct user. If you accidentally do this, just set ownership for the home directory and itâs contents with sudo chown -R [dhis2user1]:[dhis2user1] /home/[dhis2user1]
Replace [dhis2user1]
with the user name
Let me know if any of this doesnât make sense?
Thank you @Edward_Robinson for the support!
@daniel1 would you like to update us if you found the answer please? Feel free to post if you have more questions. Thank you!
Hello @Edward_Robinson ,
Thank you for your post.
I followed the same steps mentioned in your post to run two instances on one server. But unfortunately not work.
When I run the first instance on port 8080, appear this picture:
and the same problem appears when I run the second instance on port 8081.
I am sharing with you Catalinaâs file if you can help me:
<6>CATALINA_BASE: /home/dhis/tomcat-dhis
<6>CATALINA_HOME: /usr/share/tomcat9
<6>Command line argument: --add-opens=java.base/java.lang=ALL-UNNAMED
<6>Command line argument: --add-opens=java.base/java.io=ALL-UNNAMED
<6>Command line argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
<6>Command line argument: -Djava.util.logging.config.file=/home/dhis/tomcat-dhis/conf/logging.properties
<6>Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
<6>Command line argument: -Xms900m
<6>Command line argument: -Xmx1800m
<6>Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
<6>Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
<6>Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
<6>Command line argument: -Dignore.endorsed.dirs=
<6>Command line argument: -Dcatalina.base=/home/dhis/tomcat-dhis
<6>Command line argument: -Dcatalina.home=/usr/share/tomcat9
<6>Command line argument: -Djava.io.tmpdir=/home/dhis/tomcat-dhis/temp
<6>The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib]
<6>Initializing ProtocolHandler [âhttp-nio-8080â]
<6>Server initialization in [1,715] milliseconds
<6>Starting service [Catalina]
<6>Starting Servlet engine: [Apache Tomcat/9.0.31 (Ubuntu)]
<6>Deploying web application archive [/home/dhis/tomcat-dhis/webapps/ROOT.war]
<6>At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
- INFO 2023-02-05T18:00:11,223 Context variable dhis2-home not set (LogOnceLogger.java [main])
- INFO 2023-02-05T18:00:11,246 System property dhis2.home not set (LogOnceLogger.java [main])
- INFO 2023-02-05T18:00:11,247 Environment variable DHIS2_HOME not set (LogOnceLogger.java [main])
- INFO 2023-02-05T18:00:11,249 Directory /opt/dhis2 cannot be created (LogOnceLogger.java [main])
- ERROR 2023-02-05T18:00:11,255 No Home directory set, and /opt/dhis2 is not a directory (LogOnceLogger.java [main])
<2>Error deploying web application archive [/home/dhis/tomcat-dhis/webapps/ROOT.war]
<2>java.lang.IllegalStateException: Error starting child
<2> at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:720)
<2> at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
<2> at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
<2> at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
<2> at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1848)
<2> at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
<2> at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
<2> at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
<2> at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:118)
<2> at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:772)
<2> at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:427)
<2> at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1575)
<2> at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:309)
<2> at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
<2> at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423)
<2> at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:366)
<2> at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:936)
<2> at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841)
<2> at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
<2> at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
<2> at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
<2> at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
<2> at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
<2> at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
<2> at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
<2> at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
<2> at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
<2> at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
<2> at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
<2> at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
<2> at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
<2> at org.apache.catalina.startup.Catalina.start(Catalina.java:633)
<2> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
<2> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
<2> at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
<2> at java.base/java.lang.reflect.Method.invoke(Method.java:566)
<2> at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:343)
<2> at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:478)
<2>Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
<2> at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
<2> at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
<2> at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717)
<2> ⌠37 more
<2>Caused by: java.lang.IllegalStateException: Properties could not be loaded
<2> at org.hisp.dhis.external.conf.DefaultDhisConfigurationProvider.loadDhisConf(DefaultDhisConfigurationProvider.java:343)
<2> at org.hisp.dhis.external.conf.DefaultDhisConfigurationProvider.init(DefaultDhisConfigurationProvider.java:113)
<2> at org.hisp.dhis.webapi.servlet.DhisWebApiWebAppInitializer.getConfig(DhisWebApiWebAppInitializer.java:115)
<2> at org.hisp.dhis.webapi.servlet.DhisWebApiWebAppInitializer.onStartup(DhisWebApiWebAppInitializer.java:61)
<2> at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:174)
<2> at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5135)
<2> at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
<2> ⌠38 more
<2>Caused by: org.hisp.dhis.external.location.LocationManagerException: External directory not set
<2> at org.hisp.dhis.external.location.DefaultLocationManager.buildDirectory(DefaultLocationManager.java:303)
<2> at org.hisp.dhis.external.location.DefaultLocationManager.getFileForReading(DefaultLocationManager.java:233)
<2> at org.hisp.dhis.external.location.DefaultLocationManager.getInputStream(DefaultLocationManager.java:206)
<2> at org.hisp.dhis.external.location.DefaultLocationManager.getInputStream(DefaultLocationManager.java:199)
<2> at org.hisp.dhis.external.conf.DefaultDhisConfigurationProvider.loadDhisConf(DefaultDhisConfigurationProvider.java:332)
<2> ⌠44 more
<2>
<6>Deployment of web application archive [/home/dhis/tomcat-dhis/webapps/ROOT.war] has finished in [21,754] ms
<6>Starting ProtocolHandler [âhttp-nio-8080â]
<6>Server startup in [22,059] milliseconds
<6>Pausing ProtocolHandler [âhttp-nio-8080â]
<6>Stopping service [Catalina]
<6>Stopping ProtocolHandler [âhttp-nio-8080â]
<6>Destroying ProtocolHandler [âhttp-nio-8080â]
<4>Failed to clear soft references from ObjectStreamClass$Caches for web application [ROOT]
<4>java.lang.ClassCastException: class java.io.ObjectStreamClass$Caches$1 cannot be cast to class java.util.Map (java.io.ObjectStreamClass$Caches$1 and java.util.Map are in module java.base of loader âbootstrapâ)
<4> at org.apache.catalina.loader.WebappClassLoaderBase.clearCache(WebappClassLoaderBase.java:2269)
<4> at org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesObjectStreamClassCaches(WebappClassLoaderBase.java:2256)
<4> at org.apache.catalina.loader.WebappClassLoaderBase.clearReferences(WebappClassLoaderBase.java:1627)
<4> at org.apache.catalina.loader.WebappClassLoaderBase.stop(WebappClassLoaderBase.java:1555)
<4> at org.apache.catalina.loader.WebappLoader.stopInternal(WebappLoader.java:443)
<4> at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257)
<4> at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5432)
<4> at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257)
<4> at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:293)
<4> at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:817)
<4> at org.apache.catalina.core.ContainerBase.destroyInternal(ContainerBase.java:1023)
<4> at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:321)
<4> at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:817)
<4> at org.apache.catalina.core.ContainerBase.destroyInternal(ContainerBase.java:1023)
<4> at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:321)
<4> at org.apache.catalina.core.StandardService.destroyInternal(StandardService.java:556)
<4> at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:321)
<4> at org.apache.catalina.core.StandardServer.destroyInternal(StandardServer.java:1065)
<4> at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:321)
<4> at org.apache.catalina.startup.Catalina.stop(Catalina.java:707)
<4> at org.apache.catalina.startup.Catalina$CatalinaShutdownHook.run(Catalina.java:803)
<4>
Hello @jamal_aljadan
Your Tomcat seems to be properly installed, also, it detects the DHIS2 app (named ROOT.war and located in /home/dhis/tomcat-dhis/webapps/ROOT.war). But as you can see from the quote above, it seems that you have not properly configured (or you are not providing well) the DHIS2 config.
If you follow the guide: System Administration Guide - DHIS2 Documentation you will see that you need to the define the configuration directory (actually it is what is called DHIS2_HOME and config file is expected there). You can define this either via a Tomcat directive (not very common) or via an environment path. The later seems more common and you can find it in the guide where the setenv.sh is explained.
Next edit the file
tomcat-dhis/bin/setenv.sh
and add the lines below.
JAVA_HOME
sets the location of the JDK installation.JAVA_OPTS
passes parameters to the JVM.
-Xms
sets the initial allocation of memory to the Java heap memory space.-Xmx
sets the maximum allocation of memory to the Java heap memory space. This should reflect how much memory you would like to allocate to the DHIS 2 software application on your server.DHIS2_HOME
sets the location of thedhis.conf
configuration file for DHIS 2.Check that the path the Java binaries are correct as they might vary from system to system, e.g. on AMD systems you might see
/java-11-openjdk-amd64
. Note that you should adjust these values to your environment.JAVA_HOME='/usr/lib/jvm/java-11-openjdk-amd64/' JAVA_OPTS='-Xms4000m -Xmx7000m' DHIS2_HOME='/home/dhis/config'
I hope this helps.
Thank @jaime.bosque , for your assistance.
it was my problem. I didnât put the âexportâ word in dhis.conf like this:
export JAVA_HOME='/usr/lib/jvm/java-11-openjdk-amd64/'
export JAVA_OPTS='-Xms4000m -Xmx7000m'
export DHIS2_HOME='/home/dhis/config'
Regards,