ウェブサイト検索

Debian 12にMattermostをインストールする方法


Debian 12にMattermostをインストールする方法

このチュートリアルはこれらのOSバージョンのために存在します

  • Debian 12 (ブックワーム)
  • Debian 11 (バルセイヤ)
  • Debian 10 (バスター)

このページで

  1. 前提条件
  2. 依存関係をインストール中
  3. PostgreSQLのユーザーとデータベースの設定
  4. Mattermostのインストール
  5. Mattermostのためのsystemdサービスを作成する
  6. Nginxをリバースプロキシとして設定する
  7. Mattermostで最初のワークスペースを作成する
  8. 結論

Mattermostは、SlackやMicrosoft Teamsのオープンソースの代替手段です。オンラインチャットを自己ホストすることができ、ファイル共有、検索、オートメーション、さまざまなサードパーティとの統合など、多くの機能を提供しています。

Mattermostは、組織や企業のために設計された内部チャットのコラボレーションプラットフォームです。それは、重要なワークフローのためのメッセージングシステム、自動化、統合、およびセキュリティを組み合わせています。

このガイドでは、Debian 12 サーバーに Mattermost をインストールする方法を示します。PostgreSQL と Nginx を使用して Mattermost をインストールし、SSL 証明書で Mattermost を保護します。

前提条件

このガイドを始めるには、次のものを用意してください:

  • Debian 12 サーバー
  • 管理者権限を持つ非ルートユーザー
  • ドメイン名が準備完了し、サーバーのIPアドレスにポイントされています。

依存関係をインストール中

Mattermostをインストールする前に、依存関係をインストールする必要があります。これには、PostgreSQLデータベースサーバー、Nginxウェブサーバー、そしてCertbotが含まれます。

まず、次のコマンドを実行してDebianパッケージインデックスを更新します。

sudo apt update

以下の「apt」コマンドを使用して、PostgreSQL、Nginx、Certbot、Gnupg、およびcurlなどの依存関係をインストールします。インストールを確認するには「Y」を入力してください。

sudo apt install postgresql postgresql-contrib nginx certbot gnupg curl

インストールが完了したら、'systemctl'コマンドでPostgreSQLサービスの状態を確認してください。あなたのシステムでPostgreSQLが実行されていることが分かります。

sudo systemctl is-enabled postgresql
sudo systemctl status PostgreSQL

最後に、以下のコマンドを使ってNginxサービスのステータスを確認してください。NginxサービスはあなたのDebianシステム上で稼働している必要があります。

sudo systemctl is-enabled nginx
sudo systemctl status nginx

PostgreSQLのユーザーとデータベースの設定

依存関係がインストールされた後、Mattermost用の新しいデータベースとユーザーを作成します。このために、PostgreSQLサーバーをインストールするとデフォルトでインストールされるPostgreSQLシェル「psql」を利用します。

下記の「psql」コマンドを使ってPostgreSQLにログインしてください。

sudo -u postgres psql

次のクエリを実行して、新しいデータベースとユーザー「mattermost」を、パスワード「password」で作成してください。

CREATE DATABASE mattermost;
CREATE USER mmuser WITH PASSWORD 'password';
GRANT ALL ON DATABASE mattermost TO mmuser;
ALTER DATABASE mattermost OWNER TO mmuser;
GRANT USAGE, CREATE ON SCHEMA PUBLIC TO mmuser;

次に、以下のコマンドを使用してPostgreSQLサーバー内のデータベースとユーザーのリストを確認してください。

\l
\du

以下に、データベースとユーザー'mattermost'が作成されたことがわかります。

'psql'シェルから退出するには、'quit'と入力してください。

新しいPostgreSQLユーザーとデータベースが作成されたので、PostgreSQLユーザーがPostgreSQLサーバーにログインできることを確認します。

以下の 'psql' コマンドを実行して、ユーザー 'mattermost' で PostgreSQL サーバーにログインしてください。プロンプトが表示されたらパスワードを入力してください。

sudo -u postgres psql --host=localhost --dbname=mattermost --username=mmuser --password

ログインしたら、次のクエリで接続を確認してください:

\conninfo

PostgreSQLへの接続状態は以下のように表示されます:

Mattermostのインストール

