ウェブサイト検索

CentOS 7 に PostgreSQL と Nginx を使用して Mattermost をインストールする


Slack の代替手段。 Mattermost は、ファイアウォールの内側で行われる最新の通信です。

独自の SaaS メッセージングの代替として、Mattermost はチームのすべてのコミュニケーションを 1 か所に集め、どこからでも検索してアクセスできるようにします。

Mattermost は「Slack 限定ではなく Slack 互換」であり、既存の Slack 統合との互換性を含む、Slack の受信および送信 Webhook 統合のスーパーセットをサポートしています。既存の Slack チームから、ユーザー、パブリック チャンネル履歴、さらにはテーマ設定をインポートできます。 Mattermost に色を追加します。

この HowTo 内で使用される名前、変数、およびアカウント

local IP of server                 : 192.168.2.100
FQDN of server : mattermost.example.com
Name of mattermost database : mattermost
User to access mattermost database : mmuser
Password for mmuser within database: DBAss47slX3

前提条件

この Howto では、データベース バックエンドとして PostgreSQL を使用して CentOS7 に Mattermost をインストールする方法について説明します。このガイドでは、すべてを 1 台のサーバーにインストールすると仮定しますが、経験豊富なユーザーであれば、部品を分解して各コンポーネント (データベース サーバーなど) を別のマシンにインストールすることも簡単です。インストールはユーザーrootを使用して行われていますが、 もちろんsudo が有効なユーザーを使用することもできます。

また、サーバーの IP アドレスが 192.168.2.100 であり、DNS が mattermost.example.com に解決されると仮定します。したがって、この HowTo の中で 192.168.2.100 または mattermost.example.com と書かれている箇所は、サーバーの IP アドレスに置き換えてください。

開始する前に、CentOS7 の最小限のインストールが必要です。インストール後、システムが (スマート ホストまたは同様のソリューション経由で) 電子メールを送信できるように、電子メールが正しく設定されていること (postfix 構成) を確認してください。

続行する前に、いくつかの小さなチェックを行ってください。

サーバー上の端末からメールを送信してみます。

