ウェブサイト検索

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


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

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

  • Debian 11 (Bullseye)
  • Debian 10 (バスター)

このページで

  1. 前提条件
  2. MariaDBデータベースサーバーのインストールと設定
  3. Mattermostをインストールする
  4. MattermostのためのSystemdサービスファイルを作成する
  5. MattermostのリバースプロキシとしてNginxを構成する
  6. MattermostのWebインターフェースにアクセスする
  7. 結論

Mattermostはセキュリティを考慮して作られた無料のオープンソースのコラボレーションおよびメッセージングプラットフォームです。これは、DiscordやSlackの代替であり、1対1のメッセージング、無制限の検索履歴やファイル共有機能、二要素認証、通知など、多くの便利な機能を提供します。GolangとReactで書かれた自己ホスト型のオンラインチャットサービスです。特に組織や企業向けに設計されており、チームがどこからでも安全にコミュニケーションできるようにします。

このチュートリアルでは、Debian 11 に Mattermost チャットサーバーをインストールする方法を示します。

前提条件

  • Debian 11を実行しているサーバー。
  • サーバーIPにポイントされた有効なドメイン名。
  • サーバーにはルートパスワードが設定されています。

MariaDBデータベースサーバーのインストールと設定

Mattermostは、データベースバックエンドとしてMySQLまたはMariaDBを使用します。そのため、MariaDBサーバーをあなたのサーバーにインストールする必要があります。以下のコマンドを使用してインストールできます:

apt-get install mariadb-server -y

MariaDBがインストールされたら、MariaDBサービスを起動し、システム再起動時に自動起動するように設定します:

systemctl start mariadb
systemctl enable mariadb

次に、以下のコマンドを使ってMariaDBシェルに接続します:

mysql

接続されたら、次のコマンドを使用してデータベースとユーザーを作成します:

MariaDB [(none)]> create database mattermost;
MariaDB [(none)]> create user mattermost@localhost identified by 'password';

次に、次のコマンドを使用してMattermostデータベースにすべての権限を付与します:

MariaDB [(none)]> grant all privileges on mattermost.* to mattermost@localhost;

次に、次のコマンドを使用して権限をフラッシュし、MariaDBシェルから退出します:

MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;

完了したら、次のステップに進むことができます。

Mattermostをインストールする

まず、次のコマンドを使用してMattermost用の専用ユーザーを作成します。

useradd --system --user-group mattermost

次に、以下のコマンドを使用してMattermostの最新バージョンをダウンロードします:

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

ダウンロードが完了したら、以下のコマンドでダウンロードしたファイルを展開します:

tar -xvzf mattermost-6.0.2-linux-amd64.tar.gz

次に、以下のコマンドを使って抽出したディレクトリを /opt に移動します:

mv mattermost /opt

次に、次のコマンドを使用してmattermostのデータディレクトリを作成します:

mkdir /opt/mattermost/data

次に、以下のコマンドでmattermostディレクトリの所有権を変更します。

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

次に、以下のコマンドでconfig.jsonファイルを編集します:

nano /opt/mattermost/config/config.json

次の行を見つけてください:

    "DriverName": "postgres",
    "DataSource": "postgres://mmuser:mostest@localhost/mattermost_test?sslmode=disable&connect_timeout=10",

そして、あなたのデータベース設定に従って、次の行に置き換えました。

"DriverName": "mysql",
"DataSource": "mattermost:password@tcp(127.0.0.1:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s",

作業が完了したら、ファイルを保存して閉じてください。

MattermostのためのSystemdサービスファイルを作成する

次に、Mattermostのためのsystemdサービスファイルを作成する必要があります。以下のコマンドを使用して作成できます:

nano /etc/systemd/system/mattermost.service

次の行を追加してください:

[Unit]
Description=Mattermost
After=syslog.target network.target mysqld.service

[Service]
Type=notify
WorkingDirectory=/opt/mattermost
User=mattermost
ExecStart=/opt/mattermost/bin/mattermost
PIDFile=/var/spool/mattermost/pid/master.pid
TimeoutStartSec=3600
LimitNOFILE=49152

[Install]
WantedBy=multi-user.target

ファイルを保存して閉じたら、変更を適用するためにsystemdデーモンを再読み込みします:

systemctl daemon-reload

次に、Mattermostを起動し、システム再起動時に自動的に起動するように設定します:

systemctl start mattermost
systemctl enable mattermost

次に、以下のコマンドを使用してMattermostのステータスを確認してください:

systemctl status mattermost

次の出力が得られます:

