はじめに
久しぶりにMattermostをインストールしようと思ったら色々と変わっていたので、インストール方法をメモることにした。
対象環境
OS:Rocky Linux 8.5
データベース:mariadb 10.3
準備
Rocky Linuxは基本的にデフォルト状態でインストールし、以下の作業を実施済み。
1 2 3 |
# dnf update # dnf install epel-release # dnf install elrepo-release |
mariadb インストール
mariadb をインストールします。
ザクっとコマンドだけ以下に記します。
細かいことは適当にやっちゃいます。
1 2 3 4 |
# dnf install mariadb-server # systemctl start mariadb # systemctl enable mariadb # mysql_secure_installation |
DB作成
こちらもザクっと書いちゃいます。
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 17 Server version: 10.3.32-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> create user 'mmuser'@'%' identified by 'xxxxxx'; MariaDB [(none)]> create database mattermost; MariaDB [(none)]> grant all privileges on mattermost.* to 'mmuser'@'%'; |
ザクっと行き過ぎ?
取り敢えず、ユーザ作って、データベース作って、アクセス許可設定してって感じです。
Mattermost ダウンロード
なんでこのメモ。。。記事を書き始めたかというと、コレなんです!
ダウンロードが変わっちゃっててよく分んなくなってた。
やりたいことは、インストールモジュールをダウンロードしたいのですが、どこにあるか分からなかった。
取り敢えず、ダウンロードするフォルダを準備します。
どこか適当な作業用のフォルダを作成して、そのフォルダへ移動しておきます。
準備が出来たので、ダウンロード対象を探します。
まずはブラウザこのURLを参照する。
https://mattermost.com/deploy/

下の方にスクロールすると、こんな画面があるので、「Binary」タブを選択する。

すると、こんな画面になる。

URLをコピって、以下のコマンドを実行する。
1 |
# wget https://releases.mattermost.com/6.7.0/mattermost-6.7.0-linux-amd64.tar.gz |
※バージョン番号はダウンロードするタイミングで変わっていると思われるので注意してください。
せっかくなので、先のホームページで「Installation Guide >>」とその後の手順が示されているっぽいので覗いてみます。