この時点で、あなたのサーバーはMattermostのインストールの準備が整いました。次に、Mattermostのソースコードをダウンロードし、インストールディレクトリを設定し、PostgreSQLを使用してMattermostを構成し、Mattermostのドメイン名を設定し、最後にMattermostのインストールディレクトリの適切な権限と所有権を設定します。

Mattermostをダウンロードする前に、新しいシステムユーザー'mattermost'を以下のように追加してください:

sudo useradd --system --user-group mattermost

次に、以下の 'wget' コマンドを実行して Mattermost をダウンロードし、下記の 'tar' コマンドを使用して解凍してください。 Mattermost サーバーは 'mattermost' ディレクトリ内で利用可能になります。

wget https://releases.mattermost.com/10.0.1/mattermost-10.0.1-linux-amd64.tar.gz
tar -xf mattermost-10.0.1-linux-amd64.tar.gz

次に、'mattermost'ディレクトリを'/opt'に移動します。これで、Mattermostのインストールディレクトリは'/opt/mattermost'で利用できるようになります。

mv mattermost /opt/

次に、新しいデータディレクトリ'/opt/mattermost/data'を作成します。これはユーザーデータを保存するために使用されます。

sudo mkdir -p /opt/mattermost/data

次に、デフォルトのMattermost設定「/opt/mattermost/config/config.json」を「nano」エディタで開きます。

sudo nano /opt/mattermost/config/config.json

「SiteURL」をあなたのドメイン名に変更してください。例: https://mattermost.howtoforge.local.

