On-premise Multiple App Servers

When the need to run multiple app-server arise some extra configuration of Moodle is needed. To make this as simple as possible we’ve made preparations so that only two things needs to be done.

  • Set the environment variable MOODLE_CLUSTERED to true

  • Mount 3 extra volumes that are shared between the app servers

  • Mount 1 extra volume that is local to the host

General Preparations

The most common method of sharing data between app servers is to setup a central NFS server. We will not be diving into the setup or configuration of the NFS server in this documentation, we will assume that NFS is used and already setup.

Tip

Share you docker-compose.yml from the same central server and you can setup new app servers that automatically have the correct configuration.

Four Shared Folders

Moodle needs four different folders to be accessible from all app servers. However you can have three of them nested inside the fourth.

moodledata

The main data folder for Moodle, this can also be the root folder for the other shares.

moodletemp

A shared temp folder. It’s possible to create this one under moodledata, e.g. moodledata/moodletemp

moodlecache

A shared cache folder. It’s possible to create this one under moodledata, e.g. moodledata/moodlecache

moodlebackup

A shared backup folder. It’s possible to create this one under moodledata, e.g. moodledata/moodlebackup

Container Host Preparations

When the shared folders have been setup make sure to configure the host servers for the containers to mount these folders in to a location that suits your data structure.

One More Local Folder

Each server also needs a local cache folder that gets mounted into the container on the path /moodlelocalcache. Make sure that this folder is created in a location that suits your data structure.

docker-compose.yml

As a last step docker-compose.yml and app-moodle.env needs to modified to include the settings needed for clustering. Add this to app-moodle.env:

MOODLE_CLUSTERED=false

Now it’s time to modify docker-compose.yml and mount the extra folders. In the following example we assume that all folders that needs to be shared are nested below moodledata and moodledata has been mounted to /data/moodledata. In this example moodlelocalcache has been created at /data/moodlelocalcache. The folders needs to be mounted in the following directories in the container:

Host

Container

/path/to/moodlecache/

/moodlecache/

/path/to/moodletemp/

/moodletemp/

/path/to/moodlebackup/

/moodlebackup/

/path/to/moodlelocalcache

/moodlelocalcache/

Here is an example:

/etc/docker-compose/docker-compose.yml
version: '3'

services:
  moodle:
    image: <your-moodle-image>
    restart: unless-stopped
    env_file:
      - ./settings/database-moodle.env
      - ./settings/app-moodle.env
      - ./settings/shared-email.env
      #- ./settings/shared-debug.env
    volumes:
      - /data/moodledata:/moodledata/
      - /data/moodledata/moodlecache/:/moodlecache/
      - /data/moodledata/moodletemp/:/moodletemp/
      - /data/moodledata/moodlebackup/:/moodlebackup/
      - /data/moodlelocalcache:/moodlelocalcache/
      - ./custom-root-ca.pem:/usr/local/share/ca-certificates/custom-root-ca.crt
    networks:
      - autotech

  cron:
    image: <your-moodle-cron-image>
    restart: unless-stopped
    env_file:
      - ./settings/database-moodle.env
      - ./settings/app-moodle.env
      - ./settings/shared-email.env
      #- ./settings/shared-debug.env
    volumes:
      - /data/moodledata:/moodledata/
      - /data/moodledata/moodlecache/:/moodlecache/
      - /data/moodledata/moodletemp/:/moodletemp/
      - /data/moodledata/moodlebackup/:/moodlebackup/
      - /data/moodlelocalcache:/moodlelocalcache/
      - ./custom-root-ca.pem:/usr/local/share/ca-certificates/custom-root-ca.crt
    networks:
      - autotech

networks:
  autotech: