How to Install Mattermost on AlmaLinux 9

How to install Mattermost on AlmaLinux 9

Welcome to this tutorial on how to install Mattermost on AlmaLinux 9. Mattermost is an open-source, self-hosted team communication platform that provides messaging, file sharing, and integrations with various tools and services. It offers an alternative to proprietary messaging systems, giving you complete control over your data and customization options. This guide will walk you through installing and configuring Mattermost on AlmaLinux 9, ensuring a secure and efficient setup for your team’s communication needs.

Prerequisites:

  • An Alma Linux 9 VPS
  • At least 2GB of RAM
  • SSH root access or a system user with sudo privileges

Step 1. Update System Packages

To start, log in to your Alma Linux 9 VPS using SSH:

ssh root@IP_Address -p Port_number

Replace ‘IP_Address’ and ‘Port_number’ with your server’s IP address and SSH port number. If needed, replace ‘root’ with the username of your sudo account.

Once logged in, you must ensure that all AlmaLinux OS packages installed on the server are up to date. You can do this by running the following commands:

dnf update -y && dnf upgrade -y

Step 2. Install Dependencies:

Afterward, install essential dependencies on your server. Run the following command to install these dependencies:

dnf install git gcc redhat-rpm-config libxslt-devel bzip2-devel openldap-devel libjpeg-devel freetype-devel curl unzip openssl-devel wget yum-utils make libffi-devel zlib-devel tar

Step 3. Install MariaDB:

Mattermost supports PostgreSQL 11.0+, MySQL 5.7.12, 8.0.12+, or equivalent MariaDB servers. We’ll install MariaDB from the AlmaLinux repository. To do this, run the following command:

dnf install mariadb-server -y

Next, initiate and enable the MariaDB service with the following command. This command will start MariaDB and configure it to launch automatically during boot.

systemctl enable --now mariadb

After installing MariaDB, create a new MariaDB user for Mattermost with the following commands:

# mysql -u root

MariaDB [(none)]> CREATE DATABASE mattermostdb;

MariaDB [(none)]> CREATE USER 'mattermost'@'localhost' IDENTIFIED BY 'YourStrongP4ssw0rd';

MariaDB [(none)]> GRANT ALL PRIVILEGES ON mattermostdb.* TO 'mattermost'@'localhost' WITH GRANT OPTION;

MariaDB [(none)]> FLUSH PRIVILEGES;

Be sure to update the value of the “YourStrongP4ssw0rd” above with a more secure password.

Step 4. Install and Configure Mattermost

We’re setting up a Mattermost instance using a dedicated system user account. Let’s create a new system account named “mattermost” using the following command to do this.

useradd -mrd /opt/mattermost mattermost -s "$(which bash)"

Next, access the “mattermost” user and download Mattermost. If you want to download the most recent tarball package, you can go to their download page at https://docs.mattermost.com/install/install-tar.html and replace the link in the command below with the newest version.

su - mattermost
wget https://releases.mattermost.com/9.9.0/mattermost-9.9.0-linux-amd64.tar.gz -O mattermost.tar.gz

Next, extract the downloaded file using the following command:

tar -xzvf mattermost.tar.gz --strip-component 1

Before running Mattermost, we need to configure it to connect to our database. We recommend taking a backup of this default config ahead of making changes:

cp /opt/mattermost/config/config.json /opt/mattermost/config/config.defaults.json

After you create a backup of the default configuration, you can access the default file and configure it for your instance.

nano /opt/mattermost/config/config.json

In the ‘SqlSettings’ section, modify the following values:

Set the DriverName value to "mysql".
Set the DataSource value to
"mattermost:YourStrongP4ssw0rd@tcp(localhost:3306)/mattermostdb?charset=utf8mb4,utf8\u0026readTimeout=30s\u0026writeTimeout=30s",

Replace ‘mattermost’, ‘YourStrongP4ssw0rd’ and ‘mattermostdb’ with the database name, user, and password you created in the previous step.

Now, in the ‘ServiceSettings’ section, modify the following values:

Set your "SiteURL" to the domain name you want for your Mattermost application (e.g. https://mattermost.yourdomain.com).

Save the file, then exit from Nano editor

Then, exit from user ‘mattermost’:

exit

Step 5. Create Mattermost Systemd Service File

Now that Mattermost is installed and configured, you need to create a Systemd service file to start, restart, or stop it. You can make this file using the following command:

nano /etc/systemd/system/mattermost.service

Add the following lines:

[Unit]
Description=Mattermost
After=network.target

[Service]
Type=notify
ExecStart=/opt/mattermost/bin/mattermost
TimeoutStartSec=3600
KillMode=mixed
Restart=always
RestartSec=10
WorkingDirectory=/opt/mattermost
User=mattermost
Group=mattermost
LimitNOFILE=49152

[Install]
WantedBy=multi-user.target

Save and close the file, then reload the systemd daemon to apply the changes:

systemctl daemon-reload

Next, initiate and enable the Mattermost service with the following command. This command will start Mattermost and be configured to launch automatically during boot.

systemctl enable --now mattermost

Check if the Mattermost service is started correctly using the following command:

systemctl status mattermost

If the service starts correctly, its output should be similar to the following:

# systemctl status mattermost
● mattermost.service - Mattermost
     Loaded: loaded (/etc/systemd/system/mattermost.service; enabled; preset: disabled)
     Active: active (running) since Tue 2024-06-18 14:18:47 CDT; 57min ago
   Main PID: 5743 (mattermost)
      Tasks: 35 (limit: 23192)
     Memory: 340.4M
        CPU: 26.229s
     CGroup: /system.slice/mattermost.service
             ├─5743 /opt/mattermost/mattermost/bin/mattermost
             ├─5768 plugins/com.mattermost.nps/server/dist/plugin-linux-amd64
             ├─5776 plugins/com.mattermost.calls/server/dist/plugin-linux-amd64
             └─5786 plugins/playbooks/server/dist/plugin-linux-amd64

You can access the Mattermost backend using the URL http://YOUR_SERVER_IP:8065.

Step 6. Configure Reverse Proxy

A web server is required if you want to use a domain name instead of your server’s IP address. In this tutorial, we’ll install and use Nginx. Execute the following command to install nginx:

dnf install -y nginx

Next, start and enable the Nginx service using the following command. This will start Nginx immediately and configure it to launch automatically at boot.

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
systemctl enable --now nginx

Next, create an Nginx server block:

nano /etc/nginx/conf.d/mattermost.conf

Add the following lines:

upstream backend {
   server 127.0.0.1:8065;
   keepalive 32;
}

server {
  listen 80;
  server_name   mattermost.yourdomain.com;

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_http_version 1.1;
       proxy_pass http://backend;
   }

   location / {
       client_max_body_size 50M;
       proxy_set_header X-Frame-Options SAMEORIGIN;
       proxy_buffers 256 16k;
       proxy_buffer_size 16k;
       proxy_read_timeout 600s;
       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;
   }
}

Be sure to update “mattermost.yourdomain.com” with your domain name.

Save and close the file, then reload the nginx service to apply the changes:

systemctl reload nginx

You can now access Mattermost using your domain name at http://mattermost.yourdomain.com and begin working on your project. Refer to their official documentation for additional details about Mattermost, its features, and configuration.

Of course, you don’t have to install Mattermost on AlmaLinux 9 if you use one of our AlmaLinux VPS Hosting services. You can ask our expert Linux admins to install and configure Mattermost for you. They are available 24×7 and will take care of your request immediately.

If you liked this post on installing Mattermost on Alma Linux 9, please share it with your friends or leave a comment below.

Leave a Comment