[

( [email をサーバーが送信できるメール アドレスに置き換えます)。システムからメールが届いたことを確認してください。

mattermost.example.com の名前解決を確認する

別のコンピューター (セットアップしようとしているサーバーではありません) から、mattermost.example.com に ping を実行してみます。肯定的な結果が得られるはずです。

C:\>ping mattermost.example.com
Pinging mattermost.witron.com [192.168.2.100] with 32 bytes of data:
Reply from 192.168.2.100: bytes=32 time<1ms TTL=64
Reply from 192.168.2.100: bytes=32 time<1ms TTL=64
Reply from 192.168.2.100: bytes=32 time<1ms TTL=64
Reply from 192.168.2.100: bytes=32 time<1ms TTL=64

Ping statistics for 192.168.2.100:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms

インターネット接続を確認する

ここで、wget パッケージをインストールします (後で必要になります)。

[ ~] yum -y install wget

そしてそれを使用してパブリック IP を決定します。したがって、インターネット接続を確認できます。

[ ~] wget http://ipinfo.io/ip -qO -
46.101.122.124

結果はパブリック IP アドレスになるはずです。

ファイアウォールのステータスを確認し、今は無効にしてください

CentOS7 インストールでファイアウォールが有効になっているかどうかを確認してください。これを確認するには、次のように入力します。

[ ~] systemctl status firewalld

次のようなものが表示された場合

アクティブ: ... 以降アクティブ (実行中)

この 2 つのコマンドを使用して、それをオフにして無効にしてください。

[ ~] systemctl disable firewalld

このチュートリアルの最後には、firewalld を再度有効にする方法と、Mattermost で動作するように正しく設定する方法が記載されています。

上記のチェックをすべてパスした場合、またはこのチュートリアルに使用できるシステムがあることがわかっている場合は、今すぐ続行できます。

PostgreSQLデータベースサーバーをインストールする

Mattermost のデータベース バックエンドとして PostgreSQL を使用します。次のコマンドを使用してインストールします。

[ ~] yum -y install postgresql-server postgresql-contrib

インストール後、データベースを初期化する必要があります。

[ ~] postgresql-setup initdb
Initializing database ... OK

次に、PostgreSQL を起動し、自動起動を有効にします。

[ ~]# systemctl enable postgresql
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql.service to /usr/lib/systemd/system/postgresql.service.

を実行して、PostgreSQL が実行されていることを確認してください。

[ ~]# systemctl status postgresql

これと同様の内容が報告されるはずです ( テキストのどこかにアクティブ: アクティブ (実行中) があることを確認してください)。

? postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2016-03-04 11:37:50 CET; 44s ago
Main PID: 17660 (postgres)
CGroup: /system.slice/postgresql.service
??17660 /usr/bin/postgres -D /var/lib/pgsql/data -p 5432
??17661 postgres: logger process
??17663 postgres: checkpointer process
??17664 postgres: writer process
??17665 postgres: wal writer process
??17666 postgres: autovacuum launcher process
??17667 postgres: stats collector process

Mar 04 11:37:48 mattermost systemd[1]: Starting PostgreSQL database server...
Mar 04 11:37:50 mattermost systemd[1]: Started PostgreSQL database server.
Mar 04 11:37:59 mattermost systemd[1]: Started PostgreSQL database server.

mattermost データベースとデータベース ユーザーを作成する

PostgreSQL は、postgres という名前のユーザーとグループを自動的に作成しました。ユーザー postgres を使用してデータベース エンジンに接続し、データベースとそれにアクセスできるユーザーをセットアップします。

ユーザー postgres としてプロンプトを開始します。

[ ~]# sudo -i -u postgres

プロンプトは次のように変わります。

-bash-4.2$

次に、データベースサーバーに接続してみましょう。

-bash-4.2$ psql
psql (9.2.15)
Type "help" for help.
postgres=#

PostgreSQL プロンプト内で、mattermost という名前のデータベースを作成します。

postgres=# CREATE DATABASE mattermost;
CREATE DATABASE

次に、パスワード DBAss47slX3 を持つユーザー mmuser を作成します。

postgres=# CREATE USER mmuser WITH PASSWORD 'DBAss47slX3';
CREATE ROLE

次のように入力して、ユーザーに Mattermost データベースへのアクセスを許可します。

postgres=# GRANT ALL PRIVILEGES ON DATABASE mattermost to mmuser;
GRANT
postgres=#

次に、次のように入力してPostgreSQL プロンプトを終了します。

postgres=# \q
-bash-4.2$

次に、 ユーザー postgres として開始したシェルを終了します。

-bash-4.2$ exit
logout
[ ~]#

ユーザー名/パスワードによるローカルホストからの PostgreSQL データベースへのアクセスを許可します。

その後、重要なインスタンスは PostgreSQL データベースと通信し、ユーザー名とパスワードで認証したいと考えています。これを可能にするには、PostgreSQL の構成を少し変更する必要があります。ファイルを開きます:

vi /var/lib/pgsql/data/pg_hba.conf

vi や nano などのエディタを使用して次の行を変更します。

host    all             all             127.0.0.1/32            ident

に:

host    all             all             127.0.0.1/32            md5

ファイルを保存して、Postgresql を再起動します。

[ ~]# systemctl restart postgresql

以前に作成したユーザーとパスワードを使用してデータベース サーバーに接続し、それが正しく行われたことを確認する必要があります (サーバーで別のパスワードを使用している場合は、そのパスワードを使用してください)。

[ ~]#

PostgreSQL サーバーとデータベースは Mattermost に対応できるようになりました。

Mattermost をダウンロードして抽出する

wget を使用して、GitHub リポジトリ (このチュートリアルの作成時点ではバージョン v2.0.0 が最新バージョンでした) から Mattermost サーバー ディレクトリのコピーをダウンロードしてみましょう。

[ ~]# wget -q "https://github.com/mattermost/platform/releases/download/v2.0.0/mattermost.tar.gz" -O mattermost.tar.gz

次に、アーカイブを抽出し、抽出されたファイルをターゲットの場所 (この場合は /opt/mattermost を使用します) に置きます。

[ ~]# mv mattermost /opt

Mattermost のインストール

Mattermost デーモンを実行するユーザーを作成する

後で、Mattermost をデーモンとして実行します。したがって、システム上にmattermostという名前の新しいユーザーを設定します。最も重要なインスタンスは後で実行されます。次のコマンドを実行して、システム ユーザーとグループmattermostを作成します。

[ ~]# useradd -r mattermost -U -s /sbin/nologin

Mattermostのデータ保存フォルダーを作成する

Mattermost は、データの一部を保存したいと考えています。フォルダー内にファイルなどをアップロードします。したがって、そのフォルダーを作成する必要があります。ハードドライブ上のどこにでも置くことができますが、 ユーザーが最も重要にアクセスできる必要があります。 /opt/mattermost/data を使用することにしました。次のコマンドでフォルダーを作成します。

[ ~]# mkdir -p /opt/mattermost/data

mattermost ディレクトリの所有者を設定する

次に、mattermost ディレクトリのグループと所有者を、以前に作成したユーザーとグループに設定します。

[ ~]# chmod -R g+w /opt/mattermost

mattermost のデータベース接続を構成する

Mattermost が PostgreSQL データベースに接続する方法を指示するには、構成ファイルを編集する必要があります。

/opt/mattermost/config/config.json

SqlSettings セクションを見つけて、必要に応じて変更してください。

"SqlSettings": {
"DriverName": "mysql",
"DataSource": "mmuser:(dockerhost:3306)/mattermost_test?charset=utf8mb4,utf8",
"DataSourceReplicas": [],
"MaxIdleConns": 10,
"MaxOpenConns": 10,
"Trace": false,
"AtRestEncryptKey": "7rAh6iwQCkV4cA1Gsg3fgGOXJAQ43QVg"
},

その後

"SqlSettings": {
"DriverName": "postgres",
"DataSource": "postgres://mmuser::5432/mattermost?sslmode=disable&connect_timeout=10",
"DataSourceReplicas": [],
"MaxIdleConns": 10,
"MaxOpenConns": 10,
"Trace": false,
"AtRestEncryptKey": "7rAh6iwQCkV4cA1Gsg3fgGOXJAQ43QVg"
},

AtRestEncryptKey はそのままにしておいても問題ありません。

mattermost の電子メール接続を構成する

再度、設定ファイルを編集する必要があります

/opt/mattermost/config/config.json

[EmailSettings] セクションを見つけて、必要に応じて変更します。

 "EmailSettings": {
"EnableSignUpWithEmail": true,
"EnableSignInWithEmail": true,
"EnableSignInWithUsername": false,
"SendEmailNotifications": false,
"RequireEmailVerification": false,
"FeedbackName": "",
"FeedbackEmail": "",
"SMTPUsername": "",
"SMTPPassword": "",
"SMTPServer": "",
"SMTPPort": "",
"ConnectionSecurity": "",
"InviteSalt": "bjlSR4QqkXFBr7TP4oDzlfZmcNuH9YoS",
"PasswordResetSalt": "vZ4DcKyVVRlKHHJpexcuXzojkE5PZ5eL",
"SendPushNotifications": false,
"PushNotificationServer":
},

その後

 "EmailSettings": {
"EnableSignUpWithEmail": true,
"EnableSignInWithEmail": true,
"EnableSignInWithUsername": false,
"SendEmailNotifications": false,
"RequireEmailVerification": false,
"FeedbackName": "",
"FeedbackEmail": "",
"SMTPUsername": "",
"SMTPPassword": "",
"SMTPServer": "127.0.0.1",
"SMTPPort": "25",
"ConnectionSecurity": "",
"InviteSalt": "bjlSR4QqkXFBr7TP4oDzlfZmcNuH9YoS",
"PasswordResetSalt": "vZ4DcKyVVRlKHHJpexcuXzojkE5PZ5eL",
"SendPushNotifications": false,
"PushNotificationServer": ""
},

外部に電子メールを送信できるようにすでに構成されているローカル postfix インストールを使用しているため、127.0.0.1 とポート 25 を使用します。ここでの設定が異なる場合は、正しい値を設定する必要があります。

内部インターフェイス (127.0.0.1) でのみリッスンするように mattermost を設定する

デフォルトでは、mattermost サーバー インスタンスはポート 8065 (:8065) 上のすべてのインターフェイスをリッスンします。 Nginx サーバーを mattermost の前に置きたいため、ローカルホスト (127.0.0.1:8065) でのみリッスンするようにこの動作を変更します。

ラインを変えるだけ

        "ListenAddress": ":8065",

        "ListenAddress": "127.0.0.1:8065",

config.json ファイル内。

Mattermost サーバーをテストする

コマンド ラインから実行して、mattermost サーバーが起動するかどうかをテストできるようになりました。ユーザーが最も重要なこととしてこれを行うようにしてください。誤って root としてこれを実行した場合は、mattermost フォルダーのアクセス許可を再度修正する必要があります。

[ ~]# su - mattermost -s /bin/bash

Last login: Fri Mar 4 12:47:52 CET 2016 on pts/0
su: warning: cannot change directory to /home/mattermost: No such file or directory
-bash-4.2$

ここで、最も重要なインストール ディレクトリに移動します。

-bash-4.2$ cd /opt/mattermost/bin/

そして、コマンドラインから mattermost を実行します。

-bash-4.2$ ./platform

出力は次のようになります。

[2016/03/04 13:00:10 CET] [INFO] Loaded system translations for 'en' from '/opt/mattermost/i18n/en.json'
[2016/03/04 13:00:10 CET] [INFO] Current version is 2.0.0 (5950/Sat Feb 13 15:42:01 UTC 2016/c71c5cef632c7dc68072167c6fe091a60835fa02)
[2016/03/04 13:00:10 CET] [INFO] Enterprise Enabled: false
[2016/03/04 13:00:10 CET] [INFO] Current working directory is /opt/mattermost/bin
[2016/03/04 13:00:10 CET] [INFO] Loaded config file from /opt/mattermost/config/config.json
[2016/03/04 13:00:10 CET] [INFO] Server is initializing...
[2016/03/04 13:00:10 CET] [INFO] Pinging sql master database
[2016/03/04 13:00:10 CET] [INFO] Pinging sql replica-0 database
[2016/03/04 13:00:10 CET] [DEBG] Deleting any unused pre-release features
[2016/03/04 13:00:10 CET] [INFO] The database schema has been set to version 2.0.0
[2016/03/04 13:00:10 CET] [DEBG] Initializing user api routes
[2016/03/04 13:00:10 CET] [DEBG] Initializing team api routes
[2016/03/04 13:00:10 CET] [DEBG] Initializing channel api routes
[2016/03/04 13:00:10 CET] [DEBG] Initializing post api routes
[2016/03/04 13:00:10 CET] [DEBG] Initializing web socket api routes
[2016/03/04 13:00:10 CET] [DEBG] Initializing file api routes
[2016/03/04 13:00:10 CET] [DEBG] Initializing command api routes
[2016/03/04 13:00:10 CET] [DEBG] Initializing admin api routes
[2016/03/04 13:00:10 CET] [DEBG] Initializing oauth api routes
[2016/03/04 13:00:10 CET] [DEBG] Initializing webhook api routes
[2016/03/04 13:00:10 CET] [DEBG] Initializing preference api routes
[2016/03/04 13:00:10 CET] [DEBG] Initializing license api routes
[2016/03/04 13:00:10 CET] [DEBG] Parsing server templates at /opt/mattermost/api/templates/
[2016/03/04 13:00:10 CET] [DEBG] Initializing web routes
[2016/03/04 13:00:10 CET] [DEBG] Using static directory at /opt/mattermost/web/static/
[2016/03/04 13:00:10 CET] [DEBG] Parsing templates at /opt/mattermost/web/templates/
[2016/03/04 13:00:10 CET] [INFO] Starting Server...
[2016/03/04 13:00:10 CET] [INFO] Server is listening on 127.0.0.1:8065
[2016/03/04 13:00:10 CET] [INFO] RateLimiter is enabled
[2016/03/04 13:00:10 CET] [DEBG] Checking for security update from Mattermost
[2016/03/04 13:00:10 CET] [EROR] Failed to get security update information from Mattermost.

Ctrl+C で重要なサーバーを停止します

次に、ユーザー mattermost として開始したシェルを終了します。

-bash-4.2$ exit
logout
[ ~]#

最も重要なインスタンスが起動しない場合は、出力を注意深く読んでください。私自身、config.json 内の単純なカンマを忘れたため、多くの問題を抱えていました。また、dbusers パスワードに特殊文字、特に @ 記号を使用しないようにしてください。最初はそれが私を奇妙にさせました!

上記のコマンドを誤って root として実行し、それが機能する可能性がある場合は、mattermost フォルダーのアクセス許可を再修正する必要があります。この間違いに遭遇した場合は、次のコマンドを使用してください。

[ ~]# chown -R mattermost:mattermost /opt/mattermost

すべてがうまくいけば、続行できます。

Mattermost をデーモンとしてセットアップする

Mattermost をデーモンとして設定するには、ファイルを作成します

/etc/systemd/system/mattermost.service

次の内容で:

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

[Service]
Type=simple
WorkingDirectory=/opt/mattermost/bin
User=mattermost
ExecStart=/opt/mattermost/bin/platform
PIDFile=/var/spool/mattermost/pid/master.pid

[Install]
WantedBy=multi-user.target

次に、次のコマンドを使用してデーモン ファイルをリロードします。

[ ~]# systemctl daemon-reload

これまでと同様に、 このサービスを開始/停止/有効化/無効化できるようになりました。

それでは、Mattermost を起動し、ステータスを取得して、サービスとして有効にしてみましょう (自動起動)。

mattermost デーモンを開始

[ ~]# systemctl start mattermost.service

重要なステータスを確認する

[ ~]# systemctl status mattermost.service
? mattermost.service - Mattermost
Loaded: loaded (/etc/systemd/system/mattermost.service; disabled; vendor preset: disabled)
Active: active (running) since Fri 2016-03-04 14:03:40 CET; 4s ago
Main PID: 18573 (platform)
CGroup: /system.slice/mattermost.service
??18573 /opt/mattermost/bin/platform
...
...

それがアクティブ(実行中)であることを確認してください。

デーモンの自動起動を有効にする

[ ~]# systemctl enable mattermost.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mattermost.service to /etc/systemd/system/mattermost.service.

ここで、念のため、次のコマンドを実行して、Mattermost が 127.0.0.1:8065 をリッスンしているかどうかをテストします。

[ config]# curl -s "http://127.0.0.1:8065" | grep -b "2015 Mattermost"

2015 Mattermost を含む 1 行を取得する必要があります。

11343:        <span class="pull-right footer-link copyright">© 2015 Mattermost, Inc.</span>

そうであれば、Mattermost サーバー インスタンスが実行されていると確信できるので、続行できます。


SELinux 関連の権限の問題を修正する

CentOS7 では、SELinux はデフォルトで有効になっています。これを完全に無効にすることもできますが、再構成して Mattermost サーバーが実行できるようにすることをお勧めします。

次の 2 つのコマンドを入力するだけで SELinux 権限を修正できます。

[ config]# setsebool -P httpd_can_network_connect 1

Nginxサーバーのセットアップ

Nginx サーバーを Mattermost サーバー インスタンスの前に配置します。

主な利点は次のとおりです。

  • ポートマッピング:80から:8065
  • 標準リクエストログ
  • 後で SSL に切り替えるときのその他のオプション

epel リポジトリを有効にする

Nginx は CentOS のデフォルトのリポジトリには含まれていません。したがって、最初に epel リポジトリを有効にする必要があります。これは簡単な作業です。次のように入力するだけです。

[ config]# yum -y install epel-release && yum update

nginxをインストールする

epel-release を有効にしたら、次のコマンドを使用して nginx をインストールするだけです。

[ config]# yum -y install nginx

これにより、nginx とそのすべての依存関係がインストールされます。

nginxの設定

Nginx を構成するにはさまざまな方法があります。このチュートリアルでは、Mattermost サーバーをポート 80 でホストするだけの非常に単純な Nginx セットアップを作成する方法のみを説明します。

Nginx のデフォルト設定ファイルを変更する

次のコマンドを実行して、現在の nginx.conf のバックアップを作成します。

[ config]# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak

次に、 /etc/nginx/nginx.conf を次の内容に置き換えます。

# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
worker_connections 1024;
}

http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;

include /etc/nginx/mime.types;
default_type application/octet-stream;

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

server {
server_name mattermost.example.com;
location / {
client_max_body_size 50M;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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_pass http://127.0.0.1:8065;
}
}
}

