Home / How To / How to install Mattermost Team Messaging System on Ubuntu 20.04

How to install Mattermost Team Messaging System on Ubuntu 20.04



Mattermost is an open source and self-hosted messaging application used for chat, file sharing, search and integrations. It is an alternative to Slack chat that provides all your team communication in one place. It is written in React and Golang and uses PostgreSQL or MySQL database in the backend. It offers a rich set of features including, Push Notifications, Unlimited Search History, Custom Emojis, Webhooks & Commands, Active Directory, Multiple Node Database Distribution Support, Forums, Discussion Board and many more.

In this tutorial we will show you how to install Mattermost with Nginx and Let’s Encrypt SSL on Ubuntu 20.04.

conditions

  • A server running Ubuntu 20.04.
  • A valid domain name pointed to your server IP.
  • A root password is configured on the server.

Getting Started

First, it is recommended that you update your system packages with the latest version. You can update them by running the following command:

apt-get update -y

After all packages have been updated, install other necessary dependencies by running the following command:

apt-get install curl wget vim git unzip gnupg2 -y

Once you have installed all the necessary packages, you can proceed to the next step.

Install and configure MariaDB

Mattermost uses MySQL / MariaDB as the database backend. So the MariaDB server needs to be installed on your server. If it is not installed, you can install it with the following command:

apt-get install mariadb-server -y

After installing the MariaDB server, log in to MariaDB with the following command:

mysql

After logging in, create a database and a user for Mattermost with the following command:

MariaDB [(none)]> CREATE DATABASE mattermostdb;
MariaDB [(none)]> CREATE USER 'mattermost'@'%' IDENTIFIED BY 'password';

Then grant all permissions to Mattermost with the following command:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON mattermostdb.* TO 'mattermost'@'%';

Then flush the privileges and leave the MariaDB shell with the following command:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Once your MariaDB database is configured, you can proceed to the next step.

Install and configure Mattermost

First you need to download the latest version of Mattermost from its official website. You can download it with the following command:

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

Once downloaded, extract the downloaded file with the following command:

tar -xvzf mattermost-5.24.2-linux-amd64.tar.gz

Then copy the extracted directory to / opt:

cp -r mattermost /opt

Then create a data directory for Mattermost:

mkdir /opt/mattermost/data

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

useradd --system --user-group mattermost

Then you change the ownership of the most important directory to the most important and give the right permissions with the following command:

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

Next, edit the default Mattermost configuration file and define your database settings and website URL.

nano /opt/mattermost/config/config.json

Change the following lines according to your needs:

    "SiteURL": "https://mattermost.linuxbuz.com",

    "DriverName": "mysql",
    "DataSource": "mattermost:[email protected](localhost:3306)/mattermostdb?charset=utf8mb4,utf8u0026readTimeout=30su0026writeTimeout=30s",

Save and close the file when you are done.

Create a Systemd service file for Mattermost

Next, you need to create a systemd service file to handle the Mattermost service. You can create it with the following command:

nano /lib/systemd/system/mattermost.service

Add the following lines:

[Unit]
Description=Mattermost
After=network.target
After=mysql.service
Requires=mysql.service

[Service]
Type=notify
User=mattermost
Group=mattermost
ExecStart=/opt/mattermost/bin/mattermost
TimeoutStartSec=3600
Restart=always
RestartSec=10
WorkingDirectory=/opt/mattermost
LimitNOFILE=49152

[Install]
WantedBy=mariadb.service

Save and close the file, then reload the system daemon with the following command:

systemctl daemon-reload

Then start the Mattermost service and enable it to start at system startup with the following command:

systemctl start mattermost
systemctl enable mattermost

Then verify the status of the Mattermost service with the following command:

systemctl status mattermost

You should get the following output:

? mattermost.service - Mattermost
     Loaded: loaded (/lib/systemd/system/mattermost.service; disabled; vendor preset: enabled)
     Active: active (running) since Sat 2020-08-01 09:12:52 UTC; 17s ago
   Main PID: 4106 (mattermost)
      Tasks: 20 (limit: 2353)
     Memory: 85.9M
     CGroup: /system.slice/mattermost.service
             ??4106 /opt/mattermost/bin/mattermost
             ??4198 plugins/com.mattermost.nps/server/dist/plugin-linux-amd64

Aug 01 09:12:52 ubuntu2004 mattermost[4106]: {"level":"info","ts":1596273172.131499,"caller":"mlog/sugar.go:19","msg":"Sent notification of ne>
Aug 01 09:12:52 ubuntu2004 mattermost[4106]: {"level":"info","ts":1596273172.1841655,"caller":"jobs/workers.go:73","msg":"Starting workers"}
Aug 01 09:12:52 ubuntu2004 mattermost[4106]: {"level":"info","ts":1596273172.1842792,"caller":"bleveengine/bleve.go:267","msg":"UpdateConf Ble>
Aug 01 09:12:52 ubuntu2004 mattermost[4106]: {"level":"info","ts":1596273172.1930475,"caller":"jobs/schedulers.go:74","msg":"Starting schedule>
Aug 01 09:12:52 ubuntu2004 mattermost[4106]: {"level":"info","ts":1596273172.20063,"caller":"app/web_hub.go:83","msg":"Starting websocket hubs>
Aug 01 09:12:52 ubuntu2004 mattermost[4106]: {"level":"info","ts":1596273172.2099638,"caller":"app/license.go:37","msg":"License key from http>
Aug 01 09:12:52 ubuntu2004 mattermost[4106]: {"level":"info","ts":1596273172.2205582,"caller":"app/server.go:525","msg":"Starting Server..."}
Aug 01 09:12:52 ubuntu2004 mattermost[4106]: {"level":"info","ts":1596273172.2208374,"caller":"app/server.go:594","msg":"Server is listening o>
Aug 01 09:12:52 ubuntu2004 mattermost[4106]: {"level":"info","ts":1596273172.2211802,"caller":"commands/server.go:106","msg":"Sending systemd >
Aug 01 09:12:52 ubuntu2004 systemd[1]: Started Mattermost.

Right now, Mattermost is driving and listening on port 8065.

Configure Nginx as a reverse proxy

Next, you need to configure Nginxx as a reverse proxy for Mattermost. First, install the Nginx package with the following command:

apt-get install nginx -y

After installing, create a Nginx virtual host configuration file with the following command:

nano /etc/nginx/sites-available/mattermost.conf

Add the following lines:

upstream mattermost {
   server localhost: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.linuxbuz.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://mattermost;
   }

   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://mattermost;
   }
}

Save and close the file, then enable the virtual host configuration using the following command:

ln -s /etc/nginx/sites-available/mattermost.conf /etc/nginx/sites-enabled/mattermost.conf

Then verify Nginx for configuration errors:

nginx -t

You should get the following output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Finally, restart the Nginx service to apply the changes:

systemctl restart nginx

Secure Mattermost with Let’s Encrypt SSL

First, you need to install the Certbot client in your system to handle Let’s Encrypt SSL. You can install it with the following command:

apt-get install python3-certbot-nginx -y

After installing Certbot, run the following command to install Let’s Encrypt SSL for your Web site.

certbot --nginx -d mattermost.linuxbuz.com

You will be asked to enter a valid email address and accept the service shown below:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for mattermost.linuxbuz.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/mattermost.conf

Then select whether to redirect HTTP traffic to HTTPS:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Type 2 and press Enter to install Let’s Encrypt SSL on your domain. After installing, you should see the following output:

Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/mattermost.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://mattermost.linuxbuz.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=mattermost.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/mattermost.linuxbuz.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/mattermost.linuxbuz.com/privkey.pem
   Your cert will expire on 2020-10-30. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

Access Mattermost web interface

Now open your browser and enter the URL https://mattermost.linuxbuz.com. You will be redirected to the Mattermost registration screen:

Matter Most-Login

Enter your email address, name, password and click Create Account button. The following screen is displayed:

Mattermost Team Communication

click Create one team button. The following screen is displayed:

Team name

Enter your team name and click Next button. The following screen is displayed:

Team URL

Enter your URL and click End button. You should see the Mattermost welcome screen:

Matter Most dashboard

click Jump Tutorials button. You should see the Mattermost Dashboard on the following screen:

Matter Most Chat

Conclusion

In this guide you will learn how to install Mattermost Team Messaging application on Ubuntu 20.04 server. You’ve also learned how to configure Nginx as a reverse proxy and secure it with Let’s Encrypt SSL. You can now explore Mattermost services and work with your team.


Source link