OS/Linux

Ubuntu 20.04 : Rocket.Chat 설치

파란크리스마스 2022. 5. 24. 00:56
728x90

출처

Ubuntu 시스템 업그레이드

bluesanta@Kubuntu:~$ sudo apt update
bluesanta@Kubuntu:~$ sudo apt upgrade

필수 패키지 종속성 설치

MongoDB GPG 서명 키 추가

bluesanta@Kubuntu:~$ wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
OK
bluesanta@Kubuntu:~$ sudo apt update
bluesanta@Kubuntu:~$ sudo apt-get install gnupg

MongoDB 저장소 추가

bluesanta@Kubuntu:~$ echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse

Ubuntu 20.04에 MongoDB 5.0 설치

bluesanta@Kubuntu:~$ sudo apt-get update
bluesanta@Kubuntu:~$ sudo apt-get install -y mongodb-org

Ubuntu 패키지 관리자를 통해 Node.js가 설치되도록 구성

bluesanta@Kubuntu:~$ sudo apt-get update
bluesanta@Kubuntu:~$ sudo apt-get install -y curl && curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -

Node.js, 빌드도구, GraphicsMagick 설치

bluesanta@Kubuntu:~$ sudo apt install -y build-essential nodejs graphicsmagick

Node.js 버전 확인

bluesanta@Kubuntu:~$ node --version
v14.19.3

inherits, n 설치

bluesanta@Kubuntu:~$ sudo npm install -g inherits n
/usr/bin/n -> /usr/lib/node_modules/n/bin/n
+ n@8.2.0
+ inherits@2.0.4
added 2 packages from 2 contributors in 0.323s

node 실행파일 symbolic link

bluesanta@Kubuntu:~$ sudo ln -s /usr/bin/node /usr/local/bin/node

Ubuntu 20.04에 Rocket.Chat 설치

최신 버전의 Rocket.Chat을 다운로드

bluesanta@Kubuntu:~$ curl -L https://releases.rocket.chat/latest/download -o /tmp/rocket.chat.tgz

다운로드한 파일을 /tmp 폴더에 압축 해제

bluesanta@Kubuntu:~$ tar -xzf /tmp/rocket.chat.tgz -C /tmp

Rocket.Chat을 설치(/opt 디렉토리에 설치)

bluesanta@Kubuntu:~$ cd /tmp/bundle/programs/server
bluesanta@Kubuntu:/tmp/bundle/programs/server$ npm install
 
... 생략 ...
 
{
  "npm": "6.14.16",
  "ares": "1.18.1",
  "brotli": "1.0.9",
  "cldr": "37.0",
  "http_parser": "2.9.4",
  "icu": "67.1",
  "llhttp": "2.1.4",
  "modules": "72",
  "napi": "8",
  "nghttp2": "1.41.0",
  "node": "12.22.12",
  "openssl": "1.1.1n",
  "tz": "2021a4",
  "unicode": "13.0",
  "uv": "1.40.0",
  "v8": "7.8.279.23-node.57",
  "zlib": "1.2.11"
}
added 157 packages from 85 contributors and audited 157 packages in 62.738s

4 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

bluesanta@Kubuntu:/tmp/bundle/programs/server$ cd ~/
bluesanta@Kubuntu:~$ sudo mv /tmp/bundle /opt/Rocket.Chat

Rocketchat 시스템 사용자 생성

bluesanta@Kubuntu:~$ sudo useradd -M rocketchat && sudo usermod -L rocketchat
bluesanta@Kubuntu:~$ sudo chown -R rocketchat:rocketchat /opt/Rocket.Chat

Rocket.Chat 서비스 등록

Rocket.Chat 서비스 파일을 생성

bluesanta@Kubuntu:~$ cat << EOF |sudo tee -a /etc/systemd/system/rocketchat.service
[Unit]
Description=The Rocket.Chat server
After=network.target remote-fs.target nss-lookup.target nginx.service mongod.service
[Service]
ExecStart=/usr/local/bin/node /opt/Rocket.Chat/main.js
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=rocketchat
User=rocketchat
Environment=MONGO_URL=mongodb://localhost:27017/rocketchat?replicaSet=rs01 MONGO_OPLOG_URL=mongodb://localhost:27017/local?replicaSet=rs01 ROOT_URL=http://localhost:3000/ PORT=3000
[Install]
WantedBy=multi-user.target
EOF

MongoDB에 대한 스토리지 엔진 및 복제를 구성한 다음 MongoDB 서비스를 시작

$ sudo sed -i "s/^#  engine:/  engine: wiredTiger/"  /etc/mongod.conf
$ sudo sed -i "s/^#replication:/replication:\n  replSetName: rs01/" /etc/mongod.conf

MongoDB 서비스 시작 및 활성화

bluesanta@Kubuntu:~$ sudo systemctl daemon-reload
bluesanta@Kubuntu:~$ sudo systemctl enable mongod
Created symlink /etc/systemd/system/multi-user.target.wants/mongod.service → /lib/systemd/system/mongod.service.
bluesanta@Kubuntu:~$ sudo systemctl restart mongod

MongoDB 서비스 확인

bluesanta@Kubuntu:~$ systemctl status mongod
● mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2022-05-24 01:28:11 KST; 5s ago
       Docs: https://docs.mongodb.org/manual
   Main PID: 287216 (mongod)
     Memory: 65.2M
     CGroup: /system.slice/mongod.service
             └─287216 /usr/bin/mongod --config /etc/mongod.conf
 
 5월 24 01:28:11 Kubuntu systemd[1]: Started MongoDB Database Server.
 5월 24 01:28:11 Kubuntu mongod[287216]: /usr/bin/mongod: /usr/local/lib/libcurl.so.4: no version information available (required by >

MongoDB 테스트

bluesanta@Kubuntu:~$ mongo --eval "printjson(rs.initiate())"
MongoDB shell version v5.0.8
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("63537e3c-d3f1-42df-8158-043e7a759f3c") }
MongoDB server version: 5.0.8
{
        "info2" : "no configuration specified. Using a default configuration for the set",
        "me" : "127.0.0.1:27017",
        "ok" : 1
}

