When it comes to monitoring the uptime of your servers and websites, having a reliable tool is essential. Uptime Robot has long been a popular choice, but if you prefer a self-hosted solution, Kuma is an excellent alternative. Built with Nodejs, Kuma offers a beautiful dashboard and supports multiple notification methods, making it a versatile and powerful monitoring tool. In this comprehensive guide, we will walk you through the step-by-step process of installing Kuma on an Ubuntu 20.04 server, setting up Apache as a reverse proxy, and securing your installation with a free Let’s Encrypt SSL certificate.
Prerequisites
Before we dive into the installation process, there are a few prerequisites you’ll need to have in place:
- An Ubuntu 20.04 server.
- A user with root privileges – we’ll use the username “shapehost” throughout this guide.
- Basic knowledge of Linux commands.
Let’s get started!
Adding a New User
To enhance security, it’s recommended to run the Kuma application as a non-root user. We’ll begin by creating a new user called “shapehost” and granting them the necessary privileges.
- Log in to your server as the root user or any user with sudo privileges.
sudo su -
- Create a new user by running the following command, replacing “shapehost” with your desired username.
useradd -m -s /bin/bash shapehost
The -m
option automatically creates a home directory for the user, while the -s
option specifies the default shell for the user (in this case, /bin/bash
).
- Set a password for the new user.
passwd shapehost
Follow the prompts to set a strong password for the user.
- Add the user to the “sudo” group to grant them administrative privileges.
usermod -aG sudo shapehost
By adding the user to the “sudo” group, they will be able to execute commands with root privileges using the sudo
command.
Install NVM (Node Version Manager)
Next, we’ll install NVM (Node Version Manager), a handy tool for managing multiple Node.js versions on a single system. This will allow us to install the required version of Node.js for Kuma.
- Switch to the newly created user.
su - shapehost
- Download and execute the NVM installation script.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
This command will download the NVM installation script and execute it.
- Reload the bash environment.
source ~/.bashrc
This will ensure that the NVM command is available in your current terminal session.
- Verify the NVM installation.
command -v nvm
If the installation was successful, you should see the output nvm
. You can also run nvm --help
to see the NVM command’s manual page.
Install Node.js LTS Version
With NVM installed, we can now proceed to install the required version of Node.js for Kuma.
- Install the LTS (Long-Term Support) version of Node.js.
nvm install --lts
This command will install the latest LTS version of Node.js. It may take a few moments to complete.
- Verify the Node.js installation.
node --version npm --version
If the installation was successful, you should see the versions of Node.js and npm installed on your system.
Download and Install Kuma
Now that we have Node.js installed, we can proceed to download and install Kuma.
- Clone the Kuma source code from the GitHub repository.
git clone https://github.com/louislam/uptime-kuma.git
This command will clone the Kuma repository into a directory named “uptime-kuma”.
- Change to the “uptime-kuma” directory.
cd uptime-kuma
- Install the necessary packages for Kuma using npm.
npm install
This command will download and install all the required dependencies for Kuma.
Setting up Kuma with PM2
PM2 is a process manager for Node.js applications that helps you manage and keep your application running smoothly. We’ll use PM2 to start and manage the Kuma application.
- Install PM2 globally using npm.
npm install -g pm2
This command will install PM2 as a global package, making it accessible from anywhere in your system.
- Start the Kuma application using PM2.
pm2 start npm --name kuma -- run start-server -- --port=3001 --hostname=127.0.0.1
The above command starts the Kuma application, assigns it the name “kuma,” and specifies the port and hostname. Feel free to modify these values according to your requirements.
- Check the status of your Kuma application.
pm2 status
This command will display the status of your Kuma application, including the process ID and other details.
- Set up PM2 to start automatically on system boot.
pm2 startup
Follow the instructions provided by the command to generate the necessary startup script for your system.
- Save the current state of PM2.
pm2 save
This command ensures that your Kuma application will automatically start with PM2 when your system boots up.
Setting up Apache as a Reverse Proxy
To access the Kuma application from a web browser, we’ll configure Apache as a reverse proxy. This will allow Apache to forward requests to the Kuma application running on port 3001.
- Install Apache web server.
sudo apt install apache2
- Enable the required Apache modules.
sudo a2enmod ssl proxy proxy_ajp proxy_wstunnel proxy_http rewrite deflate headers proxy_balancer proxy_connect proxy_html
These modules are necessary for Apache to act as a reverse proxy.
- Create a new virtual host configuration file for Kuma.
sudo nano /etc/apache2/sites-available/kuma.conf
Paste the following configuration into the file, replacing yourdomain.com
with your actual domain name.
<VirtualHost *:80>
ServerName yourdomain.com
ProxyPass / http://localhost:3001/
RewriteEngine on
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule ^/?(.*) "ws://localhost:3001/$1" [P,L]
</VirtualHost>
Save the file and exit the text editor.
- Enable the new virtual host configuration.
sudo a2ensite kuma
- Test the Apache configuration.
sudo apachectl configtest
If the configuration is valid, you should see the message Syntax OK
.
- Restart Apache to apply the changes.
sudo systemctl restart apache2
Securing Kuma with SSL using Let’s Encrypt
To secure the access to your Kuma application, we’ll use Let’s Encrypt to obtain an SSL certificate for your domain.
- Install the Certbot tool.
sudo apt install python3-certbot-apache
- Generate the SSL certificate.
sudo certbot --apache -d yourdomain.com
Follow the prompts to register your email address and agree to the Let’s Encrypt Terms of Service. Certbot will automatically configure Apache to use the SSL certificate.
- Test the SSL configuration.
sudo certbot renew --dry-run
If the test is successful, Certbot will automatically renew your SSL certificate when it is close to expiration.
Verifying the Kuma Installation
Now that everything is set up, let’s verify your Kuma installation and access the beautiful dashboard.
- Open your web browser and enter the URL for your Kuma installation.
https://yourdomain.com/
You should be redirected to a secure HTTPS connection.
- On the initial setup page, create a new admin user for Kuma.
- Log in with your new username and password.
Congratulations! You have successfully installed Kuma and set up Apache as a reverse proxy with SSL encryption. You can now start adding hosts to monitor and receive notifications for any downtime incidents.
Conclusion
In this guide, we have covered the step-by-step process of installing Kuma, a self-hosted Uptime Robot alternative, on an Ubuntu 20.04 server. We have also configured Apache as a reverse proxy and secured the installation with a Let’s Encrypt SSL certificate. Kuma’s beautiful dashboard and versatile notification methods make it an excellent choice for monitoring the uptime of your servers and websites.
With Kuma and Shape.host’s Linux SSD VPS services, you can ensure the reliability and performance of your online assets. Shape.host offers scalable and secure cloud hosting solutions, empowering businesses with efficient and dependable hosting services.