7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Mattermost+MySQLのセットアップ (Docker)

Last updated at Posted at 2019-11-17

Mattermost+MySQLのセットアップメモ

SlackからMattermostに移行するに当たり,いろいろハマったのでメモ.

起動まで

準備

ソース:
https://github.com/mattermost/mattermost-docker

以下はDockerコンテナ

  • Mattermostのバージョンは5.16.3
  • MySQL 8.0.18

docker-compose.yml を編集.

  • DBはMySQLを使用.
  • <>内のパスワードは適宜設定.
  • MySQLはホストでも立っているのでポート番号は33306にする.
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -3,16 +3,21 @@ version: "3"
 services:
 
   db:
-    build: db
-    read_only: true
+    image: mysql/mysql-server:8.0
+    # read_only: true
     restart: unless-stopped
     volumes:
-      - ./volumes/db/var/lib/postgresql/data:/var/lib/postgresql/data
+      - ./volumes/db/var/lib/mysql:/var/lib/mysql
+      - ./volumes/db/etc/my.cnf.d:/etc/my.cnf.d
       - /etc/localtime:/etc/localtime:ro
     environment:
-      - POSTGRES_USER=mmuser
-      - POSTGRES_PASSWORD=mmuser_password
-      - POSTGRES_DB=mattermost
+      - MYSQL_ROOT_PASSWORD=<mysql-root-password>
+      - MYSQL_USER=mmuser
+      - MYSQL_PASSWORD=<dbpass>
+      - MYSQL_DATABASE=mattermost
+    ports:
+      - "33306:3306"
+
     # uncomment the following to enable backup
     #  - AWS_ACCESS_KEY_ID=XXXX
     #  - AWS_SECRET_ACCESS_KEY=XXXX
@@ -23,8 +28,8 @@ services:
     build:
       context: app
       # uncomment following lines for team edition or change UID/GID
-      # args:
-      #   - edition=team
+      args:
+        - edition=team
       #   - PUID=1000
       #   - PGID=1000
     restart: unless-stopped
@@ -34,25 +39,24 @@ services:
       - ./volumes/app/mattermost/logs:/mattermost/logs:rw
       - ./volumes/app/mattermost/plugins:/mattermost/plugins:rw
       - ./volumes/app/mattermost/client-plugins:/mattermost/client/plugins:rw
+
       - /etc/localtime:/etc/localtime:ro
     environment:
       # set same as db credentials and dbname
+      - DB_PORT_NUMBER=3306
+      - MM_SQLSETTINGS_DRIVERNAME=mysql
+      - MM_SQLSETTINGS_DATASOURCE=mmuser:<dbpass>@tcp(db:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s
       - MM_USERNAME=mmuser
       - MM_PASSWORD=<dbpass>
       - MM_DBNAME=mattermost
-
-      # use the credentials you've set above, in the format:
-      # MM_SQLSETTINGS_DATASOURCE=postgres://${MM_USERNAME}:${MM_PASSWORD}@db:5432/${MM_DBNAME}?sslmode=disable&connect_timeout=10
-      - MM_SQLSETTINGS_DATASOURCE=postgres://mmuser:mmuser_password@db:5432/mattermost?sslmode=disable&connect_timeout=10
-
       # in case your config is not in default location
       #- MM_CONFIG=/mattermost/config/config.json
 
   web:
     build: web
     ports:
-      - "80:80"
-      - "443:443"
+      - "8888:80"
+      - "8443:443"
     read_only: true
     restart: unless-stopped
     volumes:

起動

ソースのGithubの記載に倣う.

mkdir -p ./volumes/app/mattermost/{data,logs,config,plugins}
chown -R 2000:2000 ./volumes/app/mattermost
docker-compose up -d

-> http://:8888 で起動

設定

WebのSystem Console

色々設定.Site URLとか.

重要: Max Users Per Team を十分大きくしておく.
不十分だと,Slackデータをインポートした際に全ユーザが作成されない.

日本語の部分一致検索対応

参照: https://www.nedia.ne.jp/blog/tech/2018/03/27/11585

MySQL 8.0 では以下のみでよかった.

mysql> ALTER TABLE Posts DROP INDEX idx_posts_message_txt;
mysql> ALTER TABLE Posts ADD FULLTEXT INDEX idx_posts_message_txt (`Message`) WITH PARSER ngram COMMENT 'ngram index sample';

Nginxの設定例

nginxはホストのものを使用.

プロキシ設定だけだとWebsocketが通らないようなので色々書く.

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

   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-Host $host;
   proxy_set_header X-Forwarded-Server $host;
   proxy_set_header        X-Forwarded-Proto $scheme;

   location / {
     client_max_body_size 50M;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection "upgrade";
     proxy_set_header Host $http_host;
     proxy_pass http://127.0.0.1:8888/;
   }
}

Slackデータのインポート

参照: https://docs.mattermost.com/administration/migrating.html#migrating-from-slack-using-the-mattermost-cli

Appコンテナ内で以下を実行

mattermost import slack team_name /path/to/your-slack-export.zip

2019年12月3日追記

Team作成 -> Slackデータインポート という手順です.

ですが,インポートデータのユーザ数/チャネル数が大きい場合は,インポートする前にSystem Console にてMax Users Per Team/Max Channels Per Teamの値を適切な値にしておく必要がありました.

設定値が足りない場合,インポートが不十分に終わります.ご注意を.

Issues

restartできない

Workaround:
https://forum.mattermost.org/t/solved-mattermost-suddenly-crashed-and-after-reboot-web-container-doesnt-response/3050/3

# first of all save config
cp volumes/app/mattermost/config/config.json{,.bak}
# then restart:
docker-compose stop
rm volumes/app/mattermost/config/config.json
docker-compose up -d
cp volumes/app/mattermost/config/config.json{.bak,}

TODO:

  • 根本的な原因を解明したい

  • 少なくとも,サービス登録してホスト再起動時にも手作業不要にする

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?