How to install Mattermost on RHEL 7.1


Mattermost is an open source, private cloud Slack-alternative. A workplace messaging system for web, PCs and phones, released under the MIT license.
In a previous tutorial we talked about how to install it on Ubuntu 16.04.
Now, let’s see how to install and configure Mattermost on a RHEL 7.1 machine using MySQL as the database.

Install Database

On the server, download MySQL 5.7 executing the following command:

# wget

and install the yum repository from that file with:

# yum localinstall mysql57-community-release-el7-9.noarch.rpm

Next, install MySQL:

# yum install mysql-community-server

and start it:

# systemctl start mysqld

After executing this command for the first time, MySQL will generate a temporary password for the root account. To retrieve it, just:

# grep 'temporary password' /var/log/mysqld.log

This command will output something like this:

2017-03-02T08:21:27.969295Z 1 [Note] A temporary password is generated for root@localhost: Ed4SxpDyuH(y

Change the root password. First, login as root:

# mysql -u root -p

Enter the temporary password.
Next, in the MySQL shell:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'my_new_root_strong_password';
mysql> EXIT;

Set MySQL to start automatically at boot time:

# chkconfig mysqld on

Start the MySQL shell again:

# mysql -u root -p

Entering the new root password, create a user for Mattermost and a new database:

mysql> CREATE USER 'mmuser'@'localhost' IDENTIFIED BY 'mmuser_strong_password';
mysql> CREATE DATABASE mattermostdb;
mysql> GRANT ALL PRIVILEGES ON mattermostdb.* TO 'mmuser'@'localhost';
mysql> EXIT;

Install Mattermost Server

Download the latest release of Mattermost Server. For example only, at the time we are writing:

# wget

Extract the archive, and move the ‘mattermost’ folder to /opt

# tar xf *.gz
# mv mattermost /opt/

Create a directory for storage files:

# mkdir /opt/mattermost/data

Make sure that the drive is large enough to hold the anticipated number of uploaded files and images that will be stored on data.
Next, set up a user and group, both named ‘mattermost’, and set the ownership and permissions:

# useradd --system --user-group mattermost
# chown -R mattermost:mattermost /opt/mattermost
# chmod -R g+w /opt/mattermost

Set up the database driver through the /opt/mattermost/config/config.json file. In it, search for “DriverName” and “DataSource” lines and change as follows:

"DriverName": "mysql"
"DataSource": "mmuser:@tcp(localhost:3306)/mattermost?charset=utf8"
Save, exit, and test the Mattermost Server with the following command:
# sudo -u mattermost /opt/mattermost/bin/platform

If everything works, it should output Server is listening on :8065 . Interrupt it with CTRL+C.

Create a systemd unit.

Create a systemd file for Mattermost, /etc/systemd/system/mattermost.service and, in it, paste the following configuration:

Description=Mattermost postgresql-9.4.service



Make it executable:

# chmod 664 /etc/systemd/system/mattermost.service

And reload the services:

# systemctl daemon-reload

Enable Mattermost service:

# chkconfig mattermost on

And start it with systemd:

# systemctl start mattermost

Check if it’s running visiting the URL http://localhost:8065.

Install and configure NGINX


In a production system, use a proxy server in front of Mattermost Server. In this case, NGINX.
The main benefits of doing this are:

  • SSL termination
  • Port mapping :80 to :8065
  • HTTP to HTTPS redirect
  • Standard request logs

In order to install NGINX on RHEL 7.1, create a yum repository file, /etc/yum.repos.d/nginx.repo, with the following content:

name=nginx repo

Save, exit and install NGINX with yum:

# yum install nginx.x86_64

Start NGINX and test it:

# systemctl start nginx

In order to configure NGINX as proxy server, create the file /etc/nginx/sites-available/mattermost and past:

upstream backend {
   server localhost:8065;

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;

   location /api/v3/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;
       proxy_read_timeout 600s;
       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_pass http://backend;

Remove the existing default site-enabled file with:

# rm /etc/nginx/sites-enabled/default

and enable Mattermost:

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

Restart NGINX:

# systemctl restart nginx


At the end of this process, the server should be up and running. With a web browser go to URL and continue to configure Mattermost by entering an email address and creating an account.
That’s all! The server is ready to serve as your messaging system!

The post How to install Mattermost on RHEL 7.1 appeared first on Unixmen.

via Unixmen


About debexpert

Musician and Geek, Blogger for fun

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s