Key points
- A Bash script that installs Netdata with the official kickstart installer and serves it through Apache behind a password.
- Set
NETDATA_USER,NETDATA_PASSWORDandNETDATA_PATHat the top first; it replaces Apache’s default site. - The login travels over plain HTTP until you add HTTPS, for example with Let’s Encrypt.
Streamline Netdata Installation with This Powerful Bash Script
Updated October 2026: The official installer that this Netdata setup script calls (get.netdata.cloud/kickstart.sh) still works, but check these points before you run it:
- It asks nothing: set
NETDATA_USER,NETDATA_PASSWORDandNETDATA_PATHat the top of the script first. - It replaces
/etc/apache2/sites-available/000-default.confwith its own virtual host. On a server that already serves a site on port 80, copy the Netdata lines into your own site configuration instead. - The password protection runs over plain HTTP, so the login travels unencrypted. Add HTTPS with Let’s Encrypt (
sudo apt install python3-certbot-apache, thensudo certbot --apache, or my Let’s Encrypt script) before you use it over the internet. - Some closing messages are wrong: Netdata is reached at
http://your-server/NETDATA_PATH(port 4430 is never configured), no/etc/netdata/netdata.htpasswdis created, andnetdata_random_session_idis not a Netdata Cloud key. To connect the node to Netdata Cloud, use the command Netdata Cloud gives you when you add a node.
Monitoring server performance is essential for maintaining smooth operations and addressing issues proactively. This Bash script automates the installation and configuration of Netdata, a real-time system monitoring tool, on Debian-based systems. Effortlessly set up Netdata with added features like Apache proxying and HTTP password authentication.
What Is Netdata?
Netdata is an open-source monitoring tool that provides real-time insights into system performance. It tracks metrics such as CPU usage, memory consumption, disk activity, and network traffic, helping administrators quickly identify potential issues.
Key Features of the Script
- Automated Netdata Installation: Ensures seamless setup using the official Netdata installer or package manager fallback.
- Apache Integration: Configures Apache to serve Netdata through a reverse proxy (add HTTPS for real security; see the note at the top).
- Basic HTTP Authentication: Protects Netdata access with username and password.
- Customizable Proxy Path: Allows serving Netdata under a specific URL path.
- Automatic Service Configuration: Enables Netdata to start on boot and restarts it after configuration.
How It Works
- Prepares the System: Updates package lists and installs required dependencies like
curlandapache2-utils. - Installs Netdata:
- Uses the official Netdata installer or a package manager fallback if needed.
- Dumps the default configuration for customization.
- Sets Up Apache:
- Enables required modules (
proxy,proxy_http,auth_basic). - Configures a virtual host to serve Netdata on a user-defined path with HTTP authentication.
- Enables required modules (
- Configures Netdata:
- Limits Netdata to local binding for security.
- Restarts the service and enables it at boot.
- Secures Access:
- Creates an
.htpasswdfile for password protection. - Prints the address of Netdata behind Apache (direct access on port 19999 is closed, because Netdata listens only on localhost).
- Creates an
Quick Start with the Netdata Setup Script
- Save and Make Executable: copy the full script at the end of this post into a file named
netdata-setup.sh, setNETDATA_USER,NETDATA_PASSWORDandNETDATA_PATHat its top, then run:
chmod +x netdata-setup.sh
- Run the Script:
sudo ./netdata-setup.sh
- Let It Run:
- It uses the username and password you set in the script for HTTP authentication.
- Let the script handle the installation and configuration automatically.
- Access Netdata: Open your browser and navigate to:
http://<your-server-ip>/<custom-path>.
Benefits
- Time-Saving: Automates a complex multi-step installation process.
- Enhanced Security: Protects Netdata access with password authentication.
- Customizable: Offers flexibility in configuring the proxy path and service behavior.
- Reliable: Falls back to the distribution package if the official installer fails.
Conclusion
This Bash script simplifies the process of setting up Netdata on your server, providing password-protected access and seamless Apache integration. Monitor your system’s performance with confidence and address issues proactively. Start optimizing your server management today with this powerful tool!
#!/bin/bash
# =========================================
# Netdata Setup Script
# =========================================
#
# Version: 1.0.0
# Script written by Warith AL Maawali
#
# Discord channel: https://discord.gg/KEFErEx
# Twitter: https://x.com/warith2020
# Linkedin: https://www.linkedin.com/in/warith1977
# Website: https://www.digi77.com
# (c) 2024
#
# Description:
# This script sets up Netdata on a Debian-based system.
# It ensures root privileges, updates system packages, installs Netdata,
# configures Apache for proxying, and sets up basic HTTP authentication.
#
# For more information, visit: https://learn.netdata.cloud/docs/netdata-agent/installation/linux/
#
# This software is dual-licensed:
#
# Personal, non-commercial use: Apache License 2.0
# Commercial, corporate, or organizational use: Separate commercial license required.
# Contact me for licensing inquiries.
#
# Usage: ./netdata-setup.sh
#
# Usage Examples:
# Run this script as root to set up Netdata:
# ./netdata-setup.sh
# =========================================
# Global Variables
NETDATA_USER="xxx_your_username_xxx"
NETDATA_PASSWORD="xxx_your_password_xxx"
PORT="4430"
SERVER_IP=$(curl -s ifconfig.me || curl -s icanhazip.com || curl -s ipecho.net/plain || hostname -I | awk '{print $1}')
NETDATA_PATH="/DYP1BYuftXbk0vgXErux" # User-defined variable for Netdata path
VHOST_CONF="/etc/apache2/sites-available/000-default.conf"
# Function to set up Netdata
function setup_netdata() {
# Update package lists
echo "===================="
echo "Updating package lists..."
echo "===================="
sudo apt update -y
# Install dependencies
echo "===================="
echo "Installing dependencies..."
echo "===================="
sudo apt install -y curl apache2-utils
# Install Netdata using the official installer
echo "===================="
echo "Installing Netdata..."
echo "===================="
wget -O /tmp/netdata-kickstart.sh https://get.netdata.cloud/kickstart.sh && sh /tmp/netdata-kickstart.sh --disable-telemetry || {
echo "===================="
echo "Official installer failed, trying package manager..."
echo "===================="
sudo apt-get install netdata -y
}
# Dump Netdata configuration
netdatacli dumpconfig >/etc/netdata/netdata.conf
# Update package list and install Apache utilities if not installed
echo "===================="
echo "Updating package list and installing Apache utilities..."
echo "===================="
sudo apt update -y
sudo apt install -y apache2 apache2-utils
# Enable necessary Apache modules
echo "===================="
echo "Enabling necessary Apache modules for proxying..."
echo "===================="
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod auth_basic
# Set up basic HTTP authentication
echo "===================="
echo "Setting up basic HTTP authentication for Netdata..."
echo "===================="
sudo htpasswd -bc /etc/apache2/.htpasswd "$NETDATA_USER" "$NETDATA_PASSWORD"
# Create or edit the Apache virtual host configuration for Netdata
echo "===================="
echo "Configuring Apache to serve Netdata at $NETDATA_PATH on $SERVER_IP..."
echo "===================="
# Create temporary file with configuration
TEMP_CONF=$(mktemp)
cat >"$TEMP_CONF" <<EOL
<VirtualHost *:80>
ServerName $SERVER_IP
# Proxy configuration to serve Netdata at $NETDATA_PATH
ProxyPreserveHost On
ProxyRequests Off
ProxyPass $NETDATA_PATH/ http://127.0.0.1:19999/
ProxyPassReverse $NETDATA_PATH/ http://127.0.0.1:19999/
# Basic authentication for Netdata
<Location $NETDATA_PATH>
AuthType Basic
AuthName "Restricted Access"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Location>
# Other existing configuration settings for your website
DocumentRoot /var/www/html
</VirtualHost>
EOL
# Copy temp file to actual location with sudo
sudo cp "$TEMP_CONF" "$VHOST_CONF"
# Clean up temp file
rm "$TEMP_CONF"
# Restart Apache to apply changes
echo "===================="
echo "Restarting Apache to apply the new configuration..."
echo "===================="
sudo systemctl restart apache2
# Configure Netdata to require HTTP authentication
sudo tee -a /etc/netdata/netdata.conf >/dev/null <<EOF
[web]
bind to = localhost:19999
EOF
# Restart Netdata service to apply the changes
echo "===================="
echo "Restarting Netdata service to apply changes..."
echo "===================="
timeout 2 sudo systemctl restart netdata
# Enable Netdata to start on boot
echo "===================="
echo "Enabling Netdata to start on boot..."
echo "===================="
timeout 2 sudo systemctl enable netdata
# Check Netdata service status
echo "===================="
echo "Checking Netdata service status..."
echo "===================="
timeout 2 sudo systemctl status netdata
# Display access information
IP_ADDRESS=$(hostname -I | awk '{print $1}')
echo "===================="
echo "Installation complete. Access Netdata at: http://$IP_ADDRESS:$PORT with username: $NETDATA_USER"
echo "===================="
# Display access URLs for reference
echo "===================="
echo "You can access Netdata through Apache at: http://$IP_ADDRESS$NETDATA_PATH/"
echo "===================="
echo "Direct Netdata access (if configured) at: http://$IP_ADDRESS:19999"
echo "===================="
echo "Your Apache htpasswd file is located at: /etc/apache2/.htpasswd"
echo "===================="
echo "Your Netdata htpasswd file is located at: /etc/netdata/netdata.htpasswd"
echo "===================="
# Display the private key needed for Netdata Cloud connection
echo "===================="
echo "Your Netdata Cloud private key is:"
sudo cat /var/lib/netdata/netdata_random_session_id
echo "===================="
echo "You'll need this key to connect your node to Netdata Cloud"
echo "===================="
}
# Execute the setup function
setup_netdata
ShellScript