Mattermostと言えば、
祝「第700回」!
2008年1月から開始した本連載も、
思えば連載開始から14年。いろいろなことがありました。100年に一度の大噴火が発生したり、
最近は年によって連載回数が50回を切ることもあったため年明けでの700回となりましたが、
さて、
ただのチャットではなくったMattermost
Mattermostは言わずとしれた、
セルフホストした場合は、
Software Designでも3年近く前に、
- 2019年4月号:
【1】 ご存じですか? chat 導入のメリット  - 2019年5月号:
【2】 環境構築、 便利な設定例と統合機能の紹介  - 2019年6月号:
【3】 プラグイン機能と開発方法  - 2019年7月号:
【4】 Mattermostの利用事例の紹介  
COVID-19による生活様式が変わる前の話ではあるものの、
もちろんセルフホストするならその分運用コストはかかりますし、
またSlackの場合16歳未満は利用禁止ですし、
さらに最近は、
他にもSlackからの差異をいくつかあげておきましょう。
- メッセージにMarkdownフォーマットを使える。勝手にビジュアルエディタになったりしない
[6]  - スレッドへの返信はすべてチャンネルのタイムラインに投稿される。スレッドへの返信が突然チャンネルに登場したり、
しなかったりというよくわからない状態を回避できる [7]  - バックアップが簡単。たとえばmysqldump/
rsyncで必要なものはすべてバックアップできる  - テーマを自由に作れる。発言内応だけじゃなくて、
見た目も痛チャットにできる!  - オーディオ・
ビデオコール、 画面共有は未実装。基本的に他サービスをチャットから呼び出す形になる  
ちなみにMattermostのドキュメントには、
UbuntuでMattermostを利用するには
Mattemorstに興味を持ったところで、
- リリースされているバイナリアーカイブをそのまま利用する
 - Mattermost OmnibusでDebianパッケージとしてインストールする
 - Docker Composeでデプロイする
 - Kubernetesでデプロイする
 - GitLab Omnibusに組み込まれたものを利用する
 
Mattermostはバージョン毎に、
ちなみにバイナリアーカイブはEnterprise EditionとTeam Editionの両方が提供されています。Team EditionはEnterprise Editionからオープンソースでない機能を削除したものです。さらにEnterprise Editionには
Mattermost OmnibusはDebianパッケージとして、
Docker Composeは公式が配布しているdocker-compose.
ちなみにGiLab Omnibusには最初からMattermostが同梱されています。よって設定を変更するだけでMattermostが使えるようになります。
今回は一番簡単な2番目のMattermost Omnibusを紹介します
Mattermost Omnibusのインストール
今回はサーバー版のUbuntu 20.
まずはインストールスクリプトをダウンロードします。いきなりシェルに渡してもいいのですが、
$ curl -LO https://deb.packages.mattermost.com/repo-setup.sh $ sha256sum repo-setup.sh 203908888a9fc6c751966e5e779995da8696b61152878bfa7f2cd886a32b0bcf repo-setup.sh $ cat repo-setup.sh
このスクリプトは端的に言うと、apt-keyコマンドで追加して、add-apt-repositoryするというものです
$ sudo bash repo-setup.sh
これにより
$ apt policy mattermost-omnibus
mattermost-omnibus:
  Installed: (none)
  Candidate: 6.2.1-0
  Version table:
     6.2.1-0 500
        500 https://deb.packages.mattermost.com focal/main amd64 Packages
     6.1.0-0 500
        500 https://deb.packages.mattermost.com focal/main amd64 Packages
(以下略)
$ apt show mattermost-omnibus
Package: mattermost-omnibus
Version: 6.2.1-0
Priority: optional
Section: base
Maintainer: Mattermost Team <info@mattermost.com>
Installed-Size: unknown
Depends: python3, python3-psycopg2, ansible, postgresql-13 (>= 13.1-1.pgdg20.04+1), nginx (>= 1.18.0-1~focal), certbot (>= 0.40.0-1), python3-certbot-nginx (>= 0.40.0-0ubuntu0.1), debconf, mattermost (= 6.2.1-0)
Download-Size: 5852 kB
APT-Sources: https://deb.packages.mattermost.com focal/main amd64 Packages
Description: Mattermost Omnibus Package
 Metapackage to install Mattermost server and its dependencies
N: There are 57 additional records. Please use the '-a' switch to see them.あとはmattermost-omnibusパッケージをインストールするだけなのですが、MMO_」
少し長くなりますが、
$ sudo MMO_HTTPS=false apt install mattermost-omnibus
(中略)
0 upgraded, 53 newly installed, 0 to remove and 0 not upgraded.
Need to get 310 MB of archives.
After this operation, 229 MB of additional disk space will be used.
Do you want to continue? [Y/n]
(中略)
Setting up mattermost-omnibus (6.2.1-0) ...
config file "/etc/mattermost/mmomni.yml" successfully saved
[WARNING]: provided hosts list is empty, only localhost is available. Note that
the implicit localhost does not match 'all'
PLAY [localhost] ***************************************************************
TASK [Gathering Facts] *********************************************************
ok: [localhost]
TASK [Update debconf variables with json file values] **************************
ok: [localhost] => (item={'key': 'mattermost-omnibus/domain', 'value': 'mm.example.org'})
ok: [localhost] => (item={'key': 'mattermost-omnibus/email', 'value': ''})
TASK [Ensure that NGINX is running] ********************************************
skipping: [localhost]
TASK [Check if certificate already exists] *************************************
skipping: [localhost]
TASK [Generate SSL Certificate] ************************************************
skipping: [localhost]
TASK [Renew SSL certificate] ***************************************************
skipping: [localhost]
TASK [Configure NGINX https template] ******************************************
changed: [localhost]
TASK [Delete default NGINX configuration file] *********************************
changed: [localhost]
TASK [Restart NGINX service with the new configuration] ************************
changed: [localhost]
TASK [Create database user] ****************************************************
 [WARNING]: Module did not set no_log for no_password_changes
