当前位置: 首页 > 工具软件 > Rocket.Chat > 使用案例 >

使用宝塔面板安装Rocket.Chat多功能团队聊天室

太叔昆
2023-12-01

安装

官方文档:https://rocket.chat/docs/

环境要求:NodeJS 8.11.4Mongodb 4.0.9Nginx(非必需)。

提示:由于官方建议的最低内存1G,所以512M或更小的建议加点虚拟内存,可以使用Swap一键脚本→传送门

1、安装宝塔

#CentOS系统
wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh
#Ubuntu系统
wget -O install.sh http://download.bt.cn/install/install-ubuntu_6.0.sh && sudo bash install.sh
#Debian系统
wget -O install.sh http://download.bt.cn/install/install-ubuntu_6.0.sh && bash install.sh

安装完成后,进入面板,点击左侧软件商店,然后安装PM2管理器MongoDBNginx(使用域名访问才需要安装,反之不用)。

注意:Debian安装MongoDb之前还需要使用命令apt install sudo,不然可能存在MongoDb启动不了的情况;如果你已经安装了MongoDb,那就先使用apt install sudo,再使用/etc/init.d/mongodb start启动即可。

2、环境配置
先点击左侧软件商店,找到PM2管理器设置选项,选择Node版本,切换到8.11.4版本,不然太高可能会导致Rocket.Chat运行出错。

然后再找到MongoDb设置选项,点击配置文件,新增/修改以下代码:

#设置storage引擎,新增engine参数,并修改下dbPath路径,不然会启动不了
storage:
  dbPath: /www/server/mongodb/Rocket.Chat
  directoryPerDB: true
  engine: mmapv1
  journal:
    enabled: true
#配置replica set,新增以下参数
replication:
  replSetName: rs01 

保存后,MongoDb会自动关闭,这时候使用命令:

#新建数据存储路径,即上面配置文件修改的dbPath参数
mkdir /www/server/mongodb/Rocket.Chat
#授权
chown mongo:mongo /www/server/mongodb/Rocket.Chat
#重新启动数据库
/etc/init.d/mongodb start
#启动replica set
mongo --eval "printjson(rs.initiate())"

3、安装依赖

#Debian/Ubuntu系统
apt install -y graphicsmagick
#CentOS系统
yum install -y GraphicsMagick

4、安装Rocket.Chat

#下载rocket.chat
wget -O rocket.chat.tgz https://releases.rocket.chat/latest/download 
#解压并删除
tar -xzf rocket.chat.tgz && rm -rf rocket.chat.tgz
#移动到/opt并重命名
mv bundle /opt/Rocket.Chat
#安装依赖
cd /opt/Rocket.Chat
npm install -g inherits
cd programs/server
npm install

5、启动Rocket.Chat

#新建rocketchat用户并授权
useradd -M rocketchat && usermod -L rocketchat
chown -R rocketchat:rocketchat /opt/Rocket.Chat
#新建systemd配置文件,将以下代码一起复制到SSH运行
cat > /etc/systemd/system/rocketchat.service <<EOF
[Unit]
Description=Rocket.Chat
After=network.target
Wants=network.target

[Service]
ExecStart=$(command -v node) main.js
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=rocketchat
User=rocketchat
WorkingDirectory=/opt/Rocket.Chat
Environment=MONGO_URL=mongodb://127.0.0.1:27017/rocketchat?replicaSet=rs01 MONGO_OPLOG_URL=mongodb://127.0.0.1:27017/local?replicaSet=rs01 ROOT_URL=http://127.0.0.1:3000/ PORT=3000
Type=simple
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target
EOF

开始启动:

#启动的时候,可能需要点时间加载,等待即可
systemctl start rocketchat

查看状态:

systemctl status rocketchat

开机自启:

systemctl enable rocketchat

此时访问地址为ip:3000,如果你想用ip访问,点击左侧安全,开放3000端口即可,如果想用域名访问,不需要开启,继续往下面看。

6、域名访问
要使用域名的话就需要进行反代了,这里就不用宝塔自带的反向代理配置了,默认配置不适合Rocket.Chat

先点击左侧网站,添加站点,然后再点击添加好了的域名名称,这时候就进入了站点配置,点击配置文件,在中间添加以下代码:

location ~ ^/.* {
    proxy_pass http://127.0.0.1:3000;
    proxy_set_header Host             $host;
    proxy_set_header X-Real-IP        $remote_addr;
    proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;

    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header X-Forward-Proto http;
    proxy_set_header X-Nginx-Proxy true;
    proxy_http_version 1.1;

    proxy_redirect off;
}

点击保存后,再点击SSL,申请免费的Let's Encrypt证书,并强制HTTPS

 

CentOS中的Rocket.Chat

本安装指南已在以下环境中进行了测试:

  • 火箭聊天1.0.2
  • 作业系统:CentOS 7.6
  • Mongodb 4.0.9
  • NodeJS 8.11.4

安装必要的依赖包

更新软件包列表并配置yum以使用以下yum存储库文件安装正式的MongoDB软件包:

<span style="color:#1f2329"><code><span style="color:#24909d">sudo </span>yum <span style="color:#6ab825"><strong>-y</strong></span> check-update
</code></span>
<span style="color:#1f2329"><code><span style="color:#24909d">cat</span> <span style="color:#d0d0d0"><<</span> <span style="color:#40ffff">EOF</span><span style="color:#ed9d13"> | sudo tee -a /etc/yum.repos.d/mongodb-org-4.0.repo
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
</span><span style="color:#40ffff">EOF
</span></code></span>

配置要通过软件包管理器安装的Node.js:

<span style="color:#1f2329"><code><span style="color:#24909d">sudo </span>yum install <span style="color:#6ab825"><strong>-y</strong></span> curl <span style="color:#d0d0d0">&&</span> curl <span style="color:#6ab825"><strong>-sL</strong></span> https://rpm.nodesource.com/setup_8.x | <span style="color:#24909d">sudo </span>bash -
</code></span>

安装构建工具,MongoDB,nodejs和graphicsmagick:

<span style="color:#1f2329"><code><span style="color:#24909d">sudo </span>yum install <span style="color:#6ab825"><strong>-y</strong></span> gcc-c++ make mongodb-org nodejs
</code></span>
<span style="color:#1f2329"><code><span style="color:#24909d">sudo </span>yum install <span style="color:#6ab825"><strong>-y</strong></span> epel-release <span style="color:#d0d0d0">&&</span> <span style="color:#24909d">sudo </span>yum install <span style="color:#6ab825"><strong>-y</strong></span> GraphicsMagick
</code></span>

使用npm install继承了和n,以及Rocket.Chat所需的节点版本:

<span style="color:#1f2329"><code><span style="color:#24909d">sudo </span>npm install <span style="color:#6ab825"><strong>-g</strong></span> inherits n <span style="color:#d0d0d0">&&</span> <span style="color:#24909d">sudo </span>n 8.11.4
</code></span>

安装Rocket.Chat

下载最新的Rocket.Chat版本:

<span style="color:#1f2329"><code>curl <span style="color:#6ab825"><strong>-L</strong></span> https://releases.rocket.chat/latest/download <span style="color:#6ab825"><strong>-o</strong></span> /tmp/rocket.chat.tgz
</code></span>
<span style="color:#1f2329"><code><span style="color:#24909d">tar</span> <span style="color:#6ab825"><strong>-xzf</strong></span> /tmp/rocket.chat.tgz <span style="color:#6ab825"><strong>-C</strong></span> /tmp
</code></span>

安装(本指南使用/ opt,但可以选择其他目录):

<span style="color:#1f2329"><code><span style="color:#24909d">cd</span> /tmp/bundle/programs/server <span style="color:#d0d0d0">&&</span> npm install
</code></span>
<span style="color:#1f2329"><code><span style="color:#24909d">sudo </span>mv /tmp/bundle /opt/Rocket.Chat
</code></span>

配置Rocket.Chat服务

添加rocketchat用户,在Rocket.Chat文件夹上设置正确的权限,并创建Rocket.Chat服务文件:

