CentOS7.4 Mattermostインストール

シェアする

自前のサーバーに導入できる「Mattermost」「Rocket.Chat」がビジネスチャットとして有名ですが、今回は「Mattermost(マッターモスト)」を導入してみることにしました。

この記事に関して

下記のような構成にしていみます。

[Apache HTTP(ReverseProxy)] – [mattermost] – [MariaDB]

・ReverseProxy
  192.0.20.110 [RPSERV]
・MatterMost
  192.0.20.120 [MMSERV]
・MariaDB
  192.0.20.130 [MDSERV]

なお、ReverseProxyとMariaDBは、すでにある環境なので、ここでは割愛しています。

データベース作成

Mattermostでは、データベースとして、「MySQL」か「Postgres」を利用します。今回は、すでにある「MariaDB」を利用することにしました。

MariaDBサーバー側
# mysql -u root -p
Enter password: rootpass
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 183640
Server version: 10.2.6-MariaDB MariaDB Server


Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create user 'mmuser'@'%' identified by 'mmpass';
Query OK, 0 rows affected (0.10 sec)

MariaDB [(none)]> select user,host from mysql.user where user='mmuser';
+--------+------+
| user   | host |
+--------+------+
| mmuser | %    |
+--------+------+
1 row in set (0.00 sec)

MariaDB [(none)]> create database mattermost;
Query OK, 1 row affected (0.10 sec)

MariaDB [(none)]> show databases like 'mattermost';
+-----------------------+
| Database (mattermost) |
+-----------------------+
| mattermost            |
+-----------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> grant all privileges on mattermost.* to 'mmuser'@'%';
Query OK, 0 rows affected (0.08 sec)

MariaDB [(none)]> exit
Bye
Mattermostサーバー側
# yum remove mariadb-libs
   : (省略)
Removed:
  mariadb.x86_64 1:5.5.56-2.el7
  mariadb-libs.x86_64 1:5.5.56-2.el7

Dependency Removed:
  postfix.x86_64 2:2.10.1-6.el7

Complete!
# vi mariadb.repo
# MariaDB 10.2 CentOS repository list - created 2017-05-25 08:12 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2.6/centos73-amd64/
enabled = 0
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

# yum install MariaDB-client --enablerepo=mariadb <= MariaDBクライアント(なくても良い)
   : (省略)
Installed:
  MariaDB-client.x86_64 0:10.2.6-1.el7.centos

Dependency Installed:
  MariaDB-common.x86_64 0:10.2.6-1.el7.centos  MariaDB-compat.x86_64 0:10.2.6-1.el7.centos
  perl.x86_64 4:5.16.3-292.el7                 perl-Carp.noarch 0:1.26-244.el7
  perl-Encode.x86_64 0:2.51-7.el7              perl-Exporter.noarch 0:5.68-3.el7
  perl-File-Path.noarch 0:2.09-2.el7           perl-File-Temp.noarch 0:0.23.01-3.el7
  perl-Filter.x86_64 0:1.49-3.el7              perl-Getopt-Long.noarch 0:2.40-2.el7
  perl-HTTP-Tiny.noarch 0:0.033-3.el7          perl-PathTools.x86_64 0:3.40-5.el7
  perl-Pod-Escapes.noarch 1:1.04-292.el7       perl-Pod-Perldoc.noarch 0:3.20-4.el7
  perl-Pod-Simple.noarch 1:3.28-4.el7          perl-Pod-Usage.noarch 0:1.63-3.el7
  perl-Scalar-List-Utils.x86_64 0:1.27-248.el7 perl-Socket.x86_64 0:2.010-4.el7
  perl-Storable.x86_64 0:2.45-3.el7            perl-Text-ParseWords.noarch 0:3.29-4.el7
  perl-Time-HiRes.x86_64 4:1.9725-3.el7        perl-Time-Local.noarch 0:1.2300-2.el7
  perl-constant.noarch 0:1.27-2.el7            perl-libs.x86_64 4:5.16.3-292.el7
  perl-macros.x86_64 4:5.16.3-292.el7          perl-parent.noarch 1:0.225-244.el7
  perl-podlators.noarch 0:2.5.1-3.el7          perl-threads.x86_64 0:1.87-4.el7
  perl-threads-shared.x86_64 0:1.43-6.el7

Complete!
# mysql -h DBSERV -u mmuser -p
Enter password: mmpass
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 187681
Server version: 10.2.6-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mattermost         |
+--------------------+
2 rows in set (0.00 sec)

MariaDB [(none)]> exit
Bye

# yum install wget
   : (省略)
Installed:
  wget.x86_64 0:1.14-15.el7_4.1

Complete!
# wget https://releases.mattermost.com/5.5.1/mattermost-5.5.1-linux-amd64.tar.gz -P /tmp
   : (省略)
2018-12-13 22:25:24 (10.8 MB/s) - ‘/tmp/mattermost-5.5.1-linux-amd64.tar.gz’ saved [57359559/57359559]
# cd /tmp
# tar zxvf mattermost-5.5.1-linux-amd64.tar.gz
   : (省略)