? mattermost.service - Mattermost
     Loaded: loaded (/etc/systemd/system/mattermost.service; disabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-11-12 13:56:25 UTC; 4s ago
   Main PID: 2888 (mattermost)
      Tasks: 31 (limit: 4679)
     Memory: 273.3M
        CPU: 12.191s
     CGroup: /system.slice/mattermost.service
             ??2888 /opt/mattermost/bin/mattermost
             ??2915 plugins/com.mattermost.plugin-channel-export/server/dist/plugin-linux-amd64
             ??2925 plugins/playbooks/server/dist/plugin-linux-amd64
             ??2931 plugins/focalboard/server/dist/plugin-linux-amd64

Nov 12 13:56:24 debian11 mattermost[2888]: {"timestamp":"2021-11-12 13:56:24.681 Z","level":"info","msg":"Scheduling next survey for Dec 3, 2>
Nov 12 13:56:25 debian11 mattermost[2888]: {"timestamp":"2021-11-12 13:56:25.064 Z","level":"info","msg":"Post.Message has size restrictions">
Nov 12 13:56:25 debian11 mattermost[2888]: {"timestamp":"2021-11-12 13:56:25.084 Z","level":"info","msg":"info [2021-11-12 13:56:25.083 Z] co>
Nov 12 13:56:25 debian11 mattermost[2888]: {"timestamp":"2021-11-12 13:56:25.131 Z","level":"info","msg":"\n    -- collation of mattermost's >
Nov 12 13:56:25 debian11 mattermost[2888]: {"timestamp":"2021-11-12 13:56:25.491 Z","level":"info","msg":"debug [2021-11-12 13:56:25.488 Z] i>
Nov 12 13:56:25 debian11 mattermost[2888]: {"timestamp":"2021-11-12 13:56:25.777 Z","level":"info","msg":"info [2021-11-12 13:56:25.777 Z] Se>
Nov 12 13:56:25 debian11 mattermost[2888]: {"timestamp":"2021-11-12 13:56:25.963 Z","level":"info","msg":"Starting Server...","caller":"app/s>
Nov 12 13:56:25 debian11 mattermost[2888]: {"timestamp":"2021-11-12 13:56:25.964 Z","level":"info","msg":"Server is listening on [::]:8065",">
Nov 12 13:56:25 debian11 mattermost[2888]: {"timestamp":"2021-11-12 13:56:25.964 Z","level":"info","msg":"Sending systemd READY notification.>
Nov 12 13:56:25 debian11 systemd[1]: Started Mattermost.

MattermostのリバースプロキシとしてNginxを構成する

デフォルトでは、Mattermostはポート8065でリッスンします。したがって、ポート80でMattermostにアクセスするためにNginxをリバースプロキシとしてインストールし構成するのが良い考えです。まず、次のコマンドでNginxをインストールしてください。

apt-get install nginx -y

Nginxがインストールされたら、次のコマンドでNginxの仮想ホスト設定ファイルを作成します:

nano /etc/nginx/conf.d/mattermost.conf

次の行を追加してください:

upstream mattermost {
   server localhost:8065;
   keepalive 32;
}

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=mattermost_cache:10m max_size=3g inactive=120m use_temp_path=off;

server {
   listen 80;
   server_name mattermost.example.com;

   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 $http_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 60;
       send_timeout 300;
       lingering_timeout 5;
       proxy_connect_timeout 90;
       proxy_send_timeout 300;
       proxy_read_timeout 90s;
       proxy_pass http://mattermost;
   }

   location / {
       client_max_body_size 50M;
       proxy_set_header Connection "";
       proxy_set_header Host $http_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_cache mattermost_cache;
       proxy_cache_revalidate on;
       proxy_cache_min_uses 2;
       proxy_cache_use_stale timeout;
       proxy_cache_lock on;
       proxy_http_version 1.1;
       proxy_pass http://mattermost;
   }
}

ファイルを保存して閉じ、その後、次のコマンドを使用してNginxの設定に構文エラーがないか確認してください:

nginx -t

次の出力が表示されるはずです:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

次に、変更を適用するためにNginxサービスを開始します:

systemctl start nginx

次のコマンドを使用して、Nginxのステータスを確認することもできます:

systemctl status nginx

次の出力を得るべきです:

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-11-12 13:57:02 UTC; 1min 12s ago
       Docs: man:nginx(8)
    Process: 3384 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 3392 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 3602 (nginx)
      Tasks: 3 (limit: 4679)
     Memory: 6.6M
        CPU: 55ms
     CGroup: /system.slice/nginx.service
             ??3602 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ??3604 nginx: worker process
             ??3605 nginx: worker process

Nov 12 13:57:01 debian11 systemd[1]: Starting A high performance web server and a reverse proxy server...
Nov 12 13:57:02 debian11 systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Nov 12 13:57:02 debian11 systemd[1]: Started A high performance web server and a reverse proxy server.

この時点で、NginxはMattermostのリバースプロキシとしてインストールされ、設定されています。次のステップに進むことができます。

MattermostのWebインターフェースにアクセスする

今、ウェブブラウザを開いて、URL http://mattermost.example.com を使用してMattermostのウェブインターフェースにアクセスしてください。次のページにリダイレクトされます:

管理者のメールアドレス、ユーザー名、パスワードを提供し、アカウントを作成ボタンをクリックしてください。次のページが表示されるはずです:

次に、システムコンソールに移動をクリックしてください。以下に示すように、Mattermostダッシュボードにリダイレクトされます:

結論

おめでとうございます!あなたはDebian 11上にNginxをリバースプロキシとして使ってMattermostを成功裏にインストールしました。これで、あなたの組織内でMattermostを導入し、チームがどこからでもお互いにコミュニケーションを取れるようになります。

関連記事: