How to install Mattermost Team Messaging system on Debian 10

How to install Mattermost Team Messaging system on Debian 10

Mattermost is an open source messaging system written in Golang and React programming languages. This is a slack alternative, and we can use it to build our own messaging service, such as slack or hip hop.

Mattermost brings your team communication to one place and makes it accessible from anywhere. You can access it from desktop computers, Android devices and iPhone.

In this tutorial, we will show you how to install Mattermost on Debian Buster 10. We will install Mattermost on the MySQL database server and Nginx Web server, and run Mattermost as a Systemd service on the latest Debian version Buster 10.

prerequisites

For this tutorial, we will test the Mattermost installation with 2GB of Ram, 25 free disk space, and 2 CPUs on Debian 10.

What are we going to do?

  • Install MySQL server
  • Create a MySQL database for Mattermost
  • Add system users and download Mattermost
  • Configuration is the most important
  • Set Mattermost as a system service
  • Generate SSL Letsencrypt
  • Install Nginx and configure it as a reverse proxy
  • testing

Step 1-Install MySQL database

First, we install MySQL Server 8.0 from the official repository to the Debian server. Sp, we will add the official MySQL repository and install the MySQL software package.

Use the following apt command to install the ‘gnupg2’ tool to the Debian server.

sudo apt install curl wget gnupg2

Use the following command to download and add the MySQL repository of the Debian system.

wget https://dev.mysql.com/get/mysql-apt-config_0.8.13-1_all.debdpkg -i mysql-apt-config_0.8.13-1_all.deb

Now update all Debian repositories and install the MySQL Server package.

sudo apt updatesudo apt install mysql-server -y

During the installation of MySQL Server, the system will ask you to configure the root password of the MySQL server.

Enter the MySQL root password, and then repeat it.

After the installation is complete, start the MySQL service and add it to

systemctl start mysqlsystemctl enable mysql

As a result, the MySQL server is now installed on Debian Buster 10. And the root password of the MySQL server has been configured.

Start MySQL

Step 2-Create the most important MySQL database

By default, Mattermost supports two database drivers, namely PostgreSQL and MySQL databases. In this tutorial, we will use MySQL as the default database for Mattermost.

In this step, we will create a new database and user for the Mattermost installation.

Log in to the MySQL shell using your root user and password as shown below.

mysql -u root -p

Now create a new database and user for Mattermost. We will create a new ‘mattermost’ database with user ‘mmuser’ and password ‘mmuser-password’.

create database mattermost;create user [email protected] identified by 'mmuser-password';grant all privileges on mattermost.* to [email protected];flush privileges;

Now, type “exit” to exit MySQL Shell.

Create the most important database

As a result, the MySQL database and users for Mattermost installation have been created.

Step 3-Add users and download Mattermost

In this step, we will create a new system user and download the Mattermost source code. The Mattermost software will be run under the user named “mattermost” and it will be installed in the “/ opt / mattermost” directory.

Use the following command to create a new system user named ‘mattermost’.

useradd --system --user-group mattermost

Now go to the “/ opt” directory and download the Mattermost source code using the following curl command.

cd /opt/curl -o mattermost.tar.gz https://releases.mattermost.com/5.21.0/mattermost-5.21.0-linux-amd64.tar.gz

Extract the Mattermost source code and create a new “data” directory.

tar -xf mattermost.tar.gzmkdir -p /opt/mattermost/data

After that, change the ownership of the “/ opt / mattermost” directory to the “mattermost” user and make it writable.

chown -R mattermost:mattermost /opt/mattermostchmod -R g+w /opt/mattermost

As a result, the “most important” user has been created, and the “most important” source code has been downloaded to the “/ opt / mattermost” directory.

Add Linux users to Mattermost

Step 4-Configure the most important content

In this step, we will set up Mattermost listening address and database. The Mattermost service will run on the local IP address on the default port 8065 and use MySQL as the database system.

Go to the “/ opt / mattermost” directory, and then edit the configuration file “config.json” in the “config” directory.

cd /opt/mattermost/vim config/config.json

On the “ListenAddress” option, change the IP address to “127.0.0.1”.

    "ListenAddress": "127.0.0.1:8065",

