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.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Linux system Software Installation queries.
In this context, we shall look into how to install Mattermost on CentOS 8.
1. Perform System Update
First, let's start by ensuring your system is up-to-date:
$ sudo dnf clean all
$ sudo dnf install epel-release
$ sudo dnf update
2. Install 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;
3. Install Mattermost on the system
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
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
5. Configure 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
6. Configure Firewall
Allow firewall access on HTTP and HTTPS ports:
$ sudo firewall-cmd --add-service={http,https} --permanent
$ sudo firewall-cmd --reload
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.
This article covers the process of installing Mattermost on CentOS 8 system. In fact, Mattermost is an open source, self-hosted team chat and collaboration software.