"ServiceSettings": {
 "SiteURL": "https://mattermost.howtoforge.local",

「SqlSettings」と「DataSource」のセクション内で、データベースの資格情報を次のように自分の詳細に変更してください:

"SqlSettings": {
 "DriverName": "postgres",
 "DataSource": "postgres://mattermost:password@localhost/mattermost?sslmode=disable&connect_timeout=10&binary_parameters=yes",

ファイルを保存してエディタを終了してください。

最後に、以下のコマンドを実行して、'/opt/mattermost' ディレクトリの所有権をユーザー 'mattermost' に変更します。また、グループ 'mattermost' が '/opt/mattermost' ディレクトリに書き込みできることを確認してください。

sudo chown -R mattermost:mattermost /opt/mattermost
sudo chmod -R g+w /opt/mattermost

Mattermostのためのsystemdサービスを作成する

このセクションでは、Mattermost のための新しい systemd サービスファイルを作成します。これにより、Mattermost はバックグラウンドで実行され、'systemctl' ユーティリティを使用して Mattermost プロセスを簡単に管理できるようになります。

「nano」エディタを使用して新しいsystemdサービスファイル「/etc/systemd/system/mattermost.service」を作成します。

sudo nano /etc/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
KillMode=mixed
Restart=always
RestartSec=10
WorkingDirectory=/opt/mattermost
User=mattermost
Group=mattermost
LimitNOFILE=49152
[Install]
WantedBy=multi-user.target

ファイルを保存してエディタを終了してください。

以下の 'systemctl' コマンドを実行して、systemd マネージャーを再読み込みします。

sudo systemctl daemon-reload

最後に、次のコマンドで「mattermost」サービスを開始、有効化、確認できるようになりました。

sudo systemctl enable --now mattermost
sudo systemctl status mattermost

以下のように、'mattermost'サービスが実行中で有効です。

Nginxをリバースプロキシとして設定する

この時点で、MattermostはあなたのDebian 12サーバーで実行されています。このセクションでは、LetsencryptからSSL証明書を作成し、Mattermostのリバースプロキシとして使用される新しいNginxサーバーブロックを作成します。

Nginxを設定する前に、以下のコマンドを実行してNginxサービスを停止し、Mattermost用のSSL証明書を生成してください。ドメイン名とメールアドレスはご自身の情報に変更してください。

sudo systemctl stop nginx
sudo certbot --certonly --standalone --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m [email  -d mattermost.howtoforge.local

プロセスが完了すると、あなたのSSL証明書は「/etc/letsencrypt/live/mattermost.howtoforge.local」ディレクトリ内で利用可能になります。

次に、デフォルトのNginx設定「/etc/nginx/nginx.conf」を「nano」エディタで開きます。

sudo nano /etc/nginx/nginx.conf

次の設定を行を'/etc/nginx/nginx.conf'の前に追加してください。

 server_names_hash_bucket_size 64;
 include /etc/nginx/conf.d/*.conf;

ファイルを保存して終了します。

今、'nano'エディタを使用して、新しいNginxサーバーブロックの設定ファイル'/etc/nginx/sites-available/mattermost'を作成してください。

sudo nano /etc/nginx/sites-available/mattermost

以下の設定を挿入し、'server_name'オプションをあなたのドメイン名に変更してください。また、SSL証明書のパスも調整してください。

upstream backend {
server 127.0.0.1:8065;
keepalive 32;
}
server {
listen 80;
server_name mattermost.howtoforge.local;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name mattermost.howtoforge.local;
http2_push_preload on; # Enable HTTP/2 Server Push
ssl_certificate /etc/letsencrypt/live/mattermost.howtoforge.local/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mattermost.howtoforge.local/privkey.pem;
ssl_session_timeout 1d;
Enable TLS versions (TLSv1.3 is required upcoming HTTP/3 QUIC).
ssl_protocols TLSv1.2 TLSv1.3;
Enable TLSv1.3's 0-RTT. Use $ssl_early_data when reverse proxying to
prevent replay attacks.
#
@see: https://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_early_data
ssl_early_data on;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384';
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:50m;
HSTS (ngx_http_headers_module is required) (15768000 seconds = six months)
add_header Strict-Transport-Security max-age=15768000;
OCSP Stapling ---
fetch OCSP records from URL in ssl_certificate and cache them
ssl_stapling on;
ssl_stapling_verify on;
add_header X-Early-Data $tls1_3_early_data;
location ~ /api/v[0-9]+/(users/)?websocket$ {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
client_max_body_size 50M;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_buffers 256 16k;
proxy_buffer_size 16k;
client_body_timeout 60s;
send_timeout 300s;
lingering_timeout 5s;
proxy_connect_timeout 90s;
proxy_send_timeout 300s;
proxy_read_timeout 90s;
proxy_http_version 1.1;
proxy_pass http://backend;
}
location / {
client_max_body_size 100M;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_buffers 256 16k;
proxy_buffer_size 16k;
proxy_read_timeout 600s;
proxy_http_version 1.1;
proxy_pass http://backend;
}
}
This block is useful for debugging TLS v1.3. Please feel free to remove this
and use the '$ssl_early_data' variable exposed by NGINX directly should you
wish to do so.
map $ssl_early_data $tls1_3_early_data {
"~." $ssl_early_data;
default "";
}

完了したら、ファイルを保存してエディタを終了してください。

今、Mattermost用のNginxサーバーブロックを有効にし、Nginxの構文を確認してください。構文が正しければ、「構文はOK - テストは成功です」という出力が表示されます。

sudo ln -s /etc/nginx/sites-available/mattermost /etc/nginx/sites-enabled/
sudo nginx -t

最後に、以下の `systemctl` コマンドを実行して Nginx サービスを再起動し、変更を適用します。これにより、Mattermost は Nginx リバースプロキシの下で動作します。

sudo systemctl restart nginx

Mattermostで最初のワークスペースを作成する

ウェブブラウザを開いて、https://mattermost.howtoforge.localにアクセスしてください。インストールが成功していれば、Mattermostの新しい管理者を作成するように求められます。

新しい管理者ユーザー、メールアドレス、およびパスワードを入力し、'アカウントを作成'をクリックします。

組織名を入力して、'続行'をクリックしてください。

GitHub、Gitlab、Jira、または/およびZoomとの統合のために、必要に応じて選択してください。そして、再度「続ける」をクリックします。

設定を完了するをクリックしてください。

プロセスが完了すると、次のようなMattermostダッシュボードが表示されます:

結論

おめでとうございます!Debian 12サーバーにMattermostのインストールが完了しました。Mattermostは、データベースとしてPostgreSQL、リバースプロキシとしてNginxを使用して稼働しています。また、CertbotとLetsencryptを使用してHTTPSでMattermostを保護しました。次のステップとして、メール通知を可能にするために、MattermostインストールにSMTPサーバーを追加する必要があります。さらに、Mattermostをサードパーティのアプリケーションと統合することもできます。

関連記事: