Netdata is a powerful and versatile open-source monitoring system that allows you to collect real-time metrics from various operating systems, including Linux, Unix, Windows, and macOS. It also supports containerized technologies such as Docker and Kubernetes. In this comprehensive guide, we will walk you through the step-by-step process of installing Netdata on an AlmaLinux 9 server, along with Nginx as a reverse proxy for added security and convenience.
Prerequisites
Before diving into the installation process, make sure you have the following prerequisites:
- An AlmaLinux 9 server
- A non-root user with administrator privileges
- SELinux set to permissive mode
Setting up Repositories
The first step is to add and enable the necessary repositories for Netdata. We will add the EPEL and Netdata repositories and enable the RHEL CRB (Code Ready Build) repository on your AlmaLinux server. Follow these steps:
- Install the
dnf-plugins-core
package by running the following command:
sudo dnf install dnf-plugins-core -y
- Add the EPEL repository and enable the CRB repository on your system with the following commands:
sudo dnf install epel-release sudo dnf config-manager --set-enabled crb
- Add the Netdata repository to your system by executing the following command:
sudo rpm -ivh https://repo.netdata.cloud/repos/stable/el/9/x86_64/netdata-repo-2-2.noarch.rpm
- Verify the available repositories on your AlmaLinux machine with the command:
sudo dnf repolist
Downloading and Installing Netdata
Now that the repositories are set up, it’s time to install Netdata. In this example, we will install Netdata with additional plugins to monitor your system and applications. Follow the steps below:
- Install Netdata and the desired plugins by running the following command:
sudo dnf install netdata netdata-plugin-{apps,chartsd,cups,ebpf,go,pythond,perf,freeipmi,slabinfo,systemd-journal}
- Start and enable the Netdata service with the following commands:
sudo systemctl start netdata sudo systemctl enable netdata
- Verify the status of the Netdata service by executing the command:
sudo systemctl status netdata
- Open the default Netdata port 19999 temporarily by running the command:
sudo firewall-cmd --add-port=19999/tcp
- Visit your server’s IP address followed by port 19999 using your preferred web browser (e.g.,
http://192.168.5.50:19999
). You should see the Netdata dashboard if the installation was successful.
Configuring Netdata
After installing Netdata, it’s time to configure it to run using the UNIX sock file. This will allow us to set up Nginx as a reverse proxy for Netdata in the next step. Follow these steps:
- Download the Netdata configuration file by running the following command:
sudo wget -O /etc/netdata/netdata.conf http://localhost:19999/netdata.conf
- Navigate to the
/etc/netdata
directory and open thenetdata.conf
file using the command:
cd /etc/netdata sudo ./edit-config netdata.conf
- Find the
[web]
section and uncomment thebind to
option. Change the default bind option toUNIX socket unix:/var/run/netdata/netdata.sock
. The configuration should look like this:
[web] bind to = unix:/var/run/netdata/netdata.sock
- Save and close the file.
- Restart Netdata to apply the changes:
sudo systemctl restart netdata
- Verify that Netdata is running as a UNIX socket by executing the following command:
ss -pl | grep netdata.sock
Installing Nginx as a Reverse Proxy
Now that Netdata is installed and configured, we can proceed with installing and configuring Nginx as a reverse proxy for Netdata. This will provide additional security and convenience by allowing us to access Netdata through Nginx. Follow these steps:
- Install Nginx by running the following command:
sudo dnf install nginx
- Create a server block directory and open the Nginx configuration file by executing the following commands:
sudo mkdir -p /etc/nginx/server-blocks sudo nano /etc/nginx/nginx.conf
- Within the
http {...}
section, add theinclude
option as shown below:
http{ ... include /etc/nginx/server-blocks/*.conf; }
- Save and close the file.
- Create a new Nginx server block configuration file for Netdata reverse proxy by running the following command:
sudo nano /etc/nginx/server-blocks/netdata.conf
- Insert the following configuration into the file. Replace
netdata.shapehost.io
with your desired domain name:
upstream backend { server unix:/var/run/netdata/netdata.sock; keepalive 1024; } server { listen 80; server_name netdata.shapehost.io; auth_basic "Protected"; auth_basic_user_file /etc/nginx/.passwords; location / { proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://backend; proxy_http_version 1.1; proxy_pass_request_headers on; proxy_set_header Connection "keep-alive"; proxy_store off; } }
- Save and close the file.
- Generate a password file for Nginx basic authentication by running the following command. Replace
alice
with your desired username and enter your password when prompted:
printf "alice:$(openssl passwd -apr1)" > /etc/nginx/.passwords
- Verify the syntax of the Nginx configuration by running the command:
sudo nginx -t
- Start and enable Nginx with the following commands:
sudo systemctl start nginx sudo systemctl enable nginx
- Verify that Nginx is running by executing the command:
sudo systemctl status nginx
- Open the HTTP and HTTPS ports on your AlmaLinux server by running the following command:
sudo firewall-cmd --add-service={http,https} --permanent sudo firewall-cmd --reload
- Verify the firewall rules by running the command:
sudo firewall-cmd --list-all
- Visit your Netdata domain name (e.g.,
http://netdata.shapehost.io
) in your web browser. You will be prompted for your Nginx basic authentication credentials. If everything is set up correctly, you should see the Netdata monitoring dashboard.
Securing Netdata with SSL/TLS Certificates
To secure your Netdata installation, you can generate SSL/TLS certificates using Certbot. If you’re using a local domain name, you can generate self-signed certificates. If you have a real domain name, follow these steps:
- Install Certbot and the Certbot Nginx plugin by running the following command:
sudo dnf install certbot python3-certbot-nginx -y
- Generate SSL/TLS certificates from Let’s Encrypt by running the following command. Replace
netdata.shapehost.io
with your domain name andtest@shapehost.io
with your email address:
sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email test@shapehost.io -d netdata.shapehost.io
- Once the process is complete, your Netdata installation should be secured with HTTPS.
Example: Monitoring Nginx with Netdata
Now that Netdata is installed, configured, and secured, let’s explore how to use it to monitor Nginx. This example will demonstrate how to monitor the Nginx web server using Netdata, giving you insights into its performance and resource utilization. Follow these steps:
- Create a new configuration file for enabling the Nginx
stub_status
module by running the following command:
sudo nano /etc/nginx/default.d/stub.conf
- Insert the following configuration to enable the Nginx
stub_status
module and expose it at the URL/basic_status
:
location/basic_status{ stub_status; server_tokens on; }
- Save and close the file.
- Verify the Nginx syntax by running the command:
sudo nginx -t
- Restart Nginx to apply the changes:
sudo systemctl restart nginx
- Verify the Nginx
stub_status
module by running the following command:
curl http://localhost/basic_status
- If the configuration is successful, you should see the status information from your Nginx web server.
- Open the Netdata dashboard and navigate to the Nginx section. You should be able to see detailed monitoring information about your Nginx server.
Conclusion
Congratulations! You have successfully installed Netdata on your AlmaLinux 9 server and configured it with Nginx as a reverse proxy. By following this guide, you have gained the ability to monitor system metrics and applications in real-time, empowering you to make informed decisions about your infrastructure.
Netdata, combined with the power and reliability of Shape.host’s Cloud VPS services, provides you with a comprehensive monitoring solution that ensures the optimal performance and security of your applications. With Shape.host, you can scale your infrastructure effortlessly and focus on what matters most: your business’s success.