ウェブサイト検索

Alma Linux 8にMattermostをインストールする方法


Alma Linux 8にMattermostをインストールする方法

このページで

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

Mattermostは、コミュニケーション、コラボレーション、ツールやチーム間のワークフローオーケストレーションのための無料でオープンソース、かつ安全なプラットフォームです。これは、組織や企業が内部チャットサービスを実装するために設計された自己ホスト型チャットサービスです。1対1のメッセージング、無制限の検索履歴、ファイル共有、二要素認証、通知など、いくつかの便利な機能を提供しています。Slackの代替ソリューションを探しているなら、Mattermostが最適な選択です。

このチュートリアルでは、Alma Linux 8にNginxを使用してMattermostをインストールする方法を示します。

前提条件

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

MySQLサーバーをインストールする

MattermostはMySQLをデータベースバックエンドとして使用しています。したがって、MySQLはサーバーにインストールする必要があります。次のコマンドを実行することでインストールできます:

dnf install mysql-server -y

MySQLサーバーがインストールされたら、次のコマンドでMySQLサービスを開始し、有効にします。

systemctl start mysqld
systemctl enable mysqld

今、次のスクリプトを実行することでMySQLのインストールを安全にすることができます:

mysql_secure_installation

MySQLのルートパスワードを設定し、インストールを保護するために、以下に示されているようにすべての質問に回答してください。

Press y|Y for Yes, any other key for No: N
Please set the password for root here.
New password: 
Re-enter new password: 
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y

Mattermostのデータベースを作成する

次に、Mattermostのためにデータベースとユーザーを作成する必要があります。まず、以下のコマンドを使ってMySQLにログインしてください。

mysql -u root -p

ログインしたら、次のコマンドでデータベースとユーザーを作成します:

mysql> CREATE DATABASE matterdb;
mysql> CREATE USER 'matteruser'@'localhost' IDENTIFIED BY 'password';

次に、Mattermostデータベースにすべての特権を付与します:

mysql> GRANT ALL PRIVILEGES ON matterdb.* TO matteruser@localhost;

次に、特権をフラッシュし、次のコマンドでMySQLから退出します:

mysql> FLUSH PRIVILEGES;
mysql> EXIT;

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

Alma Linux 8に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 -xf mattermost-6.0.2-linux-amd64.tar.gz

次に、抽出したディレクトリを /opt に移動します:

mv mattermost /opt

次に、Mattermostのためにデータディレクトリを作成し、Mattermostの所有権と権限を変更します:

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

次に、Mattermostの構成ファイルを編集します。

nano /opt/mattermost/config/config.json

MattermostのウェブサイトURLを以下のように定義します:

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

次に、次の行を見つけます:

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

そして、次の行に置き換えました:

    "DriverName": "mysql",
    "DataSource": "matteruser:password@tcp(localhost:3306)/matterdb?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: disabled)
   Active: active (running) since Sat 2022-01-15 14:12:29 UTC; 7s ago
 Main PID: 15201 (mattermost)
    Tasks: 32 (limit: 11411)
   Memory: 265.2M
   CGroup: /system.slice/mattermost.service
           ??15201 /opt/mattermost/bin/mattermost
           ??15298 plugins/com.mattermost.plugin-channel-export/server/dist/plugin-linux-amd64
           ??15299 plugins/com.mattermost.nps/server/dist/plugin-linux-amd64
           ??15308 plugins/playbooks/server/dist/plugin-linux-amd64
           ??15313 plugins/focalboard/server/dist/plugin-linux-amd64

