To install MongoDB, follow this guide
Modify the following MongoDB config parameters in /etc/mongod.conf
storage:
engine: wiredTiger
replication:
replSetName: rs01
Use Node.js version 14.x for Rocket.Chat. Newer versions of Node.js are unsupported and likely will not allow Rocket.Chat to run!
To install Node.js, follow this guide
Install required packages
apt install curl build-essential mongodb-org graphicsmagick nodejs apache2
Download the latest Rocket.Chat
curl -L https://releases.rocket.chat/latest/download -o /tmp/rocket.chat.tgz
Extract the archive with tar
tar xzf /tmp/rocket.chat.tgz -C /tmp
You should now see a new directory under /tmp
named bundle
.
Install the Node.js dependencies
(cd /tmp/bundle/programs/server; npm i)
Move Rocket.Chat to /opt
mv /tmp/bundle /opt/Rocket.Chat
Add the rocketchat user
useradd -M rocketchat && usermod -L rocketchat
Set permissions on the new rocket.chat directory
chown -R rocketchat:rocketchat /opt/Rocket.Chat
Create a new systemd file with the following contents
cat << EOF | tee -a /lib/systemd/system/rocketchat.service
[Unit]
Description=The Rocket.Chat server
After=network.target remote-fs.target nss-lookup.target nginx.service mongod.service
[Service]
ExecStart=/usr/bin/node /opt/Rocket.Chat/main.js
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=rocketchat
User=rocketchat
Environment=MONGO_URL=mongodb://localhost:27017/rocketchat?replicaSet=rs01
Environment=MONGO_OPLOG_URL=mongodb://localhost:27017/local?replicaSet=rs01
Environment=ROOT_URL=http://localhost:3000/
Environment=PORT=3000
[Install]
WantedBy=multi-user.target
EOF
Open the new service file and modify the following parameters.
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
Start MongoDB
systemctl enable --now mongod.service
Create the MongoDB replicaset
mongo --eval "printjson(rs.initiate())"
Start Rocket.Chat
systemctl enable --now rocketchat
Setup apache reverse proxy with these instructions.
a2enmod proxy
a2enmod proxy_http
a2enmod proxy_wstunnel
a2enmod rewrite
Virtual Config Example
<VirtualHost *:443>
ServerAdmin it@domain.com
ServerName chat.domain.com
LogLevel info
ErrorLog /var/log/chat.domain.com_error.log
TransferLog /var/log/chat.domain.com_access.log
SSLEngine On
SSLCertificateFile /etc/ssl/certs/chat.domain.com.crt
SSLCertificateKeyFile /etc/ssl/private/chat.domain.com.key
SSLCertificateChainFile /etc/ssl/certs/intermediate.ca.pem
<Location />
Require all granted
</Location>
RewriteEngine On
RewriteCond %{HTTP:CONNECTION} Upgrade [NC]
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*) ws://localhost:3000/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*) http://localhost:3000/$1 [P,L]
ProxyPassReverse / http://localhost:3000/
</VirtualHost>
Stop Rocket.Chat service
systemctl stop rocketchat.service
Remove the installation folder
rm -rf /opt/Rocket.Chat
Download the latest Rocket.Chat version
curl -L https://releases.rocket.chat/latest/download -o /tmp/rocket.chat.tgz
Extract the download
tar -xzf /tmp/rocket.chat.tgz -C /tmp
Use NPM to install
cd /tmp/bundle/programs/server && npm install
Move Rocket.Chat to /opt/
mv /tmp/bundle /opt/Rocket.Chat
Set the correct ownership
chown -R rocketchat:rocketchat /opt/Rocket.Chat
Start the Rocket.Chat service again
systemctl start rocketchat.service
systemctl status rocketchat.service
#!/bin/sh
whoami
date
stoprocket="systemctl stop rocketchat.service"
removerocket="rm -rf /opt/Rocket.Chat"
downloadrocket="curl -L https://releases.rocket.chat/latest/download -o /tmp/rocket.chat.tgz"
unpackrocket="tar -xzf /tmp/rocket.chat.tgz -C /tmp"
installrocket="cd /tmp/bundle/programs/server && npm install"
moverocket="mv /tmp/bundle /opt/Rocket.Chat"
chownrocket="chown -R rocketchat:rocketchat /opt/Rocket.Chat"
startrocket="systemctl start rocketchat.service"
statusrocket="systemctl status rocketchat.service"
updaterocketchat () {
echo $stoprocket
$stoprocket
echo "\n"
sleep 5
echo $removerocket
$removerocket
echo "\n"
sleep 2
echo $downloadrocket
$downloadrocket
echo "\n"
sleep 2
echo $unpackrocket
$unpackrocket
echo "\n"
sleep 2
echo $installrocket
eval $installrocket
echo "\n"
sleep 2
echo $moverocket
$moverocket
echo "\n"
sleep 2
echo $chownrocket
$chownrocket
echo "\n"
echo $startrocket
$startrocket
echo "\n$startrocket\n"
sleep 1
echo $statusrocket
$statusrocket
}
printf "\nPrepare to GetBent, bitch! (and update RocketChat)\n\n"
sleep 1s
printf "This script will execute the following commands:
1 - $stoprocket
2 - $removerocket
3 - $downloadrocket
4 - $unpackrocket
5 - $installrocket
6 - $moverocket
7 - $chownrocket
8 - $startrocket
9 - $statusrocket
"
while true; do
read -p "Would you like to proceed with updating RocketChat? [Y/Nn]" yn1
case $yn1 in
[Y]* ) updaterocketchat; break;;
[Nn]* ) $statusrocket; exit;;
* ) echo "Please answer Yes or No.";;
esac
done