A “SqlSettings”, change DriverName to “mysql”, and use the MySQL database and user we created to change “DataSource”.

  "SqlSettings": {    "DriverName": "mysql",     "DataSource": "dbuser:[email protected](localhost:3306)/dbname?charset=utf8mb4,utf8u0026readTimeout=30su0026writeTimeout=30s",     

Save and close.

Next, use the following command to initialize the Mattermost installation.

sudo -u mattermost ./bin/mattermost

Here are the results you will get.

Configuration is the most important

As a result, Mattermost has been started and running on the local IP address “127.0.0.1” with port “8065”, now press the “Ctrl + c” button to exit.

Step 5-Set Mattermost as a service

In this step, we set Mattermost as the systemd service, and it will run automatically when the system starts after the MySQL database service is running.

Now go to the “/ lib / systemd / system” directory and create a new service file “mattermost.service”.

cd /lib/systemd/system/vim mattermost.service

Now paste the following configuration into it.

[Unit]Description=MattermostAfter=network.targetAfter=mysql.serviceRequires=mysql.service[Service]Type=notifyExecStart=/opt/mattermost/bin/mattermostTimeoutStartSec=3600Restart=alwaysRestartSec=10WorkingDirectory=/opt/mattermostUser=mattermostGroup=mattermostLimitNOFILE=49152[Install]WantedBy=multi-user.target

Save and close.

Next, reload the systemd manager on the Debian system.

systemctl daemon-reload

After that, start the Mattermost service and add it to the system boot.

systemctl start mattermostsystemctl enable mattermost

Create system unit file

Mattermost service is up and running, please check with the following command.

systemctl status mattermost

Here are the results you will get.

Check service status

As a result, the Mattermost service has been up and running on the Debian system, and it will run automatically when the system starts.

Step 6-Install Certbot Letsencrypt

In this step, we will install the certbot tool and generate SSL Letsencrypt. We will use Letsencrypt’s SSL to protect the Mattermost installation.

Use the following apt command to install the certbot tool.

sudo apt install certbot

After the installation is complete, please use the following certbot command to generate SSL letencrypt.

certbot certonly --standalone --agree-tos -m [email protected] -d mattermost.hakase-labs.io

As a result, your SSL certificate will be generated in the “/etc/letsencrypt/live/mattermost-hakase-labs.io” directory.

Step 7-Install and configure Nginx as a reverse proxy

In this step, we will install the Nginx web server and set it as a reverse proxy for the Mattermost service.

Use the following apt command to install Nginx.

sudo apt install nginx -y

After the installation is complete, start the Nginx service and add it to the system boot.

ad

systemctl start nginx systemctl enable nginx

The Nginx web server is up and running.

Next, go to the “/ etc / nginx” configuration directory and create a new virtual host configuration.

cd /etc/nginx/vim sites-available/mattermost

Change the path of the domain name and SSL certificate yourself, and then paste the configuration into it.

upstream backend {   server 127.0.0.1:8065;   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 {   listen         80;   server_name    edu.initrc.fun;   return         301 https://$server_name$request_uri;} server {    listen 443 ssl http2;    server_name    edu.initrc.fun    ssl on;    ssl_certificate /etc/letsencrypt/live/edu.initrc.fun/fullchain.pem;    ssl_certificate_key /etc/letsencrypt/live/edu.initrc.fun/privkey.pem;    ssl_session_timeout 1d;    ssl_protocols TLSv1.2;    ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';    ssl_prefer_server_ciphers on;    ssl_session_cache shared:SSL:50m;    # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)    add_header Strict-Transport-Security max-age=15768000;    # OCSP Stapling ---    # fetch OCSP records from URL in ssl_certificate and cache them    ssl_stapling on;    ssl_stapling_verify on;   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 / {       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;   }}

Save and close.

Next, create an Nginx cache directory and change the ownership of the directory to the default “www-data” user.

mkdir -p /var/cache/nginxchown -R www-data:www-data /var/cache/nginx

After that, activate the Mattermost virtual host, then test the nginx configuration and make sure there are no errors.

ln -s /etc/nginx/sites-available/mattermost /etc/nginx/sites-enabled/nginx -t

Now, use the following systemctl command to restart the Nginx service.

systemctl restart nginx

As a result, Nginx installation and configuration as a reverse proxy for Matermost has been completed. We are ready to test the Mattermost installation.

Configure Nginx

Step 8-test

Open your web browser and enter the domain name of your Mattermost installation URL in the address bar. Mine is:

https://mattermost.hakase-labs.io/

Now you need to create a new Mattermost first account, which will be the Mattermost administrator.

Mattermost Web installer

Type in your user name, email and password for details, and then click the “Create Account” button.

Create a new first team at Mattermost.

build up a team

Enter the name of your first team and click “Next”.

Set team name

The team URL will be the team name, click “Finish” to continue.

Team URL

You will automatically join the default channels “Off-Topic” and “Town Square”.

The most important dashboard

As a result, the Mattermost installation on Debian Buster 10 with MySQL database and Nginx web server has been successfully completed.

Source

Sidebar