如何在Debian 10/Ubuntu 18.04上安装Rocket.Chat 服务器

时间:2020-02-23 14:32:50  来源:igfitidea点击:

在当今的教程中,我们将讨论如何在Debian 10/Ubuntu 18.04上安装Rocket.Chat服务器。
Rocket.Chat是一个自主托管的聊天平台,是开放的源头和最受欢迎的休闲替代品之一。
带有火箭的一些很酷的功能。
免费安装是文件共享,视频会议,聊天,音频消息等。
如果我们正在寻找在云或者本地数据中心运行的VPS中托管的开源消息平台,则此解决方案适合我们。

在本文中,我们将解释在Debian 10/Ubuntu 18.04上安装和配置Rocket.chat服务器所需的完整步骤。
安装期间,我们将使用以下工具:nginx webserverlet的加密ssl certificatenode.jsmongodb

如果服务器位于私有网络上,则可以生成并使用自签名证书代替Let’s Encrypt 。
更多建议使用普通HTTP上运行火箭服务器而不是运行Rocket.Chat服务器。

在任何一个服务器上启动终端即可开始。

第1步:更新系统

首先更新Ubuntu/Debian Linux服务器上的所有系统包。

sudo apt -y update && sudo apt -y upgrade

更新/升级后重新启动系统。

sudo shutdown -r now

第2步:安装所需的依赖项

其中我们将安装在Debian/Ubuntu服务器上运行Rocker.chat所需的所有依赖项。

sudo apt update
sudo apt install -y build-essential curl software-properties-common nodejs npm nginx graphicsmagick 
sudo systemctl enable nginx.service && sudo systemctl start nginx.service

如果我们不想要存储库节点.js,则使用其官方存储库安装它。

curl -sL https://deb.nodesource.com/setup_8.x | sudo bash 
sudo apt install -y nodejs
sudo npm install -g inherits n && sudo n 8.11.4

安装mongodb。

在Ubuntu 18.04上:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
sudo add-apt-repository 'deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse'
sudo apt update
sudo apt -y install mongodb-org
sudo systemctl enable mongod.service && sudo systemctl start mongod.service

在Debian 10:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
sudo apt update
sudo apt -y install mongodb-org
sudo systemctl enable mongod.service && sudo systemctl start mongod.service

第3步:创建Rocketchat系统用户

我们需要一个将用于运行Rocket.chat服务器的用户。
通过下面运行命令创建一个。

sudo useradd -r -m -U -d /srv/rocketchat rocketchat

第4步:下载并安装Rocket.chat

下载最新的Rocket.chat版本:

su - rocketchat
curl -L https://releases.rocket.chat/latest/download -o rocket.chat.tgz

提取下载的存档文件。

tar xvf rocket.chat.tgz
rm rocket.chat.tgz

安装Rocket.Chat服务器

cd bundle/programs/server && npm install

将Bundle目录移动到/SRV/ROCKET文件夹

$mv bundle Rocket.Chat
$ls
Rocket.Chat
$exit

确保文件夹的所有权是正确的。

sudo chown -R rocketchat:rocketchat /srv/rocketchat/Rocket.Chat/

第5步:创建系统文件

我们现在可以创建一个系统服务单元文件。

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

如果我们在DNS中使用有效域,请将其设置为root_url。
例子:

ROOT_URL=http://rocket.example.com

更新系统单元并启动Rocketchat服务。

sudo systemctl daemon-reload
sudo systemctl restart rocketchat

确认服务状态

$systemctl status rocketchat.service 
● rocketchat.service - The Rocket.Chat server
   Loaded: loaded (/etc/systemd/system/rocketchat.service; disabled; vendor preset: enabled)
   Active: active (running) since Sat 2019-07-20 09:38:14 CEST; 8s ago
 Main PID: 11264 (node)
    Tasks: 10 (limit: 4915)
   CGroup: /system.slice/rocketchat.service
           └─11264 /usr/local/bin/node /srv/rocket/Rocket.Chat/main.js
May 20 09:38:14 ubuntu18 systemd[1]: Started The Rocket.Chat server.

截屏。

不要忘记启用Rocket.Chat Service以在启动时启动。

sudo systemctl enable rocketchat

步骤6:配置Nginx反向代理

我们现在可以为Rocket.chat创建一个nginx配置文件

sudo nano /etc/nginx/conf.d/rocketchat.conf

没有SSL:

upstream rocket_backend {
  server 127.0.0.1:3000;
}
server {
    listen 80;
    server_name rocketchat.example.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;
    }
}

使用Let’s Encrypt SSL:

# Upstreams
upstream rocket_backend {
  server 127.0.0.1:3000;
}
# HTTP server with redirect to https
server {
    listen 80;
    server_name rocket.example.com;
    return 301 https://rocket.example.com$request_uri;
}
server {
    listen 443 ssl http2;
    server_name rocket.example.com;
    # Configure SSL
    ssl_certificate /etc/letsencrypt/live/rocket.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/rocket.example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/rocket.example.com/chain.pem;
    include snippets/ssl.conf;
    # Logging
    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;
    }
}

快速获取Let’s Encrypt SSL

wget https://dl.eff.org/certbot-auto
sudo mv certbot-auto /usr/local/bin/
sudo chmod a+x /usr/local/bin/certbot-auto
export DOMAIN="chat.domain.com"
export EMAIL_ALERT="Hyman@theitroad"
/usr/local/bin/certbot-auto certonly --standalone -d $DOMAIN  \
--preferred-challenges http --agree-tos -n -m  $EMAIL_ALERT --keep-until-expiring

检查配置语法:

$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服务。

sudo systemctl restart nginx

服务状态应"正在运行"。

$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 Sat 2019-07-20 09:51:21 CEST; 5s ago
     Docs: man:nginx(8)
  Process: 11510 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
  Process: 11521 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 11511 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 11534 (nginx)
    Tasks: 3 (limit: 4915)
   CGroup: /system.slice/nginx.service
           ├─11534 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
           ├─11535 nginx: worker process
           └─11536 nginx: worker process
May 20 09:51:21 ubuntu18 systemd[1]: Starting A high performance web server and a reverse proxy server...
May 20 09:51:21 ubuntu18 systemd[1]: Started A high performance web server and a reverse proxy server.

访问Rocket.Chat URL http://rocket.example.com,然后按照下一个提示完成安装。