MongoDB 로그 확인

bluesanta@Kubuntu:~$ sudo tail -f /var/log/mongodb/mongod.log

Rocket.Chat 서비스 시작

bluesanta@Kubuntu:~$ sudo systemctl enable rocketchat
Created symlink /etc/systemd/system/multi-user.target.wants/rocketchat.service → /etc/systemd/system/rocketchat.service.
bluesanta@Kubuntu:~$ sudo systemctl start rocketchat

서비스가 실행 중인지 확인

bluesanta@Kubuntu:~$ sudo systemctl status rocketchat
● rocketchat.service - The Rocket.Chat server
     Loaded: loaded (/etc/systemd/system/rocketchat.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2022-05-24 01:58:11 KST; 6s ago
   Main PID: 291367 (node)
      Tasks: 11 (limit: 18681)
     Memory: 104.0M
     CGroup: /system.slice/rocketchat.service
             └─291367 /usr/local/bin/node /opt/Rocket.Chat/main.js
 
 5월 24 01:58:11 Kubuntu systemd[1]: Started The Rocket.Chat server.

Rocket.Chat 로그 확인

bluesanta@Kubuntu:~$ sudo tail -f syslog
May 24 17:31:52 bluesanta-desktop node[1964]: ufs: temp directory created at "/tmp/ufs"
May 24 17:31:52 bluesanta-desktop node[1964]: Loaded the Apps Framework and loaded a total of 0 Apps!
May 24 17:31:53 bluesanta-desktop node[1964]: +-----------------------------------------------+
May 24 17:31:53 bluesanta-desktop node[1964]: |                 SERVER RUNNING                |
May 24 17:31:53 bluesanta-desktop node[1964]: +-----------------------------------------------+
May 24 17:31:53 bluesanta-desktop node[1964]: |                                               |
May 24 17:31:53 bluesanta-desktop node[1964]: |  Rocket.Chat Version: 4.7.2                   |
May 24 17:31:53 bluesanta-desktop node[1964]: |       NodeJS Version: 14.19.3 - x64           |
May 24 17:31:53 bluesanta-desktop node[1964]: |      MongoDB Version: 5.0.8                   |
May 24 17:31:53 bluesanta-desktop node[1964]: |       MongoDB Engine: wiredTiger              |
May 24 17:31:53 bluesanta-desktop node[1964]: |             Platform: linux                   |
May 24 17:31:53 bluesanta-desktop node[1964]: |         Process Port: 3000                    |
May 24 17:31:53 bluesanta-desktop node[1964]: |             Site URL: http://localhost:3000/  |
May 24 17:31:53 bluesanta-desktop node[1964]: |     ReplicaSet OpLog: Enabled                 |
May 24 17:31:53 bluesanta-desktop node[1964]: |          Commit Hash: 1688633945              |
May 24 17:31:53 bluesanta-desktop node[1964]: |        Commit Branch: HEAD                    |
May 24 17:31:53 bluesanta-desktop node[1964]: |                                               |
May 24 17:31:53 bluesanta-desktop node[1964]: +-----------------------------------------------+

Nginx 리버스 프록시 구성

Nginx 웹 서버 설치

bluesanta@Kubuntu:~$ sudo apt install nginx

Nginx 웹 서버 프록시 설정

bluesanta@Kubuntu:~$ sudo vi /etc/nginx/conf.d/rocketchat.conf

rocketchat.conf 내용

upstream rocket_backend {
  server 127.0.0.1:3000;
}

server {
    listen 80;
    server_name chat.hirebestengineers.com;
    access_log /var/log/nginx/rocketchat-access.log;
    error_log /var/log/nginx/rocketchat-error.log;

    location / {
        proxy_pass http://rocket_backend/;
        proxy_http_version 1.1;
        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-Forward-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forward-Proto http;
        proxy_set_header X-Nginx-Proxy true;

        proxy_redirect off;
    }
}

Nginx 구성이 올바른지 확인

bluesanta@Kubuntu:~$ sudo nginx  -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Nginx 서비스 다시 시작

bluesanta@Kubuntu:~$ sudo systemctl restart nginx
bluesanta@Kubuntu:~$ sudo systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2022-05-24 02:01:44 KST; 4s ago
       Docs: man:nginx(8)
    Process: 292050 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 292063 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 292070 (nginx)
      Tasks: 5 (limit: 18681)
     Memory: 5.1M
     CGroup: /system.slice/nginx.service
             ├─292070 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ├─292071 nginx: worker process
             ├─292072 nginx: worker process
             ├─292073 nginx: worker process
             └─292074 nginx: worker process
 
 5월 24 02:01:44 Kubuntu systemd[1]: Starting A high performance web server and a reverse proxy server...
 5월 24 02:01:44 Kubuntu systemd[1]: Started A high performance web server and a reverse proxy server.

 

 

몽고 DB 삭제 방법

bluesanta@Kubuntu:~$ sudo apt-get remove mongodb-org
bluesanta@Kubuntu:~$ sudo apt-get purge mongodb-org*
bluesanta@Kubuntu:~$ sudo rm -rf /var/log/mongodb
bluesanta@Kubuntu:~$ sudo rm -rf /var/lib/mongodb