[学习笔记] Rocket.Chat 安装与设置启动项

这篇文章主要介绍手动安装的方式来安装Rocket.Chat,在Rocket.Chat官方有三种安装方式,

  1. 面向开发人员的直接使用meteor部署
  2. 传统的源码编译安装
  3. Docker方式部署

接下来分别介绍:

使用Meteor方式部署

Meteor是一种Web应用构建平台(官网https://meteor.com/),已经包含了nodejs,mongodb等环境,所以我们只需要安装Meteor和对应的rocketchat工具即可

安装Rocket.Chat

下载对应的Release版本,这里以2.4.14为例

https://codeload.github.com/RocketChat/Rocket.Chat/tar.gz/refs/tags/2.4.14

根据文档安装和配置

Linux - Rocket.Chat Developer

配置Service

在/etc/systemd/system/目录下新建名称为rocketchat.service的文件,填写如下内容 

[Unit]
Description=The Rocket.Chat server running on Linux
After=network.target remote-fs.target nss-lookup.target nginx.service mongod.service
[Service]
WorkingDirectory=/home/xamarin/web/Rocket.Chat-2.4.14/
ExecStart=/usr/local/bin/meteor npm start
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=rocketchat
User=xamarin
Environment=ROOT_URL=http://localhost:3000/ PORT=3000
[Install]
WantedBy=multi-user.target

保存文件后执行:

 sudo systemctl daemon-reload

接下来测试服务:

sudo systemctl start rocketchat.service

如果服务启动Ok没有问题 ,我们把这个服务设置成自启动

sudo systemctl enable rocketchat.service

.Net5 的后台接口程序也设置成自动启动

在/etc/systemd/system/目录下新建名称为kestrel-cah.service的文件

键入如下内容

[Unit]
Description=CAH Web API App running on Linux

[Service]
WorkingDirectory=/home/xamarin/web/[dll所在地址]
ExecStart=/usr/local/dotnet/dotnet XXX.Web.Host.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-cah
User=xamarin
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target

用同样的方法执行systemctl 的几个步骤

完成!

Troubleshooting:

如果systemd有报错,可以通过如下命令查看

sudo systemctl status kestrel-cah.service
sudo journalctl -fu  kestrel-cah.service

 默认情况下日志记录在syslog,如果看报错详细,可以通过如下命令查看

 sudo cat /var/log/messages

 

使用传统方式部署

确定版本

首先下载对应的Release版本,这里以2.4.14为例

Release 2.4.14 · RocketChat/Rocket.Chat (github.com)

根据文档安装和配置

Manual Installation - Rocket.Chat Docs

 


注意我们待会要安装合适版本的Nodejs和Mongodb

安装Nodejs 8.17.0

先下载二进制包

https://nodejs.org/dist/v8.17.0/node-v8.17.0-linux-x64.tar.gz

将二进制包上传至目标机器的临时目录中(~/下载)

解压至/usr/local/nodejs安装目录

sudo mkdir /usr/local/nodejs 
sudo tar -zxvf node-v8.17.0-linux-x64.tar.gz -C /usr/local/nodejs

 打开.bashrc,设置环境变量NODE_PATH,并将它添加至PATH

# Nodejs
export NODE_PATH=/usr/local/nodejs/node-v8.17.0-linux-x64
export PATH=$PATH:$NODE_PATH/bin

重新载入.bashrc 

source ~/.bashrc

 查看node版本,已经可以显示,安装完成

node -version


 

安装MongoDB

从官网下载二进制包 

MongoDB Community Download | MongoDB

 将二进制包上传至目标机器的临时目录中(~/下载)

解压至cd /opt/mongodb/安装目录

sudo mkdir cd /opt/mongodb/
sudo tar -zxvf mongodb-linux-x86_64-rhel80-4.4.12.tgz -C cd /opt/mongodb/

 打开.bashrc,设置环境变量NODE_PATH,并将它添加至PATH

# Mongodb
export MONGODB_HOME=/opt/mongodb/mongodb-linux-x86_64-rhel80-4.4.12
export PATH=$PATH:$MONGODB_HOME/bin

重新载入.bashrc 

source ~/.bashrc

建立配置文件

sudo nano ~/mongod.conf

键入以下内容

storage:
  journal:
    enabled: true
  engine: wiredTiger

net:
  port: 27017
  bindIpAll: true

processManagement:
  timeZoneInfo: /usr/share/zoneinfo

replication:
  replSetName: rs01

 建立数据库存储目录

sudo mkdir /data/db
sudo chmod 777 /data/db/

注意,rocketchat需要开启分布式

mongo --eval "printjson(rs.initiate())"

启动mongod,数据库已运行成功 

mongod -f /home/xamarin/mongod.config 

添加启动项
 

sudo nano /etc/systemd/system/mongod.service

键入以下内容 

[Unit]
Description=mongod running on Linux
After=network.target remote-fs.target nss-lookup.target nginx.service
[Service]
ExecStart=/opt/mongodb/mongodb-linux-x86_64-rhel80-4.4.12/bin/mongod -f /home/xamarin/mongod.conf
User=xamarin
[Install]
WantedBy=multi-user.target

 [可选]如果在宿主机上使用数据库管理工具,则需要打开27017端口,以便外部访问

sudo firewall-cmd --zone=public --add-port=27017/tcp --permanent 
sudo firewall-cmd --reload
sudo semanage port -a -t http_port_t  -p tcp 27017

安装Rocket.Chat服务

下载二进制包至目标机器的临时目录中(~/下载)

curl -L https://releases.rocket.chat/2.4.14/download -o ~/下载/rocket.chat-2.4.14.tgz

在网速不好的环境也可用迅雷下载后,将二进制包上传至临时目录中(~/下载)

解压至安装目录

sudo mkdir /opt/rocketchat
sudo tar -zxvf rocket.chat-2.4.14.tgz -C /opt/rocketchat

安装编译服务工具

sudo yum install gcc-c++
sudo yum groupinstall 'Development Tools'

前往安装目录下的bundle/server

cd /opt/rocketchat/bundle/server/

安装npm依赖包 

npm i

 添加启动项

sudo nano /etc/systemd/system/rocketchat.service

键入以下内容

[Unit]
Description=The Rocket.Chat server running on Linux
After=network.target remote-fs.target nss-lookup.target nginx.service mongod.service
[Service]
ExecStart=/usr/local/nodejs/node-v8.17.0-linux-x64/bin/node /opt/rocketchat/bundle/main.js
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=rocketchat
User=xamarin
Environment=ROOT_URL=http://localhost:3000
Environment=PORT=3000
Environment=MONGO_URL=mongodb://localhost:27017/rocketchat?replicaSet=rs01
Environment=MONGO_OPLOG_URL=mongodb://localhost:27017/local?replicaSet=rs01
[Install]
WantedBy=multi-user.target

 完成之后测试是否正常启动:

sudo systemctl daemon-reload 
sudo systemctl start rocketchat.service
sudo systemctl status rocketchat.service

服务已经正常运行

  

 将两个服务添加至开机启动项

sudo systemctl enable rocketchat.service
sudo systemctl enable mongod.service

 

TrubbleShooting:

出现

"NotYetInitialized: Replication has not yet been configured

Rocketchat要求配置mongodb的分布式,所以需要开启Replic方式,并且初始化Selector

 

出现

getaddrinfo ENOTFOUND xxxx

xxxx为域名,需要将它添加至host文件中

xxxx 127.0.0.1

 使用Docker方式部署

安装docker-compose

可以使用curl命令下载 

curl -SL https://github.com/docker/compose/releases/download/v2.5.1/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose

 在国内如果网络不好的情况下,可以用如下操作代替上面命令

下载二进制文件:

https://github.com/docker/compose/releases/download/v2.6.0/docker-compose-linux-x86_64

将二进制文件拷贝至目标机器中的 /usr/local/bin/docker-compose
 

sudo chmod +x /usr/local/bin/docker-compose

查看是否安装完成 


在sudoer信任的目录下创建docker-compose的软连接 ,以便以sudo方式执行docker-compose

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

在合适的目录下创建docker-compose.yml文件,并输入以下内容:

version: '2'

services:
  rocketchat:
    image: registry.rocket.chat/rocketchat/rocket.chat:2.4.14
    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
    volumes:
      - ./uploads:/app/uploads
    environment:
      - PORT=3000
      - ROOT_URL=http://localhost:3000
      - MONGO_URL=mongodb://mongo:27017/rocketchat
      - MONGO_OPLOG_URL=mongodb://mongo:27017/local
      - REG_TOKEN=${REG_TOKEN}
#       - MAIL_URL=smtp://smtp.email
#       - HTTP_PROXY=http://proxy.domain.com
#       - HTTPS_PROXY=http://proxy.domain.com
    depends_on:
      - mongo
    ports:
      - 3000:3000
    labels:
      - "traefik.backend=rocketchat"
      - "traefik.frontend.rule=Host: your.domain.tld"

  mongo:
    image: mongo:4.0
    restart: unless-stopped
    volumes:
     - ./data/db:/data/db
     #- ./data/dump:/dump
    command: mongod --smallfiles --oplogSize 128 --replSet rs0 --storageEngine=mmapv1
    labels:
      - "traefik.enable=false"

  # this container's job is just run the command to initialize the replica set.
  # it will run the command and remove himself (it will not stay running)
  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

最后执行运行命令

sudo docker-compose up -d

TrubbleShooting:

若运行中出现

find: '/data/db': Permission denied
chown: changing ownership of '/data/db': Permission denied

解决办法

setenforce 0



posted @ 2022-02-15 09:43  林晓lx  阅读(2299)  评论(0编辑  收藏  举报