Installing Mattermost server on RaspberryPI4

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.

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&gt;: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.


Send email from RaspberryPi (with exim4)

Getting A Message Transfer Agent

Before your Pi can send emails it needs a message transfer agent (MTA). I have two flavours for you. The first one is exim4, the other one is SSMTP. The choice is yours. Needless to say, you will only need one of the two MTAs.
Thanks to the Debian packaging system this is easily done by typing one of the following commands.

Exim4

sudo apt-get install exim4

After installing exim4 we need to configure it. This is done by the following command:

sudo dpkg-reconfigure exim4-config

Now you need to answer some questions. Don’t worry I’ll give you the answers to those questions.

  • The first screen asks you what type of mail server you need. Select the second option: “mail sent by smarthost; received via SMTP or fetchmail”
  • The next question asks for the system mail name: Set to same as hostname (raspberrypi)
  • Now it asks you what IP addresses should be allowed to use the server. Leave as is (127.0.0.1 ; ::1)
  • Other destinations for which mail is accepted: raspberrypi
  • Machines to relay mail for: Leave blank.
  • IP address or host name of outgoing smarthost: Replace by: smtp.gmail.com::587
  • Hide local mail name in outgoing mail: Select: No
  • Keep number of DNS-queries minimal: Select: No
  • Delivery method for local mail: Select: “Maildir format in home directory”
  • Split configuration into small files: Select: No
  • Root and postmaster mail recipient: Enter: pi

After answering all these questions exim4 will restart and we’re halfway home.

Now you’ll have to enter your account details. As root, edit the file /etc/exim4/passwd.client and add the next three lines at the end of the file.

gmail-smtp.l.google.com:[email protected]:PASSWORD
*.google.com:[email protected]:PASSWORD
smtp.gmail.com:[email protected]:PASSWORD

Needless to say that you’ll have to change YOU to your Gmail login name, and PASSWORD to your password on all three lines. After that you only have to update and restart exim4 and you’re done! The next two lines will do that for you:

sudo update-exim4.conf
sudo service exim4 restart

SSMTP

sudo apt-get install ssmtp mailutils mpack

Now edit the file /etc/ssmtp/ssmtp.conf as root and add the next lines. Please note that some of the lines already exist and may need to be changed. Others don’t exist yet and need to be added to the end of the file.

mailhub=smtp.gmail.com:587
hostname=ENTER YOUR RPI'S HOST NAME HERE
[email protected]
AuthPass=PASSWORD
useSTARTTLS=YES

Again you’ll have to replace YOU with your gmail login name and PASSWORDwith your (application specific) gmail password.
After this you’re done. You don’t even have to restart the SSMTP server (in fact, there is none).

The Final Touches

Some processes, for instance crontabs, can send mails to root or other system users. If you don’t want to miss any of them you can setup some aliases. You can do that by editing the file /etc/aliases. Here’s what mine looks like:

# /etc/aliases
mailer-daemon: postmaster
postmaster: root
nobody: root
hostmaster: root
usenet: root
news: root
webmaster: root
www: root
ftp: root
abuse: root
noc: root
security: root
root: pi
pi: [email protected]

It may be necessary to run the next command to make the changes in aliases active:

sudo newaliases

This tells the system to redirect all mail to root, while mail to root is redirected to the user pi, while mail to user pi is finally redirected to my own mail account. This way all system mail will eventually be sent to my own mail account, no matter to what local user the mail was originally sent.

If you are like me, you will probably have more than one Raspberry Pi mailing you some status information. And unless you use different mail accounts for all your RPis it becomes harder and harder to find out which one is mailing you. The next command will setup a new full name (pi @ domotics) for the user name pi, with which you can idintify the source of the e-mail.

sudo chfn -f "pi @ domotics" pi

PS: The aliases don’t appear to work with the SSMTP setup. Nothing I tried seemed to work. Although SSMTP is easier to setup, I recommend you to use the Exim4 approach to get a more complete mail experience.
But if it is simplicity you’re after, feel free to use SSMTP.

A Better Mail User Agent

By default the program bsd-mailx is installed on the Raspberry Pi as the mail user agent. Every time you invoke the mail command, bsd-mailx is executed. There’s one thing that I don’t like about this program and that it won’t allow you to send attachments with your mails.
So let’s remove that program and install a better alternative:

sudo apt-get install heirloom-mailx
sudo rm /etc/alternatives/mail
sudo ln -s /usr/bin/heirloom-mailx /etc/alternatives/mail

After that you can simply do something like mail -a attachment.file -s “Subject line” [email protected] to send an email with a file attached to it.

Testing

To test your outgoing mail simply execute the next command:

mail -s "This is the subject line" root@localhost

Then type the body of the message, this is only a test so anything will do. When you’re done typing the body type a dot (.) at the beginning of a new line and hit Enter. The mail should now be sent to root, which is redirected to pi, which is redirected to your normal email address.
You can also send a mail directly to your own email address if you want to, however that would be skipping testing the redirections.

Below you see two other ways of sending mail from your RPi. Both methods will send the file body.txt as message body.

mail -s "This is the subject line" [email protected] < body.txt
cat body.txt | mail -s "This is the subject line" [email protected]

Copied from https://raspinotes.wordpress.com/2019/03/10/send-email-from-raspberrypi-with-exim4/

Personal note.

cj915ai's avatarraspinotes

Followed directions here:

https://www.sbprojects.net/projects/raspberrypi/exim4.php

Getting A Message Transfer Agent

Before your Pi can send emails it needs a message transfer agent (MTA). I have two flavours for you. The first one is exim4, the other one is SSMTP. The choice is yours. Needless to say, you will only need one of the two MTAs.
Thanks to the Debian packaging system this is easily done by typing one of the following commands.

Exim4

sudo apt-get install exim4

After installing exim4 we need to configure it. This is done by the following command:

sudo dpkg-reconfigure exim4-config

Now you need to answer some questions. Don’t worry I’ll give you the answers to those questions.

  • The first screen asks you what type of mail server you need. Select the second option: “mail sent by smarthost; received via SMTP or fetchmail”
  • The next question asks for the system mail name: Set to same as hostname…

View original post 798 more words

Design a site like this with WordPress.com
Get started