どっかの(ここも含めて)サイトの内容を信じるよりも、インストールガイドに従って作業を進める方が確実ですね♪
Mattermost インストール
インストールガイドに書かれている内容を素直に信じて作業を進めます!
私のサイトに書いている内容は、既に古い可能性があるので、見比べながら作業を進める方が良いでしょう。
また、私はrootユーザで作業を進めているので、sudoコマンドを省略しています。
さて、進めます。
まずは先程ダウンロードしたファイルを解凍します。
# tar -xvzf mattermost*.gz
本体を移動します。
1 |
# mv mattermost /opt |
ストレージディレクトリを作成します。
1 |
# mkdir /opt/mattermost/data |
※ストレージディレクトリには、ユーザーがMattermostに投稿するすべてのファイルと画像が含まれるため、アップロードされるファイルと画像の予想数を保持するのに十分な大きさのドライブがあることを確認する必要があります。
いざとなったら、シンボリックリンクで余裕のあるディレクトリへ保存することも考えた方が良いかも知れませんね。
ここまでで本体のインストールは一旦終わったようです。
Mattermost セッティング
mattermostのサービスを実行するために、ユーザとグループを作成し所有権と権限を設定します。
1 2 3 |
# useradd --system --user-group mattermost # chown -R mattermost:mattermost /opt/mattermost # chmod -R g+w /opt/mattermost |
よく失敗する私は、設定ファイルを変更する前にバックアップを作成します。
1 2 |
# cd /opt/mattermost/config/ # cp -p config.json config.json_org |
設定ファイルを弄って動かなくなって、後戻りできなくなってしまうことがよくあるのでやっているだけで、自信のある人はそんなことしないで進んでください。
設定ファイルを編集します。
1 |
# vi config.json |
滅茶苦茶余談ですが。。。。jqというjsonを扱うコマンドがあります。
jsonファイルをコマンドライン上で確認や編集を行う際にちょっと便利かな?と思っています。まだ使ったことは無いのですが、気になるコマンドです。
下記に本家サイトがあります。
https://stedolan.github.io/jq/
更新が滞っているみたいに見えるのがちょっと気になりますが。。。ご参考までに。
変更内容は以下の通りです。
- SqlSetteings -> DriverName を”mysql”に変更
- SqlSetteings -> DataSource を “mmuser:<
mmuser-password>@tcp(<host-name-or-IP>:3306)/mattermost?charset=utf8mb4,utf8&writeTimeout=30s"
<mmuser-password>はDBユーザ作成時に設定したパスワードを指定してください。
<host-name-or-IP>は「localhost」でも大丈夫です。
ちょっとコメントします。
DataSourceの最後の方にある「utf8&writeTimeout=30s」について、「&」の文字はmattermostを起動すると勝手に「\u0026」に置き換わります。
他のサイトで異る記載があり、それも有効だとは思うのですが、本家のインストールガイドに従ってやってみても良いと思われます。
実際のサンプルを以下に記します。
1 2 3 4 |
"SqlSettings": { "DriverName": "mysql", "DataSource": "mmuser:xxxxxx@tcp(localhost:3306)/mattermost?charset=utf8mb4,utf8\u0026writeTimeout=30s", |
起動確認
本番起動を行う前に、正しく起動できるか確認してみます。
1 2 |
# cd /opt/mattermost # sudo -u mattermost bin/mattermost |
ごちゃごちゃとログが出力されます。
強制終了が発生しなければ一応動いているみたいです。
環境が許すのであれば、firewalldをストップさせて確認しようと思います。
1 |
# systemctl stop firewalld |
この後、以下のURLをブラウザで起動して確認してみます。
http://localhost:8065/
サインアップ用の画面が表示されればなんとなく安心できます。
画面が表示されない場合は、「http」になっているか確認してみてください。
それでもダメな時は、何か間違っている可能性があります。がんばれ!
firewalldの設定
標準の環境だと、当然firewalldが動作していて、対象のポートはアクセスできません。
解放する必要がありますね。
解放せずとも、アクセス出来るようにしなければなりません。
後でReverseProxy使ったりして、通常のHTTP(80)ポートとかHTTPS(SSL/TLS:443)とかでアクセスしたくなりますが、それは後程。。。
取り敢えず、一旦は8065ポートを解放してアクセスできることを確認します。
基本が出来ていないとトラブルの原因が何か分からなくなりますからw
先程、firewallldを止めてしまった場合には以下のコマンドで再起動しておきます。
1 |
# systemctl start firewalld |
以下のコマンドで8065ポートを解放します。
1 2 |
# firewall-cmd --add-port=8065/tcp --permanent # firewall-cmd --reload |
再度ブラウザでアクセスすると正常にアクセスできることを確認できるとおもいます。
systemdによる自動起動設定
「起動確認」で起動したmattermostはCTRL+Cで終了させます。
systemdによる自動起動の設定を行います。
まず、serviceファイルを作成します。
1 2 3 |
# touch /lib/systemd/system/mattermost.service # cd /lib/systemd/system/ # vi mattermost.service |
記載内容は以下の通りです。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[Unit] Description=Mattermost After=network.target After=mariadb.service BindsTo=mariadb.service [Service] Type=notify ExecStart=/opt/mattermost/bin/mattermost TimeoutStartSec=3600 KillMode=mixed Restart=always RestartSec=10 WorkingDirectory=/opt/mattermost User=mattermost Group=mattermost LimitNOFILE=49152 [Install] WantedBy=multi-user.target |
[Unit]セクションのAfterとBindsToの項目をmariadb.serviceに変更しています。
インストールガイドでmysql用の記載として、それぞれをmysql.serviceにしていますが、それでも問題ありません。
それでは起動してみましょう!
1 2 3 4 5 |
# systemctl daemon-reload # systemctl start mattermost.service Job for mattermost.service failed because the control process exited with error code. See "systemctl status mattermost.service" and "journalctl -xe" for details. |
いきなり失敗しました!
多分、ここで躓きます(TT)
内容を確認します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# journalctl -xe -- Defined-By: systemd -- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- Unit mattermost.service has failed. -- -- The result is failed. 5月 28 06:07:39 localhost.localdomain setroubleshoot[14220]: AnalyzeThread.run(): Cancel pending alarm 5月 28 06:07:39 localhost.localdomain setroubleshoot[14220]: <code>SELinux is preventing /usr/lib/systemd/systemd from execute access on</code> t> 5月 28 06:07:39 localhost.localdomain setroubleshoot[14220]: SELinux is preventing /usr/lib/systemd/systemd from execute access on t> ***** Plugin catchall (100. confidence) suggests ******************> If you believe that systemd should be allowed execute access on the ma> Then you should report this as a bug. You can generate a local policy module to allow this access. Do allow this access for now by executing: # ausearch -c '(ttermost)' --raw | audit2allow -M my-ttermost # semodule -X 300 -i my-ttermost.pp 5月 28 06:07:39 localhost.localdomain setroubleshoot[14220]: AnalyzeThread.run(): Set alarm timeout to 10 5月 28 06:07:42 localhost.localdomain org.gnome.Shell.desktop[6472]: Window manager warning: last_user_time (10454099) is greater th> 5月 28 06:07:42 localhost.localdomain org.gnome.Shell.desktop[6472]: Window manager warning: W3 appears to be one of the offending w> |
まあ、ざっくりと言うと、SELinuxのチェックに引っ掛かって止まっています。
よくある話。。。なのですが、面倒なんですよねぇ〜(TT)
取り敢えず、表示された内容に記載されているコマンドを打ち込んで対応を行います。
適当なディレクトリに移動してから以下のコマンドを実行します。
1 2 |
# ausearch -c '(ttermost)' --raw | audit2allow -M my-ttermost # semodule -X 300 -i my-ttermost.pp |
再度実行してみますが。。。。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# systemctl start mattermost Job for mattermost.service failed because the control process exited with error code. See "systemctl status mattermost.service" and "journalctl -xe" for details. [root@localhost ~]# journalctl -xe 5月 28 06:15:58 localhost.localdomain dbus-daemon[934]: [system] Successfully activated service 'org.fedoraproject.SetroubleshootPrivileged' 5月 28 06:15:59 localhost.localdomain setroubleshoot[15253]: SELinux is preventing /usr/lib/systemd/systemd from 'read, open' accesses on the file /opt/mattermost/bin/mattermost. For complete SELinux > 5月 28 06:15:59 localhost.localdomain setroubleshoot[15253]: SELinux is preventing /usr/lib/systemd/systemd from 'read, open' accesses on the file /opt/mattermost/bin/mattermost. ***** Plugin restorecon (99.5 confidence) suggests ************************ If you want to fix the label. /opt/mattermost/bin/mattermost default label should be bin_t. Then you can run restorecon. The access attempt may have been stopped due to insufficient permissions to access a parent directory in whic> Do # /sbin/restorecon -v /opt/mattermost/bin/mattermost ***** Plugin catchall (1.49 confidence) suggests ************************** If you believe that systemd should be allowed read open access on the mattermost file by default. Then you should report this as a bug. You can generate a local policy module to allow this access. Do allow this access for now by executing: # ausearch -c '(ttermost)' --raw | audit2allow -M my-ttermost # semodule -X 300 -i my-ttermost.pp |
またしてもエラーが発生して留まってしまいます。
でも先程とは少し異るエラーの様で、対策が異なっています。
ログに従って以下のコマンドを実行します。
1 |
# /sbin/restorecon -v /opt/mattermost/bin/mattermost |
あれ?返ってこない。。。長い。。。という状態が続きます。
止めちゃおうか?って思います。
でも待ちます。
設定を反映するのに時間が掛かっています。
ちょっと休憩するくらい待ちました。
コマンドの終了を待って実行します。
1 |
# systemctl start mattermost.service |
今度は成功した様です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# systemctl status mattermost.service ● mattermost.service - Mattermost Loaded: loaded (/usr/lib/systemd/system/mattermost.service; disabled; vendor preset: disabled) Active: active (running) since Sat 2022-05-28 06:17:38 JST; 19s ago Main PID: 15595 (mattermost) Tasks: 40 (limit: 4605) Memory: 99.4M CGroup: /system.slice/mattermost.service ├─15595 /opt/mattermost/bin/mattermost ├─15616 plugins/com.mattermost.nps/server/dist/plugin-linux-amd64 ├─15624 plugins/com.mattermost.plugin-channel-export/server/dist/plugin-linux-amd64 ├─15638 plugins/playbooks/server/dist/plugin-linux-amd64 └─15646 plugins/focalboard/server/dist/plugin-linux-amd64 |
最後に自動起動を設定します。
1 |
# systemctl enable mattermost.service |
以上でMattermostのインストールと設定は完了しました。
ここから実際にチームを作成して利用できる環境設定を行います。
何故か私の調べた限りでその設定についての記載が成されたサイトは見つからず、私自身もメモを取る前に進めてしまいました。
またの機会に説明を記したいと思います。
ということで、サイトへアクセスして、初期設定を行います。
http://ドメイン:8065/
ログイン完了後に幾つかの設定を行いますので、その設定については別途記載したいと思います。