Rocket.Chat
官方給出的文檔也個人覺得太麻煩了,並且對ubuntu的支持程度遠高於CentOS,自己就折騰寫了個安裝的筆記,如果是在公司內部或者是部門內部還是很有用處的,比較看中的功能有和gitlab或github的整合,以及注冊認證和消息郵件外發
官方文檔:https://rocket.chat/docs/installation/manual-installation/centos/
環境依賴
- CentOS6.5
- Nginx
- Mongodb v2
安裝步驟
- 安裝Mongodb
vim /etc/yum.repos.d/mongodb.repo
寫入以下內容
[mongodb-org]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/
gpgcheck=1
enabled=1
gpgkey=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 //添加數據庫
>exit
service mongod restart
- 安裝node.js
這里就按照官方給出的文檔安裝了,那個有點麻煩
curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -
yum -y install nodejs
- 安裝Rocket.Chat
cd /opt
curl -L https://releases.rocket.chat/latest/download -o rocket.chat.tar.gz
tar zxvf rocket.chat.tgz
mv bundle Rocket.Chat
cd Rocket.Chat/programs/server
npm install
cd ../..
配置 PORT, ROOT_URL and MONGO_URL:
export PORT=3000
export ROOT_URL=http://your-host-name.com-as-accessed-from-internet:3000/
export MONGO_URL=mongodb://localhost:27017/rocketchat
啟動服務
service mongod restart && chkconfig mongod on
service 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 Server
server {
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.service
systemctl start rocketchat.service
- CentOS6
CentOS6下推薦使用Supervisor服務,需要我們寫個腳本來自動執行,這樣的話就能免去很多步驟
安裝supervisor
yum install supervisor
編輯腳本並添加執行全權限
vim /opt/Rocket.Chat/start.sh
chmod +x /opt/Rocket.Chat/start.sh
腳本內容如下
#/bin/bash
cd /opt/Rocket.Chat/
export PORT=3000
export ROOT_URL=http://your-host-name.com-as-accessed-from-internet:3000/ //根據自己的環境修改配置
export MONGO_URL=mongodb://localhost:27017/rocketchat
node /opt/Rocket.Chat/main.js
配置supervisord服務
vim /etc/supervisord.conf
在最后添加一下內容
[program:rocketchat]
command=bash /opt/Rocket.Chat/start.sh
directory=/opt/Rocket.Chat
autostart=true
autorestart=true
logfile=/var/log/supervisor/rocketchat.log
log_stderr=true
user=root
啟動supervisord
service supervisord start && chkconfig supervisord on
此時rocket也就一起起來了