changed: [localhost]
TASK [Create database for Mattermost] ******************************************
changed: [localhost]
TASK [Create system user] ******************************************************
changed: [localhost]
TASK [Ensure file permissions] *************************************************
changed: [localhost] => (item=/opt/mattermost)
changed: [localhost] => (item=/var/opt/mattermost/data)
changed: [localhost] => (item=/var/log/mattermost)
TASK [Generate mattermost env variables] ***************************************
changed: [localhost]
TASK [Generate systemd service] ************************************************
changed: [localhost]
TASK [Enable and restart Mattermost service] ***********************************
changed: [localhost]
PLAY RECAP *********************************************************************
localhost                  : ok=12   changed=10   unreachable=0    failed=0    skipped=4    rescued=0    ignored=0
 ___ ___   ____  ______  ______    ___  ____   ___ ___   ___   _____ ______
|   |   | /    ||      ||      |  /  _]|    \ |   |   | /   \ / ___/|      |
| _   _ ||  o  ||      ||      | /  [_ |  D  )| _   _ ||     (   \_ |      |
|  \_/  ||     ||_|  |_||_|  |_||    _]|    / |  \_/  ||  O  |\__  ||_|  |_|
|   |   ||  _  |  |  |    |  |  |   [_ |    \ |   |   ||     |/  \ |  |  |
|   |   ||  |  |  |  |    |  |  |     ||  .  \|   |   ||     |\    |  |  |
|___|___||__|__|  |__|    |__|  |_____||__|\_||___|___| \___/  \___|  |__|
  Installation successful! Join the Mattermost community for questions
  and help: https://mattermost.com/pl/default-ask-mattermost-community/
わかる人にはわかるかと思いますが、/var/の中で、MMO_」
 
ドメイン名は最終的にブラウザーからアクセスする際の名前を入れておいたほうが無難です。これは最終的にMattermostのServiceSettings.」
その後、mmomniコマンドを使って設定するのですが、mmonmi reconfigureでAnsibleを呼び出しています。Ansibleのプレイブックは/opt/」
ちなみに、MMO_」/var/の処理がまるっとスキップされるようです。この場合は、
mmomniコマンドは、
$ sudo mmomni status [11493] nginx: running [9646] postgresql@13-main: running [11843] mattermost: running
設定ファイルの詳細は次回以降解説しますが、
- Mattermost Omnibusの設定ファイルは
「 /etc/」mattermost/ mmomni. yaml で、 変更後の反映コマンドは 「 sudo mmomni reconfigure」。 - Mattermost本体の設定は、
「 sudo mmctl --local config edit」で編集すると反映される。  
Mattermost Omnibusをインストールした環境のListenしているTCPのポートを見ると次のようになっています。
$ sudo ss -ltnp
State      Recv-Q     Send-Q         Local Address:Port         Peer Address:Port    Process
LISTEN     0          128                  0.0.0.0:80                0.0.0.0:*        users:(("nginx",pid=11495,fd=6),("nginx",pid=11494,fd=6),("nginx",pid=11493,fd=6))
LISTEN     0          128            127.0.0.53%lo:53                0.0.0.0:*        users:(("systemd-resolve",pid=2057,fd=13))
LISTEN     0          128                  0.0.0.0:22                0.0.0.0:*        users:(("sshd",pid=243,fd=3))
LISTEN     0          128                127.0.0.1:5432              0.0.0.0:*        users:(("postgres",pid=9646,fd=5))
LISTEN     0          128                     [::]:80                   [::]:*        users:(("nginx",pid=11495,fd=7),("nginx",pid=11494,fd=7),("nginx",pid=11493,fd=7))
LISTEN     0          128                     [::]:22                   [::]:*        users:(("sshd",pid=243,fd=4))
LISTEN     0          128                        *:8065                    *:*        users:(("mattermost",pid=11843,fd=24))80番ポートがNginx、http://指定したドメイン/」http://」、http://インスタンスのIPアドレス/」
Nginxの設定について
ただし、
- Mattermost OmnibusでインストールしたNginxを正しく設定する
 - 別のリバースプロキシを利用する
 
前者はたとえばすでに取得済みの証明書を利用して、
まずドメイン名のFQDNは/etc/」/opt/」sudo mmomni reconfigure」
後者のリバースプロキシは、
Mattermost向けのリバースプロキシーの設定は、/etc/」
Mattermostの初回セットアップ
Mattermostはウェブブラウザーでアクセスした際の、
 
 
 
 
 
インストール直後は英語UIですが、
 
 
これで必要最低限の設定は完了しました。必要最低限なのでまだ動かないものがいくつかあります。たとえばメール通知に必要なメールサーバーの設定等がその最たるものです。というわけで次回からは、