How to install Mattermost on RHEL 7.1

Mattermost

Introduction

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 http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

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 [email protected]: 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> FLUSH PRIVILEGES;
mysql> EXIT;

Install Mattermost Server

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

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

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:

[Unit]
Description=Mattermost
After=syslog.target network.target postgresql-9.4.service

[Service]
Type=simple
WorkingDirectory=/opt/mattermost/bin
User=mattermost
ExecStart=/opt/mattermost/bin/platform
PIDFile=/var/spool/mattermost/pid/master.pid
LimitNOFILE=49152

[Install]
WantedBy=multi-user.target

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

Installation

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:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/rhel/7.1/$basearch/
gpgcheck=0
enabled=1

Save, exit and install NGINX with yum:

# yum install nginx.x86_64

Start NGINX and test it:

# systemctl start nginx
Configuration

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;
   server_name    mattermost.mydomain.com;

   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

Conclusions

At the end of this process, the server should be up and running. With a web browser go to URL http://mattermost.mydomain.com 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!

  • I’ve made 104000 dollars previous year by freelancing on-line a­­n­­d I was able to do it by w­o­r­k­i­n­g in my own time f­­o­­r several hours each day. I used work opportunity I stumbled upon online and I am excited that i made so much money on the side. It’s very user-friendly and I’m so thankful that i discovered it. This is what i did… http://www.wzurl­.­me/tEXzrw

  • bell_raymond

    I profited 104 thousand dollars in 2016 by working online from home and I manage to do it by working part-time f­o­r 3+ h each day. I used an earning model I came across from company that i found online and I am thrilled that i was able to make so much extra income. It’s very user-friendly and I’m just so happy that i discovered it. Check out what I did… http://urlof­.­site/gK5Tu

  • [email protected]

    I was paid 104000 dollars past year by doing an internet task and consequently I was able to do it by w­orking in my own time f­o­r quite a few hours each day. I tried work opportunity I stumbled upon on the internet and also I am excited that I was in the position to make such good money. It’s undoubtedly newbie-friendly and therefore I’m so blessed that I found out about it. Read through what I do… I was without work for six months when my early Co-worker lastly strongly recommended me to begin freelancing online… It was actually after I gained $5000 in my first thirty days when I actually believed I could do this for a living! At the moment I am happier than ever… I work-from-home moreover I am my own boss now that I always wanted… I see several unhappy people around me, working the same old boring job that is sucking the everyday life from them day-after-day… Whenever I see some-one like that I say START FREELANCING MAN! This is where I started off >>>> www­.­cat­.­org­.­uk/snip/78276

  • [email protected]

    I was paid 104000 bucks past 12 months by doing a web based job furthermore I was able to do it by w­orking in my own time f­o­r quite a few hours everyday. I utilized work opportunity I found out on the web and I am thrilled that I was manage to make such decent money. It’s really newbie-friendly and I’m so delighted that I found out regarding it. Look into what I do… www­.­cat­.­org­.­uk/snip/93439

  • lawrence_lee

    I was paid 104000 bucks past 12 months by doing an online task and I was able to do it by w­orking in my own time f­o­r quite a few hours every day. I used job opportunity I stumbled upon on the internet and also I am excited that I was manage to make such decent money. It is undoubtedly newbie-friendly and I’m so delighted that I found out regarding it. Go and visit what I do… http://polr­.­me/1g1h