LoginSignup
1
2

More than 1 year has passed since last update.

Mattermost のインストール作業メモ [Apache & Subdirectry 運用]

Last updated at Posted at 2021-05-14

インストール 作業メモ [21/07/04]

Apache & Subdirectry 運用設定

  • Ubuntu 20.04.2 LTS
  • Mattermost Team Edition v5.34.2
  • PostgreSQL 12.6 (Ubuntu 12.6-0ubuntu0.20.04.1)
※gitlabの[Omnibus]パッケージに[GitLabMattermost]として同梱されていますので、
 Subdirectry 運用が必要なければ、こちらのインストールの方が楽です。
 しかしながら、この同梱版[GitLabMattermost]では、サブディレクトリ運用の方法がわからず、
 今回のインストール方法としています。

https://mattermost.com/
image.png

↑ここのリンクは、エンタープライズ版のリンクです。
エンタープライズ版でも構わないと説明はありますが、オープンソース版と明示されている Team Edition をインストールしています。
※このページでのリンク先は使用せず、右下の Version archiveからリンク先をたどります。

・ ×Mattermost Enterprise Edition v5.34.2
https://releases.mattermost.com/5.34.2/mattermost-5.34.2-linux-amd64.tar.gz

・ 〇Mattermost Team Edition v5.34.2 ('-team-'の文字が付きます。)
https://releases.mattermost.com/5.34.2/mattermost-team-5.34.2-linux-amd64.tar.gz


■↓基本的なインストール手順は基本的にここに載っているコマンドをそのまま使用しました。


■インストール設定内容

インストール先: /opt/mattermost
ユーザー & グループ: mattermost : mattermost
設定ファイル : /opt/mattermost/config/config.json
起動ポート : 8065


■事前のDB設定 (説明通りにコマンドを打ちます。)

sudo usermod -aG sudo postgres ##※私の環境では必要でした。postgresをsudoユーザーへ

sudo apt install postgresql postgresql-contrib
sudo --login --user postgres
sudo -u postgres psql
postgres=# CREATE DATABASE mattermost;
postgres=# CREATE USER mmuser WITH PASSWORD 'mmuserのパスワード';
postgres=# GRANT ALL PRIVILEGES ON DATABASE mattermost to mmuser;
postgres=# \q
exit
sudo systemctl reload postgresql
postgresqlの設定ファイルを編集します。以下を、trustに変えます。
/etc/postgresql/12/main/pg_hba.conf

local   all             all                                     trust


host    all             all             ::1/128                 trust

↓ データベース設定のテスト確認コマンド
psql --dbname=mattermost --username=mmuser --password
psql --host=localhost --dbname=mattermost --username=mmuser --password

■プログラムのダウンロード、展開、配置 (説明通りにコマンドを打ちます。)

sudo apt update
sudo apt upgrade
cd /usr/local/src
sudo wget https://releases.mattermost.com/5.34.2/mattermost-team-5.34.2-linux-amd64.tar.gz
sudo tar -xvzf mattermost*.gz
sudo mv mattermost /opt
sudo mkdir /opt/mattermost/data
sudo useradd --system --user-group mattermost
sudo chown -R mattermost:mattermost /opt/mattermost
sudo chmod -R g+w /opt/mattermost

■Mattermost の設定ファイル ※必要な部分を修正します。 

sudo vi /opt/mattermost/config/config.json
/opt/mattermost/config/config.json

##3
        "SiteURL": "http://mattermost.example.com/mattermost",

##149-150
        "DriverName": "postgres",
        "DataSource": "postgres://mmuser:パスワード@localhost:5432/mattermost?sslmode=disable\u0026connect_timeout=10",
■Mattermost の起動テストを行います。(以下のコマンドを実行、CTRL+C で停止します)
cd /opt/mattermost
sudo -u mattermost ./bin/mattermost

http://localhost:8065/mattermost 等のアドレスで初期設定画面が表示されるか確認します。

image.png

■プログラムの起動設定① サービス自動起動設定
sudo touch /lib/systemd/system/mattermost.service
sudo vi /lib/systemd/system/mattermost.service
/lib/systemd/system/mattermost.service

[Unit]
Description=Mattermost
After=network.target
After=postgresql.service
BindsTo=postgresql.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=postgresql.service

■プログラムの起動設定② Apacheの設定

default-ssl.conf に追記しました。

/etc/apache2/sites-available/default-ssl.conf
<VirtualHost _default_:443>

 --------

ProxyPreserveHost On  ##←この記載がないとWebSocketのエラーが発生します。
######## mattermost ########################################
  RewriteCond %{REQUEST_URI} /mattermost/api/v[0-9]+/(users/)?websocket [NC,OR]
  RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC,OR]
  RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
  RewriteRule .* ws://127.0.0.1:8065%{REQUEST_URI} [P,QSA,L]

  <Location /mattermost>
    Require all granted

    ProxyPass http://127.0.0.1:8065/mattermost
    ProxyPassReverse http://127.0.0.1:8065/mattermost
    ProxyPassReverseCookieDomain 127.0.0.1 mattermost.example.com/mattermost

  </Location>

--------

</VirtualHost>
■起動に関する主なコマンドの例

①mattermost.service
②apache2.service  両方の起動が必要

sudo systemctl daemon-reload
sudo systemctl status mattermost.service
sudo systemctl start mattermost.service
sudo systemctl enable mattermost.service

sudo a2ensite default-ssl
sudo apache2ctl configtest

sudo systemctl start apache2
sudo systemctl stop apache2
sudo systemctl reload apache2
■設定を間違えた時用のアンインストール用コマンド
sudo systemctl stop mattermost.service
sudo systemctl disable mattermost.service
sudo rm -rf /opt/mattermost

##mattermostデータベースを削除して再度作成
sudo -u postgres psql
postgres=# DROP DATABASE mattermost;
postgres=# CREATE DATABASE mattermost;
postgres=# GRANT ALL PRIVILEGES ON DATABASE mattermost to mmuser;
postgres=# \q

■トラブル発生対応

起動後、このような警告が表示されるようになりました。

Mattermostに接続できません。接続を確認してください。この問題が続くようならば、システム管理者にWebSocketのポートを確認するよう依頼してください。(Please check connection, Mattermost unreachable. If issue persists, ask administrator to check WebSocket port.)

image.png

原因:Apacheの設定の問題でした、

①以下の設定をVirtualHost内に追加すると直りました。

/etc/apache2/sites-available/default-ssl.conf
ProxyPreserveHost On

②以下、Apacheにモジュールを追加しました。

$ sudo a2enmod proxy
$ sudo a2enmod proxy_http
$ sudo a2enmod proxy_wstunnel
■参考にさせていただいたページ

https://github.com/mattermost/docs/issues/1295
https://forum.mattermost.org/t/mm-server-subpath-issue/5391/15
https://notes.only-weekend.net/2018/11/28/mattermost%E3%82%92%E3%82%B5%E3%83%96%E3%83%87%E3%82%A3%E3%83%AC%E3%82%AF%E3%83%88%E3%83%AA%E3%81%A7%E4%BD%BF%E3%81%86apache%E3%81%AE%E8%A8%AD%E5%AE%9A%E3%81%AB%E6%88%90%E5%8A%9F%E3%81%97%E3%81%9F/

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2