mattermost/fonts/
mattermost/fonts/OFL.txt
mattermost/fonts/nunito-bold.ttf
# mv mattermost /opt
# mkdir /opt/mattermost/data
# useradd --system --user-group mattermost <= システムアカウントで作成
# chown -R mattermost:mattermost /opt/mattermost
# chmod -R g+w /opt/mattermost
# cd /opt/mattermost/config
# cp -p config.json config.json.original
# vi config.json
   : (省略)
"ServiceSettings": {
        "SiteURL": "http://RPSERV/chat",
        "WebsocketURL": "",
   : (省略)
"SqlSettings": {
   "DriverName": "mysql",
   "DataSource": "mmuser:mmpass@tcp(DBSERV:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s",
   "DataSourceReplicas": [],
   : (省略)
# cd /opt/mattermost
# su mattermost -c ./bin/mattermost <= ハイフンなしで
{"level":"info","ts":1545021783.9176931,"caller":"utils/i18n.go:78","msg":"Loaded system translations for 'en' from '/opt/mattermost/i18n/en.json'"}
{"level":"info","ts":1545021783.9179206,"caller":"app/app.go:204","msg":"Server is initializing..."}
{"level":"info","ts":1545021783.9220464,"caller":"sqlstore/supplier.go:209","msg":"Pinging SQL master database"}
{"level":"info","ts":1545021783.9586954,"caller":"sqlstore/channel_store_experimental.go:47","msg":"Enabling experimental public channels materialization"}
{"level":"info","ts":1545021786.5524735,"caller":"commands/server.go:82","msg":"Current version is 5.5.0 (5.5.1/Thu Dec  6 09:21:58 UTC 2018/826252252404c13bf564a8c4fd51616fc2cc4df9/19ede6fcdfbfa13d72f67e4c76307efce8d8ee56)"}
{"level":"info","ts":1545021786.5527263,"caller":"commands/server.go:83","msg":"Enterprise Enabled: true"}
{"level":"info","ts":1545021786.5528123,"caller":"commands/server.go:84","msg":"Current working directory is /opt/mattermost"}
{"level":"info","ts":1545021786.5530255,"caller":"commands/server.go:85","msg":"Loaded config file from /opt/mattermost/config/config.json"}
{"level":"info","ts":1545021786.5541315,"caller":"filesstore/localstore.go:33","msg":"Able to write files to local storage."}
{"level":"info","ts":1545021786.561193,"caller":"app/license.go:44","msg":"License key from https://mattermost.com required to unlock enterprise features."}
{"level":"info","ts":1545021786.567932,"caller":"app/plugin.go:100","msg":"Starting up plugins"}
{"level":"info","ts":1545021787.408218,"caller":"app/server.go:88","msg":"Starting Server..."}
{"level":"info","ts":1545021787.4089968,"caller":"app/server.go:148","msg":"Server is listening on [::]:8065"}
{"level":"info","ts":1545021787.4487329,"caller":"app/web_hub.go:75","msg":"Starting 2 websocket hubs"}
{"level":"info","ts":1545021787.469876,"caller":"sqlstore/post_store.go:1297","msg":"Post.Message supports at most 16383 characters (65535 bytes)"}
{"level":"info","ts":1545021787.6854997,"caller":"jobs/workers.go:63","msg":"Starting workers"}
{"level":"info","ts":1545021787.6899462,"caller":"jobs/schedulers.go:68","msg":"Starting schedulers."}
[Ctrl]+[c]で終了

自動起動の設定

Mattermostを自動で起動できるようにします。

# touch /etc/systemd/system/mattermost.service
# vi /etc/systemd/system/mattermost.service
[Unit]
Description=Mattermost
After=syslog.target network.target

[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
# chmod 644 /etc/systemd/system/mattermost.service
# systemctl daemon-reload
# systemctl enable mattermost
Created symlink from /etc/systemd/system/multi-user.target.wants/mattermost.service
 to /etc/systemd/system/mattermost.service.
# systemctl start mattermost
# systemctl status mattermost
* mattermost.service - Mattermost
   Loaded: loaded (/etc/systemd/system/mattermost.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2018-12-17 21:47:41 JST; 6s ago
 Main PID: 14632 (mattermost)
   CGroup: /system.slice/mattermost.service
           └─14632 /opt/mattermost/bin/mattermost
   : (省略)

リバースプロキシーの設定

ApacheのRewriteを使って、HTTPがUpgradeのときに、websocketにいくようにします。

# /etc/httpd/conf/httpd.conf
   : (省略)
<Location /chat>
  RewriteEngine On
  RewriteCond %{HTTP:Upgrade} =websocket [NC]
  RewriteRule ^/(.*) ws://192.0.20.110:8065/$1 [L]
  RewriteCond %{HTTP:Upgrade} !=websocket [NC]
  RewriteRule ^/(.*) http://MMSERV:8065/$1 [L]
  ProxyPass http://192.0.20.110:8065/chat
  ProxyPassReverse http://192.0.20.110:8065/chat
</Location>
   : (省略)