Jan 15 14:12:26 almalinux8 mattermost[15201]: {"timestamp":"2022-01-15 14:12:26.344 Z","level":"info","msg":"Sent notification of next survey>
Jan 15 14:12:26 almalinux8 mattermost[15201]: {"timestamp":"2022-01-15 14:12:26.402 Z","level":"info","msg":"Post.Message has size restrictio>
Jan 15 14:12:26 almalinux8 mattermost[15201]: {"timestamp":"2022-01-15 14:12:26.499 Z","level":"info","msg":"info [2022-01-15 14:12:26.497 Z]>
Jan 15 14:12:26 almalinux8 mattermost[15201]: {"timestamp":"2022-01-15 14:12:26.537 Z","level":"info","msg":"\n    -- collation of mattermost>
Jan 15 14:12:28 almalinux8 mattermost[15201]: {"timestamp":"2022-01-15 14:12:28.297 Z","level":"info","msg":"debug [2022-01-15 14:12:28.295 Z>
Jan 15 14:12:28 almalinux8 mattermost[15201]: {"timestamp":"2022-01-15 14:12:28.804 Z","level":"info","msg":"info [2022-01-15 14:12:28.803 Z]>
Jan 15 14:12:29 almalinux8 systemd[1]: Started Mattermost.
Jan 15 14:12:29 almalinux8 mattermost[15201]: {"timestamp":"2022-01-15 14:12:29.149 Z","level":"info","msg":"Starting Server...","caller":"ap>
Jan 15 14:12:29 almalinux8 mattermost[15201]: {"timestamp":"2022-01-15 14:12:29.150 Z","level":"info","msg":"Server is listening on [::]:8065>
Jan 15 14:12:29 almalinux8 mattermost[15201]: {"timestamp":"2022-01-15 14:12:29.150 Z","level":"info","msg":"Sending systemd READY notificati>

この時点で、Mattermostは起動してポート8065で実行されています。次のコマンドで確認できます:

ss -antpl | grep 8065

次の出力が得られます:

LISTEN 0      128                *:8065             *:*    users:(("mattermost",pid=15201,fd=35))                   

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

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

MattermostのリバースプロキシとしてNginxをインストールして構成することを推奨します。そのためには、サーバーにNginxサーバーをインストールする必要があります。以下のコマンドを実行してインストールできます:

dnf install nginx -y

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

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

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

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

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
	proxy_pass http://localhost:8065/;
            index  index.html index.htm;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

ファイルを保存して閉じたら、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
systemctl enable nginx

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

systemctl status nginx

次の出力が得られます:

? nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2022-01-15 14:14:05 UTC; 7s ago
  Process: 15356 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 15354 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 15351 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 15358 (nginx)
    Tasks: 2 (limit: 11411)
   Memory: 3.8M
   CGroup: /system.slice/nginx.service
           ??15358 nginx: master process /usr/sbin/nginx
           ??15359 nginx: worker process

Jan 15 14:14:05 almalinux8 systemd[1]: nginx.service: Succeeded.
Jan 15 14:14:05 almalinux8 systemd[1]: Stopped The nginx HTTP and reverse proxy server.
Jan 15 14:14:05 almalinux8 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jan 15 14:14:05 almalinux8 nginx[15354]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jan 15 14:14:05 almalinux8 nginx[15354]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jan 15 14:14:05 almalinux8 systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Jan 15 14:14:05 almalinux8 systemd[1]: Started The nginx HTTP and reverse proxy server.

この時点で、Nginxはインストールされ、Mattermostを提供するように設定されています。次のステップに進むことができます。

ファイアウォールを設定する

次に、ファイアウォールを通過するポート80を許可する必要があります。以下のコマンドを実行することで許可できます。

firewall-cmd --add-service=http --permanent

次に、変更を適用するためにファイアウォールを再読み込みしてください。

firewall-cmd --reload

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

MattermostのWeb UIにアクセスする

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

メールアドレス、管理者ユーザー名、パスワードを入力し、アカウント作成 ボタンをクリックしてください。次の画面が表示されます:

チーム を作成 する をクリックしてください。次の画面が表示されます:

チーム名を入力し、次へボタンをクリックしてください。次の画面が表示されます:

MattermostチームのURLを入力し、完了ボタンをクリックしてください。次の画面にMattermostダッシュボードが表示されます:

結論

上記のガイドでは、Alma Linux 8にNginxを使用してMattermostチャットサービスをインストールする方法を学びました。これで、あなたの組織でMattermostを実装し、内部チャットとして使用を開始できます。質問があれば気軽にお尋ねください。

関連記事: