CentOSLinuxTutorials

How To Install Mattermost on CentOS 8

Install Mattermost on CentOS 8

In this tutorial, we will show you how to install Mattermost on CentOS 8. For those of you who didn’t know, Mattermost is an open-source, private cloud Slack alternative. A workplace messaging system for web, PCs, and phones, released under the MIT license. As an alternative to proprietary SaaS messaging, Mattermost brings all your team communication into one place, making it searchable and accessible anywhere. Mattermost is “Slack-compatible, not Slack-limited”, supporting a superset of Slack’s incoming and outgoing webhook integrations, including compatibility with existing Slack integrations. From your existing Slack teams, you can import users, public channel history, and even theme setting colors into Mattermost.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you through the step-by-step installation of Mattermost on a CentOS 8.

Prerequisites

  • A server running one of the following operating systems: CentOS 8.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Mattermost on CentOS 8

Step 1. First, let’s start by ensuring your system is up-to-date.

sudo dnf clean all
sudo dnf install epel-release
sudo dnf update

Step 2. Installing Database Server.

Run the following command to install MariaDB:

sudo dnf install mariadb-server

By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:

mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

Remove anonymous users? [Y/n] y
 ... Success!

Disallow root login remotely? [Y/n] y
 ... Success!

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...
Thanks for using MariaDB!

Then, restart the MariaDB database server and enable it to start on system start-up using:

sudo systemctl restart mariadb
sudo systemctl status mariadb
sudo systemctl enable mariadb

After database installation, login to MariaDB shell and create database and user for Mattermost:

$ mysql -u root -p
CREATE DATABASE mattermost;
GRANT ALL PRIVILEGES ON mattermost.* TO mattermost@localhost IDENTIFIED BY 'Your-Strong-Passwd';
FLUSH PRIVILEGES;
QUIT;

Step 3. Installing Mattermost on CentOS 8.

First, you will need to create a separate user to run Mattermost. You can create it with the following command:

sudo useradd -d /opt/mattermost -U -M mattermost

Next, download the latest version of the Mattermost:

wget https://releases.mattermost.com/5.20.2/mattermost-5.20.2-linux-amd64.tar.gz

Unpack the Mattermost archive to the document root directory on your server:

tar xf *.gz
mv mattermost /opt/

Create the storage directory for files:

mkdir /opt/mattermost/data

Also, set the ownership and permissions:

sudo chown -R mattermost:mattermost /opt/mattermost
sudo chmod -R g+w /opt/mattermost

Next, we’ll have to set up the database driver in the file /opt/mattermost/config/config.json by making some changes to its contents. Search for “DriverName” and “DataSource” lines and change as follows:

nano /opt/mattermost/config/config.json
"SqlSettings": {
        "DriverName": "mysql",
        "DataSource": "mattermost:Str0ngP@ss@tcp(localhost:3306)/mattermost?charset=utf8mb4,utf8\u0026readTimeout=30s\u0026writeTimeout=30s",
        "DataSourceReplicas": [],
        "DataSourceSearchReplicas": [],
        "MaxIdleConns": 20,
        "ConnMaxLifetimeMilliseconds": 3600000,
        "MaxOpenConns": 300,
        "Trace": false,
        "AtRestEncryptKey": "myyti1r597i99qrk7eu91ywqhaawz4md",
        "QueryTimeout": 30
    },

Save and close the file. Then, change the directory to /opt/mattermost and start the Mattermost server with the following command:

cd /opt/mattermost
sudo -u mattermost ./bin/mattermost

Step 4. Configure Mattermost Systemd Service.

First, we’ll create a new systemd unit file using the following command:

nano /etc/systemd/system/mattermost.service
[Unit]
Description=Mattermost
After=syslog.target network.target mariadb.service

[Service]
Type=notify
WorkingDirectory=/opt/mattermost
User=mattermost
ExecStart=/opt/mattermost/bin/mattermost
PIDFile=/var/run/mattermost.pid
TimeoutStartSec=3600
LimitNOFILE=49152

[Install]
WantedBy=multi-user.target

Next, start the Mattermost service and enable it to start after system reboot with the following command:

sudo systemctl daemon-reload
sudo systemctl start mattermost.service
sudo systemctl enable mattermost.service

Verify that Mattermost is running and listening on port 8065. You can check it with the following command:

curl http://localhost:8065

Step 5. Configuring Nginx with Mattermost.

Install and configure Nginx as a reverse proxy for better performance and security. Now we install Nginx on the CentOS system:

sudo dnf install nginx

After installing the Nginx web server, start the Nginx service and enable it to start after system reboot with the following command:

sudo systemctl start nginx
sudo systemctl enable nginx

Then, configure the Nginx web server as a proxy for Mattermost:

sudo nano /etc/nginx/conf.d/mattermost.conf
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    mattermost.example.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_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;
   }
}

Finally, restart the Nginx service to apply the changes:

nginx -t
sudo systemctl restart nginx

Step 6. Configure Firewall.

Allow firewall access on HTTP and HTTPS ports:

sudo firewall-cmd --add-service={http,https} --permanent
sudo firewall-cmd --reload

Step 7. Accessing Mattermost Web Interface.

Mattermost will be available on HTTP port 80 by default. Open your favorite browser and navigate to http://mattermost.example.com and continue to configure Mattermost by entering an email address and creating an account.

Congratulations! You have successfully installed Mattermost. Thanks for using this tutorial for installing Mattermost on CentOS 8 system. For additional help or useful information, we recommend you to check the official Mattermost website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button