zuntan02のはてなブログ

備忘録的なものです。時々職場の技術者ブログにも転記してますが、メインはこちらで。

CentOS6+MySQL+NginxでMattermostインストール

【参考手順】
AmazonLinuxの例
qiita.com
すみません例によって上記ほぼそのまんまです。

SELINUX

vi /etc/sysconfig/selinux
SELINUX=disabled : 無効にしておく(AmazonLinuxは初期値でdisabledだがCentOSはenableなので。)

mysql5.7のインストール

※後述するポスト内容の部分一致検索にn-gramパーサを使用するため、MySQL5.7が必要

yum install -y http://dev.mysql.com/get/mysql57-community-release-el6-7.noarch.rpm
yum install -y mysql-community-server.x86_64 mysql-community-devel.x86_64 mysql-community-client.x86_64

***起動
/etc/init.d/mysqld start

***MySQL初期設定
mysql_secure_installation
# Change the root password? [Y/n] Y
# New password:
rootのパスワードを設定しましょう。あとはすべてEnterで抜けます。

***自動起動設定
chkconfig --list mysqld
# mysqld         	0:off	1:off	2:off	3:off	4:off	5:off	6:off
chkconfig mysqld on
chkconfig --list mysqld
# mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off

nginxのインストール

rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
yum install nginx --disablerepo=* --enablerepo=nginx

***自動起動確認
chkconfig --list nginx
# nginx          	0:off	1:off	2:on	3:on	4:on	5:on	6:off

Mattermost用のユーザーとDBを作成。

ここではuser名:mmuser パスワード:mattermost DB名:mattermost で設定しています。

mysql -A -uroot -p

CREATE DATABASE mattermost;
GRANT ALL PRIVILEGES ON mattermost.* TO 'mmuser'@'localhost' IDENTIFIED BY 'mattermost' WITH GRANT OPTION;
exit

MatterMostのインストール

mattermost実行ユーザーを作成。

adduser mattermost

ダウンロード及び展開、配置。

http://www.mattermost.org/download/
上記サイトにアクセスすると、最新バージョンのwget文が表示されているので、これをそのまま利用する
→今回はv3.3.0だった

cd /usr/local/src/
wget https://releases.mattermost.com/3.3.0/mattermost-team-3.3.0-linux-amd64.tar.gz
tar zxvf mattermost-team-3.3.0-linux-amd64.tar.gz

mv mattermost /opt/mattermost
mkdir -p /opt/mattermost/data
chown -R mattermost:mattermost /opt/mattermost
chmod -R g+w /opt/mattermost
Mattermostの設定を変更

DataSourceをdocker→localhostに編集、ほか微調整

cp -p /opt/mattermost/config/config.json /opt/mattermost/config/config.json_org
vi /opt/mattermost/config/config.json

"DataSource": "ユーザ名:パスワード@tcp(localhost:3306)/DB名?charset=utf8mb4,utf8",
→今回の場合
"DataSource": "mmuser:mattermost@tcp(localhost:3306)/mattermost?charset=utf8mb4,utf8",
NginxのconfにMattermostの設定を追加。

vi /etc/nginx/conf.d/mattermost.conf

  server {
    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://localhost:8065;
    }
  }

==========
# ※nginx.confにserverの設定が記述されていたらコメントアウトしておく
mv default.conf default.conf_bak

Mattermost起動スクリプトを下記場所に作成。

vi /opt/mattermost/bin/mattermost.sh

#!/bin/sh
# chkconfig:   - 85 15
# description:  mattermost

SERVICE=mattermost
start() {
    cd /opt/mattermost
    sudo -u mattermost ./bin/platform > /dev/null &
    echo "service $SERVICE [start]"
}
stop() {
    pkill platform
    echo "service $SERVICE [stop]"
}
status() {
   PID=`pgrep platform | wc -l`
   if [ $PID -eq 0 ]; then
       echo "$SERVICE stop"
   else
       echo "running $SERVICE ..."
   fi
}

case $1 in
start)
       start
       ;;
stop)
       stop
       ;;
status)
       status
       ;;
restart)
       stop
       start
       ;;
*)
       echo "Usage: $SERVICE [start|stop|restart|status]"
       ;;
esac
exit 0
権限の修正及びシンボリックリンクの作成。
chmod 755 /opt/mattermost/bin/mattermost.sh
ln -s /opt/mattermost/bin/mattermost.sh /etc/init.d/mattermost
自動起動
chkconfig --add mattermost
chkconfig mattermost on
Mattermostの起動。

/etc/init.d/mattermost start

動作ログ

/opt/mattermost/logs

全文検索の部分一致対応

初期状態では「あいうえお」という発言について「うえ」がヒットしない状態。
Postsのインデックスをn-gramパースする
qiita.com

mysql> use mattermost
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';


# 初期設定
http://ホスト名/ に接続して各種初期設定を行う

# 日本語化
[SETTING]-[GENERAL]
Localization
Default Server Language:日本語
Default Client Language:日本語