Centrifugo is a real-time messaging server that allows you to broadcast messages to multiple clients at once. In this tutorial, we will guide you through the installation of Centrifugo on Ubuntu Server.
Before you start the installation process, confirm that the following prerequisites are in place:
A server running Ubuntu 20.04, 18.04 or 16.04 version
Access to a terminal window or SSH client with sudo permissions
Installed Nginx web server
The first step is to install the dependencies required by Centrifugo:
sudo apt-get update
sudo apt-get install wget build-essential
To download the latest version of Centrifugo using the following command:
wget https://github.com/centrifugal/centrifugo/releases/download/v3.1.0/centrifugo-3.1.0-linux-amd64.zip
Once the download is complete, unzip the package to the /usr/local/bin/
directory:
sudo unzip centrifugo-*.zip -d /usr/local/bin/
Next, make the centrifugo binary executable by running the following command:
sudo chmod +x /usr/local/bin/centrifugo
Create a configuration file for centrifugo using the command:
sudo nano /etc/centrifugo/config.json
Enter the below configuration in the json file:
{
"secret": "Shhh it's a Secret",
"api_key": "yourapikey",
"admin_password": "youradminpassword",
"log_level": "debug",
"websocket": {
"enabled": true,
"sockjs": false,
"tls": false,
"port": 8000,
"address": "0.0.0.0",
"api_key": "",
"admin_password": "",
"api_insecure": true,
"compression": true,
"allow_anonymous": true,
"allow_pubsub": true
},
"engine": {
"type": "memory"
},
"control": {
"enabled": true,
"port": 8001,
"api_key": "",
"admin_password": "",
"api_insecure": true
}
}
Once done, save and close the file.
Execute the below command to create the systemd unit file for Centrifugo:
sudo nano /etc/systemd/system/centrifugo.service
Enter the below configuration in the file:
[Unit]
Description=Centrifugo Service
Requires=network.target
[Service]
User=root
Group=root
WorkingDirectory=/etc/centrifugo
ExecStart=/usr/local/bin/centrifugo -c /etc/centrifugo/config.json
Restart=on-abnormal
[Install]
WantedBy=multi-user.target
Save and close the file.
Once the unit file is created, reload the systemd daemon:
sudo systemctl daemon-reload
Start and enable the Centrifugo service using the following command:
sudo systemctl start centrifugo
sudo systemctl enable centrifugo
Open the nginx configuration file using the following command:
sudo nano /etc/nginx/sites-available/default
Enter the following configuration in the server section:
location /connection/websocket {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://127.0.0.1:8000/connection/websocket;
}
Save and close the file.
Then, restart the Nginx web server:
sudo systemctl restart nginx
You can access the Centrifugo web dashboard by visiting your server's IP address on your web browser:
http://your_server_ip:8000/
You can log in with the admin panel by providing the URL with /admin
endpoint:
http://your_server_ip:8000/admin
Enter the admin password that you configured earlier.
Congratulations! You have successfully installed and configured the Centrifugo real-time messaging server on Ubuntu Server.
If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!
Alternatively, for the best virtual desktop, try Shells!