Sunday, 25 October 2020

Install Mattermost Chat Server on CentOS/RHEL 8


Mattermost is an open source, self-hosted team chat and collaboration software. In this article, you will learn how to install this XMPP server on CentOS / RHEL 8.


Table of Contents:


What is Mattermost? :

Mattermost is a free Slack alternative. It is an open source, self-hosted server that has team chat, file sharing, search, integration and collaboration features.

Mattermost is designed as an internal chat for organisations and companies, and mostly markets itself as an open-source alternative to Slack.

Mattermost is available in open source and enterprise editions. Open Source edition is free, whereas Enterprise editions requires per user license. You can find Mattermost Pricing plans at their official website.


Environment Specification:

We are using a minimal CentOS 8 virtual machine with following specifications.

  • CPU - 3.4 Ghz (2 cores)
  • Memory - 2 GB
  • Storage - 20 GB
  • Operating System - CentOS 8.0
  • Hostname – mattermost-02.centlinux.com
  • IP Address - /24


Updating Installed Packages on Linux Server:

By using a SSH client, connect with mattermost-02.centlinux.com as root user.

By following the best practice, update software packages in your Linux operating system.

# dnf update -y


Installing MySQL Database Server on CentOS / RHEL 8:

Mattermost requires a backend database server to store its data. It supports MySQL and PostgreSQL databases.

You may install PostgreSQL database server to use with your XMPP server. But, we are installing MariaDB database server, a famous fork of MySQL.

If you already have a working database server, then you can skip this step and create the Mattermost database on that server.

MariaDB server is available in standard yum repositories, therefore you can install it with the help of dnf command.

# dnf install -y mariadb-server

Enable and start MariaDB database service.

# systemctl enable --now mariadb.service
Created symlink /etc/systemd/system/mysql.service â /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service â /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service â /usr/lib/systemd/system/mariadb.service.

Since, you have installed a fresh MariaDB server, therefore, you are required to perform initial configuration of the MySQL instance.

Use the following Linux command to configure your MySQL instance.

# mysql_secure_installation


In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

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

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

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

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

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

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

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

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

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

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

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

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Connect with MySQL server as root database user.

# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Create a new database user, that will own the Mattermost software database.

MariaDB [(none)]> create user 'mmuser'@'localhost' identified by 'mmpwd';
Query OK, 0 rows affected (0.001 sec)

Now create the mattermost database.

MariaDB [(none)]> create database mattermost;
Query OK, 1 row affected (0.001 sec)

Grant full rights on mattermost database to mmuser.

MariaDB [(none)]> grant all privileges on mattermost.* to 'mmuser'@'localhost';
Query OK, 0 rows affected (0.001 sec)

Exit from mysql shell.

MariaDB [(none)]> exit


Installing Mattermost Chat Server on CentOS / RHEL 8:

To download Mattermost, go to their official website and obtain the URL of the latest version.


By using wget command, download the latest version of Mattermost software straight at the Linux CLI.

# cd /tmp
# wget https://releases.mattermost.com/5.28.1/mattermost-5.28.1-linux-amd64.tar.gz
--2020-10-25 10:14:42--  https://releases.mattermost.com/5.28.1/mattermost-5.28.1-linux-amd64.tar.gz
Resolving releases.mattermost.com (releases.mattermost.com)...,,, ...
Connecting to releases.mattermost.com (releases.mattermost.com)||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 183523028 (175M) [application/x-gzip]
Saving to: âmattermost-5.28.1-linux-amd64.tar.gzâ

mattermost-5.28.1-l 100%[===================>] 175.02M   515KB/s    in 5m 27s

2020-10-25 10:20:11 (549 KB/s) - âmattermost-5.28.1-linux-amd64.tar.gzâ saved [183523028/183523028]

Extract the downloaded tarball with the help of tar command.

# tar xvf mattermost-5.28.1-linux-amd64.tar.gz

After extraction, move the mattermost directory (that was extracted from tarball) to /opt directory.

# mv mattermost /opt/

Create a data directory for Mattermost application.

# mkdir /opt/mattermost/data

Create a Linux user to own Mattermost software and in-memory processes.

# cd
# useradd -r -U mattermost

Adjust the file permissions and SELinux file contexts of the /opt/mattermost directory.

# chown -R mattermost:mattermost /opt/mattermost
# chmod -R g+w /opt/mattermost
# restorecon -R /opt/mattermost/

Mattermost Configurations are located in /opt/mattermost/config/config.json.

You need to edit this configuration file to update settings according to your environment.

# vi /opt/mattermost/config/config.json

Find and set following directives related to Mattermost backend database. You may find them under "SqlSettings" configuration block.

"DriverName": "mysql",
"DataSource": "mmuser:mmpwd@tcp(localhost:3306)/mattermost?charset=utf8mb4,utf8\u0026readTimeout=30s\u0026writeTimeout=30s",

Find and set following directive. You may find it under "ServiceSettings" configuration block.

"SiteURL": "http://mattermost-02.centlinux.com",

Please ensure that the hostname of your Linux server is resolvable. You can either configure an Authoritative DNS Server or simply use the local DNS resolver.

Here, we are using the Local DNS resolver.

# vi /etc/hosts

Add following entry therein.  mattermost-02 mattermost-02.centlinux.com

Mattermost software has been installed and configured. You can test it by using following command.

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

The Mattermost service has been started and listening on default port i.e. 8065.


Configure Autostart of Mattermost Service:

To enable Mattermost service to autostart at the time of Linux startup. You need to create a Systemd service unit.

Use the vim editor and create a Systemd service unit for Mattermost.

# vi /etc/systemd/system/mattermost.service

Add following directives in this file.

After=syslog.target network.target postgresql.service



Enable and start Mattermost service.

# systemctl enable --now mattermost.service
Created symlink /etc/systemd/system/multi-user.target.wants/mattermost.service â /etc/systemd/system/mattermost.service.


Configure Linux Firewall:

Although, Mattermost service is started, but it is still not accessible from the network clients. You have to allow the default service port in Linux firewall, so it can accept incoming traffic from the network clients.

You can use firewall-cmd command for this purpose.

# firewall-cmd --permanent --add-port=8065/tcp
# firewall-cmd --reload


Accessing Mattermost Web UI:

Open URL http://mattermost-02.centlinux.com:8065/ in a web browser.


Because you are accessing Mattermost web UI for the first time, therefore, it is asking to register your email address and create a user account on the cloud.


We need to create a team for collaboration and chatting.


Provide a team name and click on "Next>".


You team has been created. Note down the team URL and communicate it to your Team members.


Now, you reach at the Mattermost dashboard. The control is in your hand now, customize the Mattermost chat server according to your requirements.



You have successfully installed Slack alternative i.e. Mattermost chat server on CentOS / RHEL 8. If you found this guide too advanced then you should buy and read How Linux Works, 2nd Edition: What Every Superuser Should Know Second Edition written by Brian Ward.

If you find this article useful? Consider supporting us by Buy Me A Coffee

No comments:

Post a Comment

© 2023 CentLinux. All Rights Reserved.