5
0

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 3 years have passed since last update.

rocket.chatをEC2上でつかう

Posted at

昨今の時勢でチャットツールをちょこっと用意したいと思ったので作ってみたメモ書きです。

構成

  • AmazonLinux2
  • t2.microインスタンス

EC2ユーザーデータを用いてパパっと立てます。
私の要望上、使い終わったらすべてのデータを毎回削除して使いたい。というちょっと特殊な事情もあったのでdocker使ってます。

NWやSGの設定はよしなに
ALBとACM挟んでHTTPS化とかもできるのでそのへんはよしなに

docker-compose.yml

rocket.chatのページにあったものをちょこっと書き換えて使用。
volumeの部分を削除して使う&hubotいらないのでそのへんを削除して使用してます。

mongo
    volumes:
     - ./data/runtime/db:/data/db
     - ./data/dump:/dump
rocketchat
    volumes:
      - ./uploads:/app/uploads

スクリプト

user-data
#!/bin/bash
amazon-linux-extras install -y docker
yum install -y git
systemctl enable docker
systemctl start  docker
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
gpasswd -a ec2-user docker
systemctl restart docker

# rocket.chat
cat << _EOF_ > /home/ec2-user/docker-compose.yml
version: '2'

services:
  rocketchat:
    image: rocketchat/rocket.chat:latest
    command: >
      bash -c
        "for i in `seq 1 30`; do
          node main.js &&
          s=$$? && break || s=$$?;
          echo \"Tried $$i times. Waiting 5 secs...\";
          sleep 5;
        done; (exit $$s)"
    restart: unless-stopped
    environment:
      - PORT=3000
      - ROOT_URL=http://localhost:3000
      - MONGO_URL=mongodb://mongo:27017/rocketchat
      - MONGO_OPLOG_URL=mongodb://mongo:27017/local
    depends_on:
      - mongo
    ports:
      - 3000:3000
  mongo:
    image: mongo:4.0
    restart: unless-stopped
    command: mongod --smallfiles --oplogSize 128 --replSet rs0 --storageEngine=mmapv1
  mongo-init-replica:
    image: mongo:4.0
    command: >
      bash -c
        "for i in `seq 1 30`; do
          mongo mongo/rocketchat --eval \"
            rs.initiate({
              _id: 'rs0',
              members: [ { _id: 0, host: 'localhost:27017' } ]})\" &&
          s=$$? && break || s=$$?;
          echo \"Tried $$i times. Waiting 5 secs...\";
          sleep 5;
        done; (exit $$s)"
    depends_on:
      - mongo
_EOF_

cd /home/ec2-user
docker-compose up -d

起動後、http://InstanceIP:3000/にrocket.chatのアプリがバインドされます。
使い終わったら docker-compose downまた使う際は docker-compose upすれば毎回初期化されて使えます。

参考

https://docs.docker.com/compose/install/
https://rocket.chat/docs/installation/docker-containers/docker-compose/

5
0
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
5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?