Rocket.chat开源聊天室部署

前言

Rocket.chat是一个开源免费的聊天室程序,界面简洁,功能实用且部署简单。聊天室支持多种部署方式,包括Docker、snap,snap更是做到了一键安装部署,堪称懒人福音~

部署开始

官方的部署教程在这里

Rocket.chat社区建议程序部署的最低服务器配置为1GB运行内存以及30GB以上的存储空间,推荐配置为2GB以上运行内存及40GB存储空间。

我将它部署在了一台1C1G20GB配置的服务器上,系统为Debian11,部署方式为snap。

首先安装snap

sudo apt install snapd -y

执行安装

sudo snap install rocketchat-server

待安装完毕后即可直接通过 http://服务器IP:3000 来访问了。

如果需要修改访问端口,例如修改至8080端口,运行如下命令

sudo snap set rocketchat-server port=8080

修改完毕后需要重启Rocket.chat服务,运行

sudo snap restart rocketchat-server

或者

sudo systemctl restart snap.rocketchat-server.rocketchat-server

一些常用命令

更新rocket.chat

sudo snap refresh rocketchat-server

备份及恢复Rocket.chat数据

备份

首先停止服务的运行

sudo snap stop rocketchat-server.rocketchat-server

同时教程要求在 Rocketchat-server 服务应该停止的同时,rocketchat-mongo 服务应该保持运行,通过以下命令查看

systemctl is-active snap.rocketchat-server.rocketchat-mongo

运行后应得到 Active 的回应

备份命令

sudo snap run rocketchat-server.backupdb

运行结束后应得到如下类似的回应

[+] A backup of your data can be found at /var/snap/rocketchat-server/common/backup/rocketchat_backup_<timestamp>.tar.gz

即为备份成功

随后启动服务

sudo snap start rocketchat-server.rocketchat-server

恢复命令

依然需要先停止服务的运行

sudo snap stop rocketchat-server.rocketchat-server

将备份的文件复制到Rocket.chat的安装位置

sudo cp rocketchat_backup.tar.gz /var/snap/rocketchat-server/common/

开始恢复

sudo snap run rocketchat-server.restoredb /var/snap/rocketchat-server/common/rocketchat_backup.tgz

替换数据库时会收到提示,按需选择即可。

如果一切顺利则会看到如下内容的输出

[*] Extracting backup file...
[*] Restoring data...
[*] Preparing database...
[+] Restore completed! Please restart the snap.rocketchat services to verify.

随后启动服务即可

反向代理

官方的教程给出了snap结合caddy的方式,我使用了Nginx来进行反向代理,配置如下:

server
    {
        listen 80;
        listen [::]:80;
        server_name 你的域名;
        return 301 https://你的域名$request_uri;

        location / {
            proxy_pass http://你的IP:服务运行端口;
            proxy_http_version    1.1;
            proxy_cache_bypass    $http_upgrade;
            proxy_set_header Upgrade            $http_upgrade;
            proxy_set_header Connection         "upgrade";
            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 X-Forwarded-Proto  $scheme;
            proxy_set_header X-Forwarded-Host   $host;
            proxy_set_header X-Forwarded-Port   $server_port;
        }

        access_log off;
    }

server
    {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name 你的域名;

        ssl_certificate 域名证书位置;
        ssl_certificate_key 域名key位置;
        ssl_session_timeout 5m;
        ssl_protocols  TLSv1.2 TLSv1.3;
        ssl_prefer_server_ciphers on;
        ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
        ssl_session_cache builtin:1000 shared:SSL:10m;
        # openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
        ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;

        location / {
            proxy_pass http://你的IP:服务运行端口;
            proxy_http_version    1.1;
            proxy_cache_bypass    $http_upgrade;
            proxy_set_header Upgrade            $http_upgrade;
            proxy_set_header Connection         "upgrade";
            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 X-Forwarded-Proto  $scheme;
            proxy_set_header X-Forwarded-Host   $host;
            proxy_set_header X-Forwarded-Port   $server_port;
        }

        access_log off;
    }

这样,部署就基本完成了。

留下评论

您的邮箱地址不会被公开。 必填项已用 * 标注