Setting up a Mattermost Server

Introduction

This tutorial will explain how to set up a Mattermost server for team collaboration.

Environment

Hardware amd64 VPS
OS Debian 10 Buster

Dependencies

  1. Docker
  2. docker-compose
  3. Internet Domain

Step by Step Instructions

1. Add DNS entry to your domain.

A domain of your choice needs to point to the address of your server.

2. Change to root user

sudo -s

3. Installation of additional Dependencies

apt update
apt install -y certbot nginx

4. Create user user and add persistence

useradd --system --create-home --shell /bin/bash --uid 678 --user-group --password <your-password-here> mattermost
mkdir db
mkdir app
mkdir web
chown -R mattermost:mattermost /home/mattermost

5. Configure NGINX server

Create and open vhost file:

cd /home/mattermost
nano /etc/nginx/sites-available/sub.domain.tld.vhost
chmod 600 docker-compose.yaml

Paste the following configuration into the file:

upstream backend {
   server 127.0.0.1:56000;
   keepalive 32;
}
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=mattermost_cache:10m max_size=3g inactive=120m use_temp_path=off;
server {
  server_name sub.domain.tld;

  location / {
       client_max_body_size 50M;
       proxy_set_header Connection "";
       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_set_header X-Forwarded-Proto $scheme;
       proxy_set_header X-Frame-Options SAMEORIGIN;
       proxy_buffers 256 16k;
       proxy_buffer_size 16k;
       proxy_read_timeout 600s;
       proxy_cache mattermost_cache;
       proxy_cache_revalidate on;
       proxy_cache_min_uses 2;
       proxy_cache_use_stale timeout;
       proxy_cache_lock on;
       proxy_http_version 1.1;
       proxy_pass http://backend;
  }

   location ~ /api/v[0-9]+/(users/)?websocket$ {
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "upgrade";
       client_max_body_size 50M;
       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_set_header X-Forwarded-Proto $scheme;
       proxy_set_header X-Frame-Options SAMEORIGIN;
       proxy_buffers 256 16k;
       proxy_buffer_size 16k;
       client_body_timeout 60;
       send_timeout 300;
       lingering_timeout 5;
       proxy_connect_timeout 90;
       proxy_send_timeout 300;
       proxy_read_timeout 90s;
       proxy_pass http://backend;
   }

  location ~ /.well-known/acme-challenge/ {
    allow all;
  }

}

Activate vhost file:

ln -s /etc/nginx/sites-available/sub.domain.tld.vhost /etc/nginx/sites-enabled/sub.domain.tld.vhost

Restart NGINX:

systemctl restart nginx

6. Create Let's Encrypt certificate for nextcloud.domain.tld

https://certbot.eff.org/lets-encrypt/debianbuster-nginx

Restart NGINX:

systemctl restart nginx

7. Run server

Create and open docker-compose.yaml:

cd /home/mattermost
nano docker-compose.yaml

Paste the following configuration into the file:

version: "3"

services:
  db:
    build: db
    read_only: true
    restart: unless-stopped
    volumes:
      - ./db/var/lib/postgresql/data:/var/lib/postgresql/data
      - /etc/localtime:/etc/localtime:ro
    environment:
      - POSTGRES_USER=mmuser
      - POSTGRES_PASSWORD=mmuser_password
      - POSTGRES_DB=mattermost

  app:
    build:
      context: app
      args:
        - edition=team
        - PUID=678
        - PGID=678
    restart: unless-stopped
    volumes:
      - ./mattermost/config:/mattermost/config:rw
      - ./mattermost/data:/mattermost/data:rw
      - ./mattermost/logs:/mattermost/logs:rw
      - ./mattermost/plugins:/mattermost/plugins:rw
      - ./mattermost/client-plugins:/mattermost/client/plugins:rw
      - /etc/localtime:/etc/localtime:ro
    environment:
      # set same as db credentials and dbname
      - MM_USERNAME=mmuser
      - MM_PASSWORD=mmuser_password
      - MM_DBNAME=mattermost
      # in case your config is not in default location
      #- MM_CONFIG=/mattermost/config/config.json
    ports:
      - "56000:80"

Run server:

docker-compose up -d

8. Set up server

Visit your website: https://sub.domain.tld

Follow the on-screen instructions.

Do no change any database related settings.

Just enter the Admin's username, password and e-mail address. (E-Mail address does not need to be valid; won't be sent to.)
Then press the launch button and log in with your Admin account.

 

Sources


Revision #9
Created Sun, Aug 16, 2020 12:32 AM by Akito
Updated Mon, Aug 17, 2020 10:01 AM by Akito