diff --git a/cluster-ha/.gitignore b/cluster-ha/.gitignore new file mode 100644 index 0000000..3a15838 --- /dev/null +++ b/cluster-ha/.gitignore @@ -0,0 +1,3 @@ +.apps +config/DHIS2_home/files +config/DHIS2_home/logs \ No newline at end of file diff --git a/cluster-ha/README.md b/cluster-ha/README.md new file mode 100644 index 0000000..0915858 --- /dev/null +++ b/cluster-ha/README.md @@ -0,0 +1,3 @@ +# Clustered DHIS2 server + +This Docker Compose configuration which presents a proof-of-concept high-availability configuration using 3x DHIS2 tomcat containers and a redis instance for sharing state. See [the DHIS2 cluster docs](https://docs.dhis2.org/en/manage/performing-system-administration/dhis-core-version-239/installation.html?h=cluster+2.39#install_cluster_configuration_introduction) for more info. \ No newline at end of file diff --git a/cluster-ha/config/DHIS2_home/dhis.conf b/cluster-ha/config/DHIS2_home/dhis.conf new file mode 100644 index 0000000..96bc488 --- /dev/null +++ b/cluster-ha/config/DHIS2_home/dhis.conf @@ -0,0 +1,24 @@ +connection.dialect = org.hibernate.dialect.PostgreSQLDialect +connection.driver_class = org.postgresql.Driver +connection.url = jdbc:postgresql://db/dhis2 +connection.username = dhis +connection.password = dhis +# Database schema behavior, can be validate, update, create, create-drop +connection.schema = update + +encryption.password = xxxx +metadata.audit.persist = on + +# URLs for specifying a custom app hub, these are the defaults +#apphub.base.url = https://apps.dhis2.org +#apphub.api.url = https://apps.dhis2.org/api + +redis.enabled = on +redis.host = redis +redis.port = 6379 +# redis.password = +redis.use.ssl = false +redis.cache.invalidation.enabled = on + +# Optional, defaults to 2 minutes +# leader.time.to.live.minutes=4 \ No newline at end of file diff --git a/cluster-ha/config/nginx.conf b/cluster-ha/config/nginx.conf new file mode 100644 index 0000000..dbcb185 --- /dev/null +++ b/cluster-ha/config/nginx.conf @@ -0,0 +1,50 @@ +worker_processes 1; + +events { + worker_connections 1024; +} + +http { + upstream core { + server core:8080 max_fails=3 fail_timeout=60s; + } + + gzip on; # Enables compression, incl Web API content-types + gzip_types + "application/json;charset=utf-8" application/json + "application/javascript;charset=utf-8" application/javascript text/javascript + "application/xml;charset=utf-8" application/xml text/xml + "text/css;charset=utf-8" text/css + "text/plain;charset=utf-8" text/plain; + + server { + listen 80; + port_in_redirect off; + + root /data/apps; + + client_max_body_size 25m; + + # Redirect required to prevent 403 error on / access + rewrite ^/$ $scheme://$http_host/dhis-web-dashboard redirect; + + location / { + include mime.types; + try_files $uri $uri/ $uri/index.html @core; + } + + # location /screenshot { + # proxy_set_header Host $http_host; + # proxy_set_header X-Real-IP $remote_addr; + # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + # proxy_pass http://screenshot:9000; + # } + + location @core { + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_pass http://core; + } + } +} diff --git a/cluster-ha/config/server.xml b/cluster-ha/config/server.xml new file mode 100644 index 0000000..9b3079b --- /dev/null +++ b/cluster-ha/config/server.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cluster-ha/docker-compose.yml b/cluster-ha/docker-compose.yml new file mode 100644 index 0000000..a023cd7 --- /dev/null +++ b/cluster-ha/docker-compose.yml @@ -0,0 +1,42 @@ +version: '3' +services: + core: + image: "dhis2/core-dev:local-tons-final" + restart: always + volumes: + - ./config/DHIS2_home/dhis.conf:/DHIS2_home/dhis.conf + - ./config/server.xml:/usr/local/tomcat/conf/server.xml + - ./config/DHIS2_home:/DHIS2_home + environment: + DHIS2_HOME: /DHIS2_home + # CATALINA_OPTS: "-Dcontext.path='${DHIS2_CORE_CONTEXT_PATH:-}'" + depends_on: + - "db" + - "redis" + scale: 3 + db: + image: "ghcr.io/baosystems/postgis:12-3.3" + restart: always + volumes: + - datadb:/var/lib/postgresql/data + environment: + POSTGRES_DB: dhis2 + POSTGRES_USER: dhis + POSTGRES_PASSWORD: dhis + + redis: + image: redis + restart: always + + gateway: + image: "jwilder/nginx-proxy:alpine" + restart: always + ports: + - "8080:80" + volumes: + - ./config/nginx.conf:/etc/nginx/nginx.conf:ro + - ./.apps:/data/apps:ro + - /var/run/docker.sock:/tmp/docker.sock:ro +volumes: + datadb: + home: