Setting up Mattermost on Ubuntu 18.04

nhadiq97

NAEEM HADIQ

Posted on April 24, 2020

Setting up Mattermost on Ubuntu 18.04

Source: mattermost.com

In the present scenario of Lockdowns and work from home, Companies are investing heavily in online tools. But let's look at the opensource Toolkits that can aid in working from home maybe even better than the paid counterparts.

Mattermost-Open Source Slack Alternative

As we all know Slack being the new best choice for startups and enterprises alike for in company and in team communications. Mattermost is an opensource equivalent with a lesser attractive UI but the same functionalities.

Lets Set up a Mattemost self-hosted Server

This can either be done on the cloud(such as AWS)or on-premise. The hardware requirements are so low that an EC2 t2.micro can handle around 100 users. If on cloud configure port 80,443 to accept all inbound requests and 22 for your configuration SSH.

Step 1- Upgrade and Update the system

sudo apt update
sudo apt -y upgrade
sudo apt -y install wget curl vim
Enter fullscreen mode Exit fullscreen mode

It is recommended to reboot after an upgrade

sudo reboot
Enter fullscreen mode Exit fullscreen mode

The Next Step is to set a proper Domain name configured

sudo hostnamectl set-hostname chat.example.com --static
Enter fullscreen mode Exit fullscreen mode

Step 2- install the DB

Mattermost supports SQL and Postgress. For the Purpose of the tutorial, let's go ahead with Postgres for reliability and scale.

sudo apt -y install postgresql postgresql-contrib
Enter fullscreen mode Exit fullscreen mode

Since Postgres automatically starts up after an install.Login with Postgres account

sudo --login --user postgres
Enter fullscreen mode Exit fullscreen mode

Start the PostgreSQL interactive terminal and create the Mattermost database/user ‘ mmuser ’ grant necessary rights and exit Postgres account.

psql
CREATE DATABASE mattermost;
CREATE USER mmuser WITH PASSWORD 'StrongDBPassWord';
GRANT ALL PRIVILEGES ON DATABASE mattermost to mmuser;
\q
exit
Enter fullscreen mode Exit fullscreen mode

Step 3: Create Mattermost user and group

sudo useradd --system --user-group mattermost
Enter fullscreen mode Exit fullscreen mode

This creates a system user .

Step 4: Download and install Mattermost

With the database server configured, you can now download and install Mattermost. First, visit the Mattermost downloads page to get the latest release.

Assuming the Latest release is 5.22.1

wget [https://releases.mattermost.com/5.22.1/mattermost-5.22.1-linux-amd64.tar.gz](https://releases.mattermost.com/5.22.1/mattermost-5.22.1-linux-amd64.tar.gz)
Enter fullscreen mode Exit fullscreen mode

if the Version changes replace x.x.x with the corresponding version and use the link

wget [https://releases.mattermost.com/x.x.x/mattermost-x.x.x-linux-amd64.tar.gz](https://releases.mattermost.com/5.22.1/mattermost-5.22.1-linux-amd64.tar.gz)
Enter fullscreen mode Exit fullscreen mode

Now extract the downloaded package

tar xvf mattermost-5.22.1-linux-amd64.tar.gz
Enter fullscreen mode Exit fullscreen mode

Move the extracted file to the /opt directory.

sudo mv mattermost /opt
Enter fullscreen mode Exit fullscreen mode

Next step is to create a directory to store user files

sudo mkdir /opt/mattermost/data
Enter fullscreen mode Exit fullscreen mode

Set correct ownership and permissions

sudo chown -R mattermost:mattermost /opt/mattermost
sudo chmod -R g+w /opt/mattermost
Enter fullscreen mode Exit fullscreen mode

Step 5: Configuring the Mattermost server

The config file of Mattermost server is accessible at /opt/mattermost/config/config.json

sudo nano /opt/mattermost/config/config.json
Enter fullscreen mode Exit fullscreen mode

Configure PostgreSQL database settings to look like below under “ SqlSettings “: section.

"DriverName": "postgres",
"DataSource": "postgres://mmuser:StrongDBPassWord@localhost:5432/mattermost?sslmode=disable&connect\_timeout=10",
Enter fullscreen mode Exit fullscreen mode

“Service Settings”: “” Section Alter the corresponding values This assumes that you are going to use LetsEncrypt for SSL

"SiteURL": "chat.example.com"
Enter fullscreen mode Exit fullscreen mode

Listen port

"ListenAddress":":443"
"ConnectionSecurity":"TLS"
"UseLetsEncrypt":true
"Forward80To443":true
Enter fullscreen mode Exit fullscreen mode

Security

"ConnectionSecurity":"TLS"
Enter fullscreen mode Exit fullscreen mode

enabling Lets Encrypt alternate to enable this you can use your self signed certificate by entering appropriate data in fields

"UseLetsEncrypt":true
Enter fullscreen mode Exit fullscreen mode

HTTP to Https redirect

"Forward80To443":true
Enter fullscreen mode Exit fullscreen mode

Enabling Mattermost to bind to lower ports

sudo setcap cap\_net\_bind\_service=+ep /opt/mattermost/bin/platform
Enter fullscreen mode Exit fullscreen mode

Step 6: Configure Systemd Service

Create Mattermost Systemd service unit.

$ sudo vim /etc/systemd/system/mattermost.service
Enter fullscreen mode Exit fullscreen mode

Populate the below data into the file.

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

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

[Install]
WantedBy=multi-user.target
Enter fullscreen mode Exit fullscreen mode

Make systemd load the new unit.

sudo systemctl daemon-reload
Enter fullscreen mode Exit fullscreen mode

Start and Enable Mattermost Service

sudo systemctl start mattermost.service
sudo systemctl enable mattermost.service
Enter fullscreen mode Exit fullscreen mode

Check service status to make sure it is running.

systemctl status mattermost.service
Enter fullscreen mode Exit fullscreen mode

Verify that Mattermost is running by calling the link on a browser assuming that you have already pointed the DNS.

[https://chat.example.com](http://chat.example.com)
Enter fullscreen mode Exit fullscreen mode

would return an HTML returned by the server.

Step 7: Finish Mattermost Web configuration

Signup page

Note that the initial signup user would be the default system admin

Access System Console by clicking the go-to system console

Further configurations can be done reading through the Config Document .

You are all set to start utilizing the self-hosted Mattermost server.


💖 💪 🙅 🚩
nhadiq97
NAEEM HADIQ

Posted on April 24, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related