Mattermost Raspberry Pi Recipe

Problem

I want to install Mattermost on my Raspberry Pi for use on my network.

Solution

The Raspberry Pi architecture is not officially supported by Mattermost, but there is an excellent resource available with steps and helpful links Mattermost on Raspberry Pi, which further linked me to a really great repo with the latest install files provided by SmartHoneyBee.

The builds are updated regularly, so the most recent version of Mattermost (5.21) is available. There are installers for quite a few flavors of Linux. The version I used was Linux-arm-tar.gz as I'm running Raspbian 9 (stretch) on my Raspberry Pi 3 Model B which has an ARM Cortex-A53 processor. You can check this by running uname --kernel-name --kernel-release --machine. If your Pi is out the box, the results should be something like Linux 4.14.34-v7+ arm71. If you've installed a different flavor of Linux, it'll be different so choose the appropriate install file.

Setting up MySQL

Before you install Mattermost, you need to set up MySQL. The full instructions are on the Installing Mattermost on Debian Stretch page and cover PostgreSQL and MySQL. I use MySQL, so these are the steps I followed:

  1. Log into the server that will host the database, and open a terminal window.

  2. Download the MySQL repository package

wget https://dev.mysql.com/get/mysql-apt-config_0.8.6-1_all.deb
  1. Install the repository
sudo dpkg -i mysql-apt-config*
  1. Update your local package list
sudo apt-get update
  1. Add the MySQL repo MySQL. During the install, you’ll be prompted to create a password for the MySQL root user. Make a note of the password because you’ll need it in the next step.
sudo apt-get install mysql-server
  1. Log in to MySQL as root, using the root password that you created when installing MySQL.
sudo mysql -u root -p
  1. Create the Mattermost user 'mmuser', replacing 'mmuser-password' in the command below with the password you plan to use.
mysql> create user 'mmuser'@'%' identified by 'mmuser-password';

The ‘%’ means that 'mmuser' can connect from any machine on the network. However, it’s more secure to use the IP address of the machine that hosts Mattermost. For example, if you install Mattermost on the machine with IP address 10.10.10.2, then use bash mysql> create user 'mmuser'@'10.10.10.2' identified by 'mmuser-password';

  1. Create the Mattermost database
mysql> create database mattermost;
  1. Grant access privileges to the user 'mmuser'
mysql> grant all privileges on mattermost.* to 'mmuser'@'%';
  1. Log out of MySQL
mysql> exit

During this process I encountered an issue where I wasn’t prompted to choose a MySQL root password so I couldn’t log in as root. While you may not encounter that, I found some handy steps at How to set, change, and recover a MySQL root password.

Install Mattermost Server

  1. Download the appropriate install file
wget https://github.com/SmartHoneybee/ubiquitous-memory/releases/download/v5.12.3/mattermost-v5.12.3-linux-arm.tar.gz
  1. Extract the Mattermost Server files from the .tar.gz file
tar -xvzf mattermost*.gz
  1. Move the extracted file to the /opt directory
sudo mv mattermost /opt
  1. Create the storage directory for files
sudo mkdir /opt/mattermost/data

The storage directory will contain all the files and images that your users post to Mattermost, so you need to make sure that the drive is large enough to hold the anticipated number of uploaded files and images.

Set up a system user and group called "mattermost" that will run this service, and set the ownership and permissions.

  1. Create the Mattermost user and group
sudo useradd --system --user-group mattermost
  1. Set the user and group mattermost as the owner of the Mattermost files
sudo chown -R mattermost:mattermost /opt/mattermost
  1. Give write permissions to the mattermost group
sudo chmod -R g+w /opt/mattermost
  1. Set up the database driver in the file /opt/mattermost/config/config.json. Open the file in a text editor and make the following changes:
    1. Set DriverName to mysql
    2. Set DataSource to the following value, replacing and with the appropriate values.
mmuser:mmuser-password@tcp(localhost:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s

Start the Mattermost Server

  1. Change to the bin directory
cd /opt/mattermost
  1. Start the Mattermost server as the user mattermost
sudo -u mattermost ./bin/mattermost
  1. To test that you can access the server, navigate to http://<your-IP-address>:8065

When the server starts the output log generates information, including the current version of Mattermost and the listening port (8065). You can stop the server by pressing CTRL+C on your keyboard.

Set up Mattermost to Use systemd for Starting and Stopping.

If you want your Mattermost server to start up automatically on boot, you can create a systemd file to install it as a service.

  1. Create a systemd unit file
sudo touch /lib/systemd/system/mattermost.service
  1. Open the unit file as root in a text editor, and copy the following lines into the file:
[Unit]
Description=Mattermost
After=network.target
After=mysql.service
Requires=mysql.service

Note: If you are using PostgreSQL, replace mysql.service with postgresql.service. If you have installed MySQL or PostgreSQL on a dedicated server then you need to remove the After=postgresql.service and Requires=postgresql.service or After=mysql.service and Requires=mysql.service lines in the [Unit] section or the Mattermost service will not start.

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

[Install]
WantedBy=multi-user.target
  1. Make systemd load the new unit
sudo systemctl daemon-reload
  1. Check to make sure that the unit was loaded
sudo systemctl status mattermost.service

You should see an output similar to the following:

mattermost.service - Mattermost
Loaded: loaded (/lib/systemd/system/mattermost.service; disabled; vendor preset: enabled)
Active: inactive (dead)
  1. Start the service
sudo systemctl start mattermost.service
  1. Verify that Mattermost is running
curl http://localhost:8065

You should see the HTML that’s returned by the Mattermost server. In my case it was a message referring to a connection error, which was a bit confusing. So I re-checked the service status by running

sudo systemctl status mattermost.service

and confirmed that the service was active.

  1. Finally, set Mattermost to start on boot
sudo systemctl enable mattermost.service

The output should indicate that a symlink has been successfully created.

Inviting Team Members

The last step in the process is to make the Mattermost server available to team members so they can join the server. To do this, log into the server using http://<your-IP-address>:<port> and follow the configuration steps. Once complete, open the main menu, select Get Team Invite Link, copy the link, and send it out.

Discussion

If I wanted to deploy multiple Mattermost Pi appliances, I’d need to repeat this process step-by-step multiple times. One solution to this is to use a Docker image. For this recipe I didn’t use a Docker image as Docker is far more resource-intensive to use and on a Pi you generally want to run something as light as possible. A second reason is that creating a Docker image requires Docker knowledge and that learning curve is a bit steeper than simply following the steps provided. However, it is a better solution should you wish to deploy Mattermost across multiple Pis.

This setup was done on my local network, which meant that my users couldn't join the server when they were off my network. To let users join externally I forwarded port 8065 to my Pi in my router settings and provided them with my DNS host name instead of the IP address.