Rocket.Chat
官方给出的文档也个人觉得太麻烦了,并且对ubuntu的支持程度远高于CentOS,自己就折腾写了个安装的笔记,如果是在公司内部或者是部门内部还是很有用处的,比较看中的功能有和gitlab或github的整合,以及注册认证和消息邮件外发
官方文档:
环境依赖
- CentOS6.5
- Nginx
- Mongodb v2
安装步骤
- 安装Mongodb
vim /etc/yum.repos.d/mongodb.repo
写入以下内容
[mongodb-org]name=MongoDB Repositorybaseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/gpgcheck=1enabled=1gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc
Run
yum -y install epel-release curl GraphicsMagick npm mongodb-org-server mongodb-org gcc-c++
提前配置数据库
mongo>use rocketchat //添加数据库>exitservice mongod restart
- 安装node.js
这里就按照官方给出的文档安装了,那个有点麻烦
curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -yum -y install nodejs
- 安装Rocket.Chat
cd /optcurl -L https://releases.rocket.chat/latest/download -o rocket.chat.tar.gztar zxvf rocket.chat.tgzmv bundle Rocket.Chatcd Rocket.Chat/programs/servernpm installcd ../..
配置 PORT, ROOT_URL and MONGO_URL:
export PORT=3000export ROOT_URL=http://your-host-name.com-as-accessed-from-internet:3000/export MONGO_URL=mongodb://localhost:27017/rocketchat
启动服务
service mongod restart && chkconfig mongod onservice nginx start && chkconfig nginx on
- 启动服务
node main.js
现在就能登录http://your-host-name.com-as-accessed-from-internet:3000/
进行访问了
配置Nginx+SSL代理
- 安装nginx
yum -y install nginx
- 配置Nginx
创建自签证书
首先,创建证书和私钥的目录# mkdir -p /etc/nginx/cert# cd /etc/nginx/cert创建服务器私钥,命令会让你输入一个口令:# openssl genrsa -des3 -out nginx.key 2048创建签名请求的证书(CSR):# openssl req -new -key nginx.key -out nginx.csr在加载SSL支持的Nginx并使用上述私钥时除去必须的口令:# cp nginx.key nginx.key.org# openssl rsa -in nginx.key.org -out nginx.key最后标记证书使用上述私钥和CSR:# openssl x509 -req -days 365 -in nginx.csr -signkey nginx.key -out nginx.crt
配置rocketchat.conf
vim /etc/nginx/nginx.d/rocketchat.conf
注意将默认的default.conf删除掉,不然影响80端口server { listen 80; server_name im.mydomain.com; return 301 https://$host$request_uri;}# HTTPS Serverserver { listen 443; server_name im.mydomain.com; error_log off; ssl on; ssl_certificate /etc/nginx/cert/nginx.crt; ssl_certificate_key /etc/nginx/cert/nginx.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; location / { proxy_pass http://127.0.0.1:3000/; 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; }}
Auto Start Rocket.Chat
- CentOS7
CentOS7下推荐如下配置,添加一个服务项:
[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=root Environment=MONGO_URL=mongodb://localhost:27017/rocketchat ROOT_URL=http://your-host-name.com-as-accessed-from-internet:3000/ PORT=3000 [Install] WantedBy=multi-user.target
Now you can enable this service by running:
systemctl enable rocketchat.servicesystemctl start rocketchat.service
- CentOS6
CentOS6下推荐使用Supervisor服务,需要我们写个脚本来自动执行,这样的话就能免去很多步骤
安装supervisor
yum install supervisor
编辑脚本并添加执行全权限
vim /opt/Rocket.Chat/start.sh
chmod +x /opt/Rocket.Chat/start.sh 脚本内容如下#/bin/bashcd /opt/Rocket.Chat/export PORT=3000export ROOT_URL=http://your-host-name.com-as-accessed-from-internet:3000/ //根据自己的环境修改配置export MONGO_URL=mongodb://localhost:27017/rocketchatnode /opt/Rocket.Chat/main.js
配置supervisord服务
vim /etc/supervisord.conf
在最后添加一下内容
[program:rocketchat]command=bash /opt/Rocket.Chat/start.shdirectory=/opt/Rocket.Chatautostart=trueautorestart=truelogfile=/var/log/supervisor/rocketchat.loglog_stderr=trueuser=root
启动supervisord
service supervisord start && chkconfig supervisord on
此时rocket也就一起起来了