Rocket.Chat开源聊天软件部署
本安装指南已在以下环境中进行了测试:
- 火箭聊天3.0.0
- 作业系统:CentOS 7.6
- Mongodb 4.0.9
- NodeJS 12.14.0
1.安装必要的依赖包
更新软件包列表并将yum配置为使用以下yum存储库文件安装正式的MongoDB软件包:
yum -y check-update
cat << EOF | 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
EOF
配置要通过软件包管理器安装的Node.js:
yum install -y curl && curl -sL https://rpm.nodesource.com/setup_12.x | sudo bash -
安装构建工具,MongoDB,nodejs和graphicsmagick:
yum install -y gcc-c++ make mongodb-org nodejs
yum install -y epel-release && sudo yum install -y GraphicsMagick
使用npm install继承了和n,以及Rocket.Chat所需的节点版本:
npm install -g inherits n && sudo n 12.14.0
2.安装Rocket.Chat
下载最新的Rocket.Chat版本:
curl -L https://releases.rocket.chat/latest/download -o /tmp/rocket.chat.tgz
tar -xzf /tmp/rocket.chat.tgz -C /tmp
安装(本指南使用/ opt,但可以选择其他目录):
cd /tmp/bundle/programs/server && npm install
sudo mv /tmp/bundle /opt/Rocket.Chat
#注意:npm install安装失败的话,请查看报错信息
[root@xxg-sit-rocket-58 server]# npm install
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
> fibers@4.0.3 install /tmp/bundle/programs/server/node_modules/fibers
> node build.js || nodejs build.js
make: Entering directory `/tmp/bundle/programs/server/node_modules/fibers/build'
CXX(target) Release/obj.target/fibers/src/fibers.o
make: g++: Command not found
make: *** [Release/obj.target/fibers/src/fibers.o] Error 127
make: Leaving directory `/tmp/bundle/programs/server/node_modules/fibers/build'
gyp ERR! build error
。。。。。。。
Please make sure you are using a supported platform and node version. If you
would like to compile fibers on this machine please make sure you have setup your
build environment--
Windows + OS X instructions here: https://github.com/nodejs/node-gyp
Ubuntu users please run: `sudo apt-get install g++ build-essential`
RHEL users please run: `yum install gcc-c++` and `yum groupinstall 'Development Tools'`
Alpine users please run: `sudo apk add python make g++`
这是因为缺少依赖,根据提示安装RHEL users please run: `yum install gcc-c++` and `yum groupinstall 'Development Tools'`
3.配置Rocket.Chat服务
添加rocketchat用户,在Rocket.Chat文件夹上设置正确的权限,并创建Rocket.Chat服务文件:
sudo useradd -M rocketchat && sudo usermod -L rocketchat
sudo chown -R rocketchat:rocketchat /opt/Rocket.Chat
cat << EOF |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
EOF
/usr/lib/systemd/system/rocketchat.service使用sudo和您喜欢的文本编辑器打开刚刚创建的Rocket.Chat服务文件(),然后更改ROOT_URL环境变量以反映您要用于访问服务器的URL(可以选择更改MONGO_URL,MONGO_OPLOG_URL和PORT):
MONGO_URL=mongodb://localhost:27017/rocketchat?replicaSet=rs01
MONGO_OPLOG_URL=mongodb://localhost:27017/local?replicaSet=rs01
ROOT_URL=http://your-host-name.com-as-accessed-from-internet:3000
PORT=3000
为MongoDB设置存储引擎和复制(对于版本> 1为必需),并启用并启动MongoDB和Rocket.Chat:
sed -i "s/^# engine:/ engine: mmapv1/" /etc/mongod.conf
sed -i "s/^#replication:/replication:\n replSetName: rs01/" /etc/mongod.conf
systemctl enable mongod && sudo systemctl start mongod
mongo --eval "printjson(rs.initiate())"
sudo systemctl enable rocketchat && sudo systemctl start rocketchat
4.配置您的Rocket.Chat服务器
打开Web浏览器并访问配置的ROOT_URL(http://your-host-name.com-as-accessed-from-internet:3000),按照配置步骤设置管理员帐户以及您的组织和服务器信息。
官方网站参考:https://rocket.chat/docs/installation/manual-installation/centos/
5.配置反向代理
#安装nginx
[root@rock-31 ~]# yum install nginx -y
#配置nginx文件
[root@rock-31 ~]# cd /etc/nginx/conf.d/
[root@rock-31 conf.d]# cat rocketchat.conf
upstream backend {
server 127.0.0.1:3000;
}
# HTTPS Server
server {
listen 80;
server_name rocket.xxg.com;
# You can increase the limit if your need to.
client_max_body_size 200M;
error_log /var/log/nginx/rocketchat.access.log;
location / {
proxy_pass http://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-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forward-Proto http;
proxy_set_header X-Nginx-Proxy true;
proxy_redirect off;
}
}
#启动nginx
[root@rock-31 conf.d]# nginx
最后的结果:
6.排错
整整搞了一个上午,一直在纠结Site Url:http://localhost:3000/如何修改成对应的IP地址,百度了一上午,终于解决了
#在mongo里面修改Site Url
[root@rock-31 system]# mongo
rs01:PRIMARY> use rocketchat
rs01:PRIMARY> db.rocketchat_settings.update({"_id" : "Site_Url"},{$set:{value:"10.4.7.31:3000"}})
[root@rock-31 system]# systemctl restart rocketchat.service
最后总算是解决了无法传送文件的问题。