本文介绍在Debian 10/Ubuntu 18.04操作系统上安装Rocket.Chat服务器的方法,我们将在设置过程中使用:Nginx网络服务器、加密SSL证书、Node.js、MongoDB,如果你的服务器位于专用网络上,则可以生成并使用自签名证书代替Let's Encrypt,这是更推荐的,而不是在普通的http上运行Rocket.Chat服务器。Rocket.Chat是一个自托管的聊天平台,它是开源的,也是最受欢迎的备选方案之一,Rocket.Chat免费安装附带的一些很实用的功能是文件共享、视频会议、聊天、音频消息,如果你正在寻找一个开源消息传递平台来托管在云中运行的VPS或本地数据中心,那么此解决方案适合你。
一、更新系统和安装所需的依赖项 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 如果你不想要存储库Node.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 参考:在Ubuntu/Debian/Linux Mint上安装Node.js 12的方法。 3、安装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 参考:在Ubuntu系统上安装MongoDB及配置和卸载MongoDB的两种方法。 在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
二、创建rocketchat系统用户和下载并安装Rocket.Chat 1、创建rocketchat系统用户 我们需要一个用于运行Rocket.Chat服务器的用户,通过运行以下命令创建一个: sudo useradd -r -m -U -d /srv/rocketchat rocketchat 2、下载并安装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/
三、创建Systemd单元文件 我们现在可以创建一个Systemd服务单元文件: 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 更新systemd单元并启动rocketchat服务: sudo systemctl daemon-reload sudo systemctl restart rocketchat 确认服务状态: $ systemctl status rocketchat.service 截图如下:
不要忘记在启动时启用Rocket.Chat服务: sudo systemctl enable rocketchat
四、配置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的加密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的加密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="admin@domain.com" /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 服务状态应为“running”,如下图: $ systemctl status nginx
访问http://rocket.example.com上的Rocket.Chat URL,然后按照下一个提示完成安装即可。
相关主题 |