Open Source Chat Server: A Slack Alternative
It’s been around for a while now, but I only recently discovered an open source chat program called Mattermost. I just got it up and running on a test server, and thought I’d share anything I learned in the process.
January 29, 2020
As a daily Slack user, and a victim of their late 2019 Let’s Make Everybody Use a WYSIWYG Chat Box ruckus, I started wondering what else was out there. There’s an open source alternative to almost everything, so there must be an open source chat server, I figured. I was already hunting for “something chatty” in a different situation: Hangouts is set to die, so I needed a replacement my family and close friends could use. While I found one for that situation, and wrote about the process over in Open Source Messaging App: What’s Available?, I was still looking for a team kind of app.
I found Mattermost. It looked like an open source chat server and more, something that can compete with Slack. My curiosity piqued, I had to give it a try. Now that I have, I’d like to share some about how I got it up and running. Walk with me, if you will, on an install process…
Installing This Open Source Chat Server
We’re installing this on a bare-bones Ubuntu 18.04 server, and running it on a MySQL backend. There are many other possible distributions, and the ability to run it on PostgreSQL. But this was the easiest way for me to just take it out of the box and play with it, so that’s the direction I’ve decided on.
A lot of what follows is up on the official Mattermost site, but I’ll put the commands here too, with any notes or comments I have along the way. It’s now about seven hours after I started. I was trying to write this blog post as I went, stopped to take some guitar pictures for a coworker, talked to my wife and kids for a bit, etc. I’m thinking it’s probably a couple hours at the most to get from a bare Linux distribution to an up and running open source chat server. Oh, I also hosed the server I was working on several times, so I could repeat the process and make sure I had all the commands down right.
Note: I went through it one more time, in the interests of science, and was up and running in less than an hour.
Preparing the Server
Mattermost suggests running a slew of sudo
commands. I just ran a sudo -i
right off so I could have root
privileges for the whole process. There are arguments for and against this method. Just remember that as you’re going through this. If you’re going to stay logged in as the regular user you started off with, you’ll have to preface them all with sudo
too.
Let’s get our server up to date first, before we even start installing anything:
# apt update ... ... # apt upgrade ...
Answer y to the prompt about whether you want to install/update this stuff.
Install MySQL
To get MySQL installed and running, execute this:
# apt install mysql-server
Secure MySQL
We don’t want the default “sort of insecure” MySQL installation here, so let’s tighten it up. We’ll set password complexity requirements, set a root
password, remove anonymous users, and keep root
from logging in remotely. We’ll also get rid of the test
database, remove any privileges for that database, and then finally reload the privileges
table. This one command will do all that, prompting us for things as we go:
# mysql_secure_installation
Create a Database for the Open Source Chat Server
I had a little trouble doing things exactly the way that the Mattermost said to do them, so I veered off a bit here. I probably missed something in their docs…
Before I set up a user, I set up the database. The Mattermost install needs a database set up for it anyway, so let’s do that now:
# mysql -p mysql> create database mattermost;
Set up a User
Here is where we can set up the user and grant it privileges to the mattermost
database:
mysql> create user 'mmuser'@'%' identified by 'blahblahpassword'; mysql> grant all privileges on mattermost.* to 'mmuser'@'%';
blahblahpassword is not a good idea, for the record. We should pick a good one. What we can create (length, complexity, etc.) depends on our responses to one of the questions when we ran the mysql_secure_installation
command.
We can get out of MySQL:
mysql> exit
One Last MySQL Tweak
We’ve to edit a line in our MySQL configuration file. Change /etc/mysql/mysql.conf.d/mysqld.cnf
(we can use whatever text editor suits our fancy) and comment out the bind-address
line, so that it looks like this:
... # Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. # bind-address = 127.0.0.1 # # * Fine Tuning ...
Now we can restart MySQL to pick up the configuration change:
# systemctl restart mysql.service
Getting Mattermost, the Actual Open Source Chat Server Software
Look on the Mattermost download page first to get the URL of the package we want, then run something like this:
wget https://releases.mattermost.com/5.19.1/mattermost-5.19.1-linux-amd64.tar.gz
That will pull it down to the server we’re installing it on. Just be sure to change the version number.
Once we’ve got the file downloaded, extract its contents:
# tar -xvzf mattermost*.gz
Then we’ve got to move it to where we want it running from (/opt
), and create a storage directory for files:
# mv mattermost /opt/ # mkdir /opt/mattermost/data
Create and Configure a User and Group for Running Mattermost
The Mattermost application should be run and owned by a special user and group. Let’s set them both up, and give them ownership of the mattermost
directory:
# useradd --system --user-group mattermost # chown -R mattermost:mattermost /opt/mattermost # chmod -R g+w /opt/mattermost
Connect to the Database
We’re using MySQL, so let’s open up /opt/mattermost/config/config.json
in a text editor then set a few things.
- The DriverName needs to be mysql.
- In DataSource, we’ll set the password, hostname or IP, and make sure the database name is set correctly. When we’re done, the line should read something like this:
"DataSource": "mmuser:password@tcp(localhost:3306)/mattermost?charset=utf8mb4...
The /mattermost?
will probably say /mattermost_test?
, so beware.
One last thing… Up in line 3 of that same file, we need to set the SiteURL variable. For just setting up a quick test on a bare-bones server, the IP address is fine. For something just sitting on our LAN, the private IP is fine. If the server is out in the wild though, and we want remote folks connecting in, we’ll need the server’s public IP there: http://x.x.x.x will get it done, just swap out the x.x.x.x for our actual IP or name.
Fire in the Hole! Light This Open Source Chat Server Up!
Let’s give this thing a whirl, shall we? For now, we’ll just launch it in the terminal, to see if it’s working:
# sudo -u mattermost /opt/mattermost/bin/mattermost
Now we should be able to visit https://x.x.x.x:8065, and we’ll be greeted with a “Sign up as a new user” form. Once we’re in, we have the run of the mill, as the admin user.
Make It Persistent
Congratulations on getting it running, but notice we’ve still got a terminal window open full of all sorts of messages. If you got excited and started sending invites out, there is probably a plethora of information flying by right now. But once we close that terminal, poof! The server does down. We need to make Mattermost a daemon that we can start and stop (like we can do with MySQL) with systemctl
commands.
In that terminal, hit Ctrl+c to kill the service, and let’s go make a systemd unit file. Touch an empty one first:
# touch /lib/systemd/system/mattermost.service
Now we can edit it, adding these contents:
[Unit] Description=Mattermost After=network.target After=mysql.service Requires=mysql.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=mysql.service
Once that’s done, we can reload systemctl
, and then start it:
# systemctl start mattermost.service
Check to see if it’s running:
# systemctl status mattermost.service
We should be good to go at this point. But let’s take a look at some issues I ran into.
Personal Notes
Here are some things that tripped me up, and thoughts I had along the way…
Forgotten Passwords
I set this up on an AWS instance that I whipped up just for this. That meant I had to set all sorts of passwords (root
in MySQL, the regular user that I logged in as to begin with, the mmuser
in MySQL, my actual Mattermost user, another test user so I could play with the Android app, etc.) and I forgot some. It’s my fault, I should have written them down. Usually it’s people’s names I have a hard time with, not passwords, so I thought I was all set.
I learned real quick that I could (in the terminal as root
) become the mattermost
user and reset at least the Mattermost passwords. This will do it, just substitute username
and newpass
with the user whose password you’re resetting, and newpass
with their new password:
$ cd /opt/mattermost/bin $ ./mattermost user password username newpass
It will let you set very dumb passwords, so make sure you don’t.
Open Source Chat Server Daemon Starting at Boot
I’m used to running a command to make sure a daemon starts at boot. Now mind you, I learned Linux before there was a systemd, which meant setting all sorts of init scripts to fire off at various runlevels, but I didn’t do any of that here. I read in some documentation that the WantedBy=mysql.service
line makes Mattermost start whenever MySQL does, so it looked like that wouldn’t be required. After a reboot though, Mattermost was not running without me having to touch anything. I started the service again, then ran this to make it fire up at boot time:
systemctl enable mattermost.service
After the next reboot, it was running without me having to touch it again.
Playing with My New Open Source Chat Server
I’ve got the admin and a regular user set up. Once my family gets back (tomorrow — they’ve been gone a week and a half) from Florida, I’ll have my wife and both kids grab the app and dork around on the Pahkahs (that’s how we say Parkers in Maine) team space, so I can get the hang of using it. We’ve all got Android devices, but my wife also has an iPhone (through her employer). Between those and the Linux machines we all run, we should be able to put it through its paces.
I may even pitch it to my coworkers if it seems like a good replacement. Who knows? I hear that even paying for the hosted version is a lot cheaper than a paying for Slack. And I’m guessing that a company getting their hands on data is a lot easier, since it just sits on top of a database that lots of IT folks will know how to use.
Speaking of Databases…
I set this up on MySQL, but also saw instructions on how to use it with PostgreSQL. I am only vaguely familiar with that database, but I’ve always been under the impression that it’s more powerful than MySQL. If I had more experience with it, I’d have probably gone that route.
Input
Ever notice how Slack “sort of” takes Markdown input (now that they’ve fixed the aforementioned Let’s Make Everybody Use a WYSIWYG Chat Box problem)? An underscore for italics, an asterisk for bold. With real Markdown, those are both italic. You need two before and after text to make it bold. This isn’t so with Mattermost. I’ve noticed that it appears to genuinely take Markdown. So far I’ve only played with italics, bold, pre, and code ( _
or *
, __
or **
, `
, and ```
respectively) but so far so good. I type in Markdown all day, so using this software might prevent some of the scowling that happens when I use Slack.
In Closing
This was kind of fun. Being a technical writer, I don’t often get to dirty my hands with things like this, I just document other people doing it. Let me know how you make out. Maybe you could even invite me to be in your team space, if only to help you play with it.
I’m off though, to read the user manual…
NextPrevious
Leave a Reply