このドキュメントで前述したように、正しいホスト名を使用していることを確認してください。

構成ファイルに構文エラーがないことを確認するには、次のコマンドを実行して構文をチェックします。

[ config]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Nginx をデーモンとして起動して有効にする

Nginx を開始

[ config]# systemctl start nginx

ステータスを確認する

[ config]# systemctl status nginx

少なくとも以下を示す行が出力されることを確認してください。

...
Active: active (running)...
...

デーモンとして有効にする

[ config]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

すべてがうまくいけば、Mattermost インストールが Nginx の背後で実行されているはずです。ブラウザで次の URL を開いて確認してください。

Mattermost のログイン画面が表示されます。

これで、電子メール アドレスを入力してアカウントを作成し、Mattermost インストールのセットアップを続けることができます。

ファイアウォール

このチュートリアルの前半で、firewalld を無効にしました。再度有効にしたいが、ポート 80 (現在 Nginx 経由で Mattermost に使用している) を開いたままにしておきたい場合は、次の手順を実行します。

Firewalld を起動して再度有効にします

[ config]# systemctl enable firewalld
Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/basic.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.

ファイアウォールでポート 80 を開きます

[ config]# firewall-cmd --reload
success

これで、Firewalld が実行されていても、Mattermost インストールにアクセスできるようになります。

まとめ

このチュートリアルが役に立ち、うまくいったと思っていただければ幸いです。本番環境では、Mattermost ウェブサイトの証明書を作成/使用し、Nginx を介して https を有効にする必要があります。これは、この Howto を少し変更するだけで簡単に実現できます。

関連記事: