Locked

CentOS_TIPS_012

Let's chat構築メモ

  • 公式サイトURL

https://github.com/sdelements/lets-chat

  • 参考URL

http://qiita.com/tenten0213/items/dff56549586f4c5607cf

http://qiita.com/kounoike/items/86a2ab82f69e7d7a5550

バージョン情報

ここでは、以下のバージョンについて記載しています。

$ cat /etc/redhat-release
CentOS release 6.7 (Final)

npm/nodejsインストール

npmをepelからインストールします。

# yum --enablerepo=epel install npm

サーバ化するためforeverを使用/インストールします。

# npm install -g inherits forever
# npm list -g forever
/usr/lib
└── forever@0.15.1

なお、SCLにnodejs010というパッケージがありますが、こちらは試していません。

# yum list nodejs010
利用可能なパッケージ
nodejs010.x86_64                    1.2-29.el6.centos.alt                    scl

python2.7インストール

要件を満たすため2.7系以上が必要(CentOS6標準のpythonはバージョン2.6系)なのですが2.6系のままでも動作しているようです。
2.7系のパッケージはiusからインストールして使うことになります。

# yum --enablerepo=ius install python27 python27-pip python27-virtualenv

現時点では、これは行わず様子見です。

SCLにもpython27-python/python27-python-virtualenv/python27-python-pipがありますので、こちらの使用でも問題無いかもしれません。

https://github.com/sdelements/lets-chat/issues/234

上記リンク先でnode-gypのコンパイルにpython2.7が必要という記事を見付けました。
これだけであればEPELからインストール可能です。

# yum --enablerepo=epel install node-gyp

使用するnpmモジュールによっては、同様の問題が発生するかもしれません。

mongodbインストール

epelに2.4系がありますが、要件を満たすため本家サイトから2.6系をインストールします。

# yum --enablerepo=mongodb install mongodb-org

サービスを起動。

# checkconfig mongod on
# service mongod start

Let's chatインストール

サービス実行ユーザとしてアカウント「letschat」を作成/使用します。
アカウント名は任意です。

# useradd letschat
# su - letschat
$

lets-chatをGitHubから取得/npmパッケージをインストールします。

$ git clone https://github.com/sdelements/lets-chat
$ cd lets-chat
$ npm update
$ npm install

設定ファイルを用意します。

$ cp settings.yml.sample settings.yml

以下の例ではロケールを修正/追記しています。

--- settings.yml.sample
+++ settings.yml
@@ -38,3 +38,7 @@
   providers: [local]
   local:
     enableRegistration: true
+
+i18n:
+  locale: ja
+

デフォルトでは、誰でもアカウントを作成出来てしまうので、必要に応じて「enableRegistration: false」とします。

以下のコマンドにてローカルホストhttp://localhost:5000によるサービス起動/動作確認が行えます。

$ npm start

initスクリプトを作成/自動起動するようにします。

--- /dev/null
+++ /etc/init.d/letschat
@@ -0,0 +1,70 @@
+#!/bin/bash
+
+# lets-chat - Startup script for lets-chat by forever
+
+# chkconfig: 35 86 15
+# description: lets-chat
+# processname: letschat
+# pidfile: /var/run/lets-chat.pid
+# logfile: /home/letschat/lets-chat.log
+
+. /etc/rc.d/init.d/functions
+
+NAME=lets-chat
+SOURCE_DIR=/home/letschat/lets-chat
+SOURCE_FILE=app.js
+
+forever=/usr/bin/forever
+user=letschat
+pidfile=/var/run/$NAME.pid
+logfile=/home/letschat/$NAME.log
+
+export NODE_PATH=$NODE_PATH:$SOURCE_DIR/node_modules
+
+start() {
+  touch ${pidfile}
+  chown ${user} ${pidfile}
+
+  touch ${logfile}
+  chown ${user} ${logfile}
+
+  echo "Start $NAME node instance: "
+
+  su ${user} -c "cd $SOURCE_DIR; ${forever} start --pidFile ${pidfile} -l ${logfile} -a $SOURCE_FILE >/dev/null 2>&1"
+
+  RETVAL=$?
+}
+
+stop() {
+  echo "Stop $NAME node instance: "
+  su ${user} -c "cd $SOURCE_DIR; ${forever} stop $SOURCE_FILE"
+  RETVAL=$?
+}
+
+restart() {
+  echo "Stop $NAME node instance: "
+  su ${user} -c "cd $SOURCE_DIR; ${forever} restart $SOURCE_FILE"
+  RETVAL=$?
+}
+
+case "$1" in
+  start)
+    start
+    ;;
+  stop)
+    stop
+    ;;
+  restart)
+    restart
+    ;;
+  status)
+    status -p ${pidfile}
+    RETVAL=$?
+    ;;
+  *)
+    echo "Usage:  {start|stop|restart|status}"
+    exit 1
+    ;;
+esac
+exit $RETVAL
+

サーバとして起動。

# chkconfig letschat on
# service letschat start

apacheにリバースプロキシを設定。
以下の例ではhttp://example.jp/chat/となるようにしています。

--- /dev/null
+++ /etc/httpd/conf.d/letschat.conf
@@ -0,0 +1,3 @@
+<Location "/chat">
+  ProxyPass http://localhost:5000/
+</Location>

# service httpd configtest && service httpd graceful