Rocket.Chat开源聊天软件部署

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

  • 火箭聊天3.0.0
  • 作业系统:CentOS 7.6
  • Mongodb 4.0.9
  • NodeJS 12.14.0

1.安装必要的依赖包

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

  1. yum -y check-update
  1. cat << EOF | sudo tee -a /etc/yum.repos.d/mongodb-org-4.0.repo
  2. [mongodb-org-4.0]
  3. name=MongoDB Repository
  4. baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.0/x86_64/
  5. gpgcheck=1
  6. enabled=1
  7. gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
  8. EOF

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

  1. yum install -y curl && curl -sL https://rpm.nodesource.com/setup_12.x | sudo bash -

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

  1. yum install -y gcc-c++ make mongodb-org nodejs
  2. yum install -y epel-release && sudo yum install -y GraphicsMagick

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

  1. npm install -g inherits n && sudo n 12.14.0

2.安装Rocket.Chat

下载最新的Rocket.Chat版本:

  1. curl -L https://releases.rocket.chat/latest/download -o /tmp/rocket.chat.tgz
  2. tar -xzf /tmp/rocket.chat.tgz -C /tmp

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

  1. cd /tmp/bundle/programs/server && npm install
  2. sudo mv /tmp/bundle /opt/Rocket.Chat
  3. #注意:npm install安装失败的话,请查看报错信息
  4. [root@xxg-sit-rocket-58 server]# npm install
  5. npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
  6. > fibers@4.0.3 install /tmp/bundle/programs/server/node_modules/fibers
  7. > node build.js || nodejs build.js
  8. make: Entering directory `/tmp/bundle/programs/server/node_modules/fibers/build'
  9. CXX(target) Release/obj.target/fibers/src/fibers.o
  10. make: g++: Command not found
  11. make: *** [Release/obj.target/fibers/src/fibers.o] Error 127
  12. make: Leaving directory `/tmp/bundle/programs/server/node_modules/fibers/build'
  13. gyp ERR! build error
  14. 。。。。。。。
  15. Please make sure you are using a supported platform and node version. If you
  16. would like to compile fibers on this machine please make sure you have setup your
  17. build environment--
  18. Windows + OS X instructions here: https://github.com/nodejs/node-gyp
  19. Ubuntu users please run: `sudo apt-get install g++ build-essential`
  20. RHEL users please run: `yum install gcc-c++` and `yum groupinstall 'Development Tools'`
  21. Alpine users please run: `sudo apk add python make g++`
  22. 这是因为缺少依赖,根据提示安装RHEL users please run: `yum install gcc-c++` and `yum groupinstall 'Development Tools'`

3.配置Rocket.Chat服务

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

  1. sudo useradd -M rocketchat && sudo usermod -L rocketchat
  1. sudo chown -R rocketchat:rocketchat /opt/Rocket.Chat
  1. cat << EOF |sudo tee -a /lib/systemd/system/rocketchat.service
  2. [Unit]
  3. Description=The Rocket.Chat server
  4. After=network.target remote-fs.target nss-lookup.target nginx.target mongod.target
  5. [Service]
  6. ExecStart=/usr/local/bin/node /opt/Rocket.Chat/main.js
  7. StandardOutput=syslog
  8. StandardError=syslog
  9. SyslogIdentifier=rocketchat
  10. User=rocketchat
  11. 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
  12. [Install]
  13. WantedBy=multi-user.target
  14. EOF

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

  1. MONGO_URL=mongodb://localhost:27017/rocketchat?replicaSet=rs01
  2. MONGO_OPLOG_URL=mongodb://localhost:27017/local?replicaSet=rs01
  3. ROOT_URL=http://your-host-name.com-as-accessed-from-internet:3000
  4. PORT=3000

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

  1. sed -i "s/^# engine:/ engine: mmapv1/" /etc/mongod.conf
  2. sed -i "s/^#replication:/replication:\n replSetName: rs01/" /etc/mongod.conf
  3. systemctl enable mongod && sudo systemctl start mongod
  4. mongo --eval "printjson(rs.initiate())"
  5. sudo systemctl enable rocketchat && sudo systemctl start rocketchat

4.配置您的Rocket.Chat服务器

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

0.4373970413084766.png

官方网站参考:https://rocket.chat/docs/installation/manual-installation/centos/

5.配置反向代理

  1. #安装nginx
  2. [root@rock-31 ~]# yum install nginx -y
  3. #配置nginx文件
  4. [root@rock-31 ~]# cd /etc/nginx/conf.d/
  5. [root@rock-31 conf.d]# cat rocketchat.conf
  6. upstream backend {
  7. server 127.0.0.1:3000;
  8. }
  9. # HTTPS Server
  10. server {
  11. listen 80;
  12. server_name rocket.xxg.com;
  13. # You can increase the limit if your need to.
  14. client_max_body_size 200M;
  15. error_log /var/log/nginx/rocketchat.access.log;
  16. location / {
  17. proxy_pass http://backend/;
  18. proxy_http_version 1.1;
  19. proxy_set_header Upgrade $http_upgrade;
  20. proxy_set_header Connection "upgrade";
  21. proxy_set_header Host $http_host;
  22. proxy_set_header X-Real-IP $remote_addr;
  23. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  24. proxy_set_header X-Forward-Proto http;
  25. proxy_set_header X-Nginx-Proxy true;
  26. proxy_redirect off;
  27. }
  28. }
  29. #启动nginx
  30. [root@rock-31 conf.d]# nginx

最后的结果:

bf039cea-0569-4d9c-a966-44100f348d3d.png

6.排错

0c373f39-9135-4ca1-a89f-5c45dc215e14.png

整整搞了一个上午,一直在纠结Site Url:http://localhost:3000/如何修改成对应的IP地址,百度了一上午,终于解决了

  1. #在mongo里面修改Site Url
  2. [root@rock-31 system]# mongo
  3. rs01:PRIMARY> use rocketchat
  4. rs01:PRIMARY> db.rocketchat_settings.update({"_id" : "Site_Url"},{$set:{value:"10.4.7.31:3000"}})
  5. [root@rock-31 system]# systemctl restart rocketchat.service

dc694ffb-cf61-4d97-805c-83942765b1d5.png

最后总算是解决了无法传送文件的问题。