How I installed Mattermost Server on my raspberry pi. I have followed the guide at https://github.com/justinegeffen/mattermost_raspberrypi_recipe with some slight modifications.
Getting Started.
The first thing that needs to be done is to install Raspberry pi OS to a SD card. I wrote the raspberry pi OS image at https://www.raspberrypi.org/software/operating-systems/#raspberry-pi-os-32-bit to a 64 bit micro SD card using rufus (http://rufus.ie/) from my Windows laptop.
After installing raspberry pi OS, sign in using the user pi with the password raspberry. You will then want to run sudo raspi-config and enable ssh for remote access, as well as setting up the hostname. You will also want to set the localization options as well. Get your IP by running ip address and looking for the numbers next to inet under your network interface name (eth0 for Ethernet, or wlan0 for Wi-Fi).
Next you will want to create a new user for you to use as sticking with the pi user, especially when keeping the same password, can be a security risk. Create a new user using sudo useradd --create-home -G sudo <new username> and set the password using sudo passwd <new username>, replacing <new username> with the name of the user you would like to create. You can now SSH into your pi with the user you just created using openssh (linux or mac), or PuTTY (Windows or ReactOS). Verify you have sudo privileges on your new account by running sudo whoami. If you see root in the output after putting in your password, sudo has run sucessfully. If you see an error, either check your password, or if that doesn’t work, run sudo usermod -a -G sudo <your username> to make sure you are in the sudo group. You can also check this by running groups and checking for sudo in the output.
After making sure that sudo works on your new account, disable the pi user by running sudo passwd -l pi. If you are still worried about someone getting into the pi account, add exit to the beginning of the .bashrc file for pi by running sudo -e /home/pi/.bashrc and adding exit to the beginning.
Set up MariaDB
MariaDB is the sql server that we will use with Mattermost. Before we install it, we want to make sure that everything is up to date. Do so by running sudo apt update && sudo apt upgrade. Install MariaDB by running sudo apt install mariadb-server. Set it up by running sudo mysql_secure_installation. Make sure to set the root password. I recoment putting the root password in a password manager such as keepass.
Log into the server by running sudo mysql -u root -p using the root password you set. Create a use for mattermost by running create user 'mmuser'@'%' identified by 'mmuser-password'; changing mmuser-password with the password you want to set for the account. Again I recoment putting the password in a password manager. Create a database for mattermost by running create database mattermost;, and give the mmuser all permissions on the database by running grant all privileges on mattermost.* to 'mmuser'@'%';. While not required, I run flush privileges; afterwards to make sure the privileges get saved. Type exit to leave mysql.
Install Mattermost Server
Now we can install the server. First, create a folder to install mattermost to. sudo mkdir -p /opt/mattermost creates a folder in /opt to install it to. change to that directory using cd. Go to https://github.com/SmartHoneybee/ubiquitous-memory/releases to get the latest build link by right clicking on the arm build and clicking the get link address option (I use Microsoft Edge (not legacy), it may be different in your browser. Download that file by pasting the url behind the wget command. As of writing, the command is wget https://github.com/SmartHoneybee/ubiquitous-memory/releases/download/v5.32.1/mattermost-v5.32.1-linux-arm.tar.gz. Extract the file using tar. In my case, the command is sudo tar -xvf mattermost-v5.32.1-linux-arm.tar.gz As I like to organize my version, I will rename the extracted folder to the version name. mv mattermost mattermost-v5.32.1.
Next we need to create a user for Mattermost to run under as running as root is just a bad idea. Create a system user named mattermost by running sudo useradd --system --user-group --no-create-home mattermost and give it ownership of the mattermost install directory by running sudo chown -R mattermost:mattermost /opt/mattermost/. Edit the config for Mattermost to use your database by running sudo -u mattermost nano /opt/mattermost/mattermost-v5.32.1/config/config.json, being sure to modify the path as necessary. Go down to the SQL settings and set the driver to mysql and set DataSource to mmuser:mmuser-password@tcp(localhost:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s. Exit nano using ctrl+x and press y to save and exit.
To verify that mattermost was installed and configured correctly, run sudo -u mattermost /opt/mattermost/mattermost-v5.32.1/bin/mattermost changing the path as necessary. After a minute, you should see {"level":"info","ts":1615833887.84892,"caller":"app/server.go:1027","msg":"Server is listening on [::]:8065","address":"[::]:8065"} at the end of the output. If you don’t, verify that the SQL settings set up correctly. If you see an exec error, verify that you got the arm build, and not the arm64 build.
After sucessfully setting up Mattermost, open up your browser and go to http://<yourip>:8065/ to set up your account.
Starting Mattermost on Boot
You will likely want to have Mattermost running as a service that start when you power on your pi. To do so, we will use Systemd.
Systemd is the init system used on most Linux distros, and it is used by Raspberry Pi OS to create system services and start processes on boot. To create a service, create and open a new service file by running sudo -e /lib/systemd/system/mattermost.service and set it to the following, changing the paths as necessary.
[Unit]
Description=Mattermost
After=network.target
After=mysql.service
Requires=mariadb.service
[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
Now we need to enable the service. Tell Systemd to (re)load the service file (sudo systemctl daemon-reload) and enable the config sudo systemctl enable mattermost.service). Either restart the pi or run sudo systemctl start mattermost.service to start the service.