<span style="color:#1f2329"><code><span style="color:#24909d">sudo </span>useradd <span style="color:#6ab825"><strong>-M</strong></span> rocketchat <span style="color:#d0d0d0">&&</span> <span style="color:#24909d">sudo </span>usermod <span style="color:#6ab825"><strong>-L</strong></span> rocketchat
</code></span>
<span style="color:#1f2329"><code><span style="color:#24909d">sudo </span>chown <span style="color:#6ab825"><strong>-R</strong></span> rocketchat:rocketchat /opt/Rocket.Chat
</code></span>
<span style="color:#1f2329"><code><span style="color:#24909d">cat</span> <span style="color:#d0d0d0"><<</span> <span style="color:#40ffff">EOF</span><span style="color:#ed9d13"> |sudo tee -a /lib/systemd/system/rocketchat.service
[Unit]
Description=The Rocket.Chat server
After=network.target remote-fs.target nss-lookup.target nginx.target mongod.target
[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
</span><span style="color:#40ffff">EOF
</span></code></span>

/usr/lib/systemd/system/rocketchat.service使用sudo和您喜欢的文本编辑器打开刚刚创建的Rocket.Chat服务文件(),然后更改ROOT_URL环境变量以反映您要用于访问服务器的URL(可以选择更改MONGO_URL,MONGO_OPLOG_URL和PORT):

<span style="color:#1f2329"><code><span style="color:#40ffff">MONGO_URL</span><span style="color:#d0d0d0">=</span>mongodb://localhost:27017/rocketchat?replicaSet<span style="color:#d0d0d0">=</span>rs01
<span style="color:#40ffff">MONGO_OPLOG_URL</span><span style="color:#d0d0d0">=</span>mongodb://localhost:27017/local?replicaSet<span style="color:#d0d0d0">=</span>rs01
<span style="color:#40ffff">ROOT_URL</span><span style="color:#d0d0d0">=</span>http://your-host-name.com-as-accessed-from-internet:3000
<span style="color:#40ffff">PORT</span><span style="color:#d0d0d0">=</span>3000
</code></span>

为MongoDB设置存储引擎和复制(对于版本> 1为必需),并启用并启动MongoDB和Rocket.Chat:

<span style="color:#1f2329"><code><span style="color:#24909d">sudo </span>sed <span style="color:#6ab825"><strong>-i</strong></span> <span style="color:#ed9d13">"s/^#  engine:/  engine: mmapv1/"</span>  /etc/mongod.conf
</code></span>
<span style="color:#1f2329"><code><span style="color:#24909d">sudo </span>sed <span style="color:#6ab825"><strong>-i</strong></span> <span style="color:#ed9d13">"s/^#replication:/replication:</span><span style="color:#ed9d13">\n</span><span style="color:#ed9d13">  replSetName: rs01/"</span> /etc/mongod.conf
</code></span>
<span style="color:#1f2329"><code><span style="color:#24909d">sudo </span>systemctl <span style="color:#24909d">enable </span>mongod <span style="color:#d0d0d0">&&</span> <span style="color:#24909d">sudo </span>systemctl start mongod
</code></span>
<span style="color:#1f2329"><code>mongo <span style="color:#6ab825"><strong>--eval</strong></span> <span style="color:#ed9d13">"printjson(rs.initiate())"</span>
</code></span>
<span style="color:#1f2329"><code><span style="color:#24909d">sudo </span>systemctl <span style="color:#24909d">enable </span>rocketchat <span style="color:#d0d0d0">&&</span> <span style="color:#24909d">sudo </span>systemctl start rocketchat
</code></span>

可选配置

配置防火墙规则 配置HTTP反向代理以访问Rocket.Chat服务器 [配置mongo访问控制] [配置mongodb的生产值]

配置您的Rocket.Chat服务器

打开Web浏览器并访问已配置的ROOT_URL(http://your-host-name.com-as-accessed-from-internet:3000),按照配置步骤设置管理员帐户以及您的组织和服务器信息。

ZLIB版本问题

一些用户遇到了在CentOS中启动火箭聊天服务器的问题,因为他们的zlib版本与rocket.chat不兼容。

如果您在日志中找到类似于以下内容的错误消息:

<span style="color:#1f2329"><code>Exception <span style="color:#6ab825"><strong>in </strong></span>callback of async <span style="color:#6ab825"><strong>function</strong></span>: Error: /lib64/libz.so.1: version <span style="color:#ed9d13">`</span>ZLIB_1.2.9<span style="color:#ed9d13">' not found
</span></code></span>

在Rocket.Chat服务文件(/usr/lib/systemd/system/rocketchat.service)中添加以下环境变量:

环境= LD_PRELOAD = / opt / Rocket.Chat / programs / server / npm / node_modules / sharp / vendor / lib / libz.so

 类似资料: