Skip to content

Deploying Netdata Agent on AlmaLinux 9 (production-ready)

Stand up Netdata Agent on AlmaLinux 9 — parent/child streaming topology, localhost-bound child agents, Netdata Cloud claim, custom alarms, sized retention.

You ran the Netdata one-liner on every host, the dashboards came up per-node, you bookmarked a few, you moved on. Six months later port 19999 is open to the public on three of your edge VMs because nobody locked it down, each agent stores its own metrics with no central retention, the alarm thresholds are still the default and either too noisy or too quiet, and when an engineer asks “did CPU spike at 02:00 last Tuesday?” the answer depends on whether that node was rebooted since.

What’s happening

A single Netdata agent per host is excellent for live troubleshooting and terrible as a long-term metrics store. To make it production-ready, the fleet runs in a parent/child topology: each child has a short local retention and streams everything to a central parent, which keeps tiered retention (recent at high resolution, older downsampled) and is the only agent that talks to operators. Each child’s web listener belongs on 127.0.0.1 — there is no reason for it to be on the public NAT, ever. Claiming to Netdata Cloud is opt-in but useful: it gives operators a single pane and the on-call rotation a place to route alarms without standing up a separate Grafana. Alarm tuning is part of the install, not a later todo — leaving the defaults is the loudest part of a Netdata graveyard.

How to verify

On a child, the agent should bind to localhost only:

ss -lntp | grep ':19999'
# 127.0.0.1:19999  netdata

On the parent, the same listener is fine on 0.0.0.0 because nginx fronts it with TLS. Streaming health from the child:

curl -s http://127.0.0.1:19999/api/v1/info | python3 -c \
  'import json,sys; d=json.load(sys.stdin); print("stream:", d.get("stream_enabled"), "destination:", d.get("stream_destinations"))'

On the parent, confirm the children are connected:

curl -s http://127.0.0.1:19999/api/v1/info | python3 -c \
  'import json,sys; d=json.load(sys.stdin); print("hosts:", d.get("hosts_available"))'

If a child shows stream_enabled: False, the topology is just N independent agents — fix it before relying on the dashboards.

The fix

Save the script below as /root/setup-netdata-almalinux9.sh, then run it. It performs the full installer flow on a fresh AlmaLinux 9.x VM in one of two roles, set via env: base update + EPEL, SELinux enforcing, fail2ban, automatic security updates, the official Netdata installer (kickstart) which pulls the current stable, a parent/child config that wires streaming with a shared API key, localhost-only listener on children, dbengine retention sized at parent for the fleet, a starter alarm template (CPU + disk + memory) that overrides the noisier defaults, optional NETDATA_CLAIM_TOKEN for Netdata Cloud opt-in, nginx + certbot only on the parent. The script waits for the listener before continuing.

#!/usr/bin/env bash
set -euo pipefail

### AlmaLinux 9.x Netdata Agent clean VM installer
### NETDATA_ROLE=parent  -> central, retention-heavy, optionally public via nginx
### NETDATA_ROLE=child   -> localhost-bound, streams to parent
### Set NETDATA_CLAIM_TOKEN to opt into Netdata Cloud (parent only)
### Keeps root SSH key login; disables password auth
### No local backups; assumes VM-level backup

if [[ "$(id -u)" -ne 0 ]]; then
  echo "Run as root."
  exit 1
fi

: "${NETDATA_ROLE:?Set NETDATA_ROLE to 'parent' or 'child'}"
: "${NETDATA_STREAM_API_KEY:?Set NETDATA_STREAM_API_KEY (uuidgen) — same on parent + all children}"

if [[ "$NETDATA_ROLE" == "parent" ]]; then
  : "${ND_DOMAIN:?Set ND_DOMAIN for parent, e.g. metrics.example.com}"
  : "${ND_EMAIL:?Set ND_EMAIL for Let's Encrypt}"
fi
if [[ "$NETDATA_ROLE" == "child" ]]; then
  : "${NETDATA_PARENT_HOST:?Set NETDATA_PARENT_HOST (parent FQDN or IP)}"
fi

NETDATA_CLAIM_TOKEN="${NETDATA_CLAIM_TOKEN:-}"
NETDATA_CLAIM_ROOMS="${NETDATA_CLAIM_ROOMS:-}"

echo
echo "========================================"
echo "Netdata AlmaLinux 9 Setup"
echo "Role: $NETDATA_ROLE"
echo "========================================"
echo

echo "==> Updating base OS"
dnf -y update
dnf -y install epel-release
dnf -y update

echo "==> Installing base packages"
dnf -y install \
  curl wget vim ca-certificates gnupg2 \
  chrony fail2ban dnf-automatic \
  policycoreutils-python-utils \
  lsof tcpdump bind-utils iproute net-tools jq

systemctl enable --now chronyd
timedatectl set-ntp true

echo "==> SELinux enforcing on next boot"
sed -i 's/^SELINUX=.*/SELINUX=enforcing/' /etc/selinux/config || true
setenforce 1 2>/dev/null || true

echo "==> sysctl + file limits"
cat > /etc/sysctl.d/99-netdata.conf <<'SYSCTL'
net.core.somaxconn = 4096
net.ipv4.tcp_syncookies = 1
fs.file-max = 2097152
kernel.dmesg_restrict = 1
SYSCTL
sysctl --system

cat > /etc/security/limits.d/99-netdata.conf <<'LIMITS'
* soft nofile 64000
* hard nofile 64000
netdata soft nofile 64000
netdata hard nofile 64000
LIMITS

echo "==> Hardening SSH (keep root key)"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.$(date +%F-%H%M%S)
set_sshd() {
  local k="$1" v="$2"
  if grep -qE "^[#[:space:]]*${k}[[:space:]]+" /etc/ssh/sshd_config; then
    sed -i "s|^[#[:space:]]*${k}[[:space:]].*|${k} ${v}|" /etc/ssh/sshd_config
  else
    echo "${k} ${v}" >> /etc/ssh/sshd_config
  fi
}
set_sshd PermitRootLogin prohibit-password
set_sshd PasswordAuthentication no
set_sshd PubkeyAuthentication yes
set_sshd KbdInteractiveAuthentication no
set_sshd X11Forwarding no
set_sshd ClientAliveInterval 300
set_sshd MaxAuthTries 4
sshd -t
systemctl restart sshd

echo "==> fail2ban + dnf-automatic"
cat > /etc/fail2ban/jail.d/sshd.local <<'F2B'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
F2B
systemctl enable --now fail2ban

cat > /etc/dnf/automatic.conf <<'DNFA'
[commands]
upgrade_type = security
random_sleep = 900
download_updates = yes
apply_updates = yes
[emitters]
emit_via = stdio
[base]
debuglevel = 1
DNFA
systemctl enable --now dnf-automatic.timer

echo "==> Installing Netdata Agent (stable channel)"
KICKSTART_ARGS="--stable-channel --disable-telemetry --dont-wait --non-interactive"
if [[ -n "$NETDATA_CLAIM_TOKEN" && "$NETDATA_ROLE" == "parent" ]]; then
  KICKSTART_ARGS="$KICKSTART_ARGS --claim-token ${NETDATA_CLAIM_TOKEN} --claim-rooms ${NETDATA_CLAIM_ROOMS:-} --claim-url https://app.netdata.cloud"
fi
# shellcheck disable=SC2086
bash <(curl -fsSL https://get.netdata.cloud/kickstart.sh) ${KICKSTART_ARGS}

echo "==> Writing role-specific configuration"
NETDATA_CONF_DIR="/etc/netdata"
mkdir -p "$NETDATA_CONF_DIR/stream.d" "$NETDATA_CONF_DIR/health.d"

if [[ "$NETDATA_ROLE" == "parent" ]]; then
  cat > "$NETDATA_CONF_DIR/netdata.conf" <<'PARENTCONF'
[global]
    hostname = netdata-parent
    memory mode = dbengine
    page cache size = 64
    dbengine multihost disk space = 4096

[web]
    bind to = 0.0.0.0:19999
    allow connections from = localhost 127.0.0.1
    allow dashboard from = localhost 127.0.0.1
    allow streaming from = *
    allow management from = localhost 127.0.0.1

[ml]
    enabled = yes

[health]
    enabled = yes
PARENTCONF

  cat > "$NETDATA_CONF_DIR/stream.conf" <<STREAMP
# Parent: accept streams using this API key
[${NETDATA_STREAM_API_KEY}]
    enabled = yes
    default history = 3600
    default memory mode = dbengine
    health enabled by default = auto
    allow from = *
STREAMP

else
  cat > "$NETDATA_CONF_DIR/netdata.conf" <<CHILDCONF
[global]
    hostname = $(hostname)
    memory mode = ram
    history = 600

[web]
    bind to = 127.0.0.1:19999
    allow connections from = localhost 127.0.0.1
    allow dashboard from = localhost 127.0.0.1
    allow management from = localhost 127.0.0.1

[ml]
    enabled = no

[health]
    enabled = no
CHILDCONF

  cat > "$NETDATA_CONF_DIR/stream.conf" <<STREAMC
# Child: stream to parent
[stream]
    enabled = yes
    destination = ${NETDATA_PARENT_HOST}:19999
    api key = ${NETDATA_STREAM_API_KEY}
    timeout seconds = 60
    default port = 19999
    send charts matching = *
    buffer size bytes = 10485760
    reconnect delay seconds = 5
    initial clock resync iterations = 60
STREAMC
fi

echo "==> Writing starter alarm overrides (override the noisier defaults)"
cat > "$NETDATA_CONF_DIR/health.d/cpu.conf" <<'HCPU'
template: 10min_cpu_usage
      on: system.cpu
   class: Utilization
    type: System
component: CPU
   hosts: *
    calc: 100 - $idle
   units: %
   every: 1m
    warn: $this > 85
    crit: $this > 95
   delay: down 15m multiplier 1.5 max 1h
    info: 10 minute average CPU utilization
HCPU

cat > "$NETDATA_CONF_DIR/health.d/disk.conf" <<'HDISK'
template: disk_space_usage
      on: disk.space
   class: Utilization
    type: System
component: Disk
   hosts: *
   units: %
   every: 1m
    calc: $used * 100 / ($avail + $used)
    warn: $this > 85
    crit: $this > 95
   delay: down 15m multiplier 1.5 max 1h
    info: disk space utilization
HDISK

cat > "$NETDATA_CONF_DIR/health.d/ram.conf" <<'HRAM'
template: ram_in_use
      on: system.ram
   class: Utilization
    type: System
component: Memory
   hosts: *
    calc: ($used + $buffers + $active) * 100 / ($used + $buffers + $active + $cached + $free)
   units: %
   every: 1m
    warn: $this > 85
    crit: $this > 95
   delay: down 15m multiplier 1.5 max 1h
    info: RAM in use
HRAM

chown -R netdata:netdata /etc/netdata
mkdir -p /etc/systemd/system/netdata.service.d
cat > /etc/systemd/system/netdata.service.d/limits.conf <<'NDLIM'
[Service]
LimitNOFILE=64000
NDLIM
systemctl daemon-reload
systemctl restart netdata

echo "==> Waiting for Netdata listener"
if [[ "$NETDATA_ROLE" == "parent" ]]; then
  EXPECTED="0.0.0.0:19999"
else
  EXPECTED="127.0.0.1:19999"
fi

for i in {1..30}; do
  if ss -lntp | grep -q "$EXPECTED"; then
    echo "  netdata bound on $EXPECTED"
    break
  fi
  sleep 1
done

if [[ "$NETDATA_ROLE" == "parent" ]]; then
  echo "==> Installing nginx + Let's Encrypt for parent UI"
  dnf -y install nginx certbot python3-certbot-nginx

  cat > /etc/nginx/conf.d/netdata.conf <<NGINX_BOOT
server {
    listen 80;
    server_name ${ND_DOMAIN};
    location /.well-known/acme-challenge/ { root /var/lib/letsencrypt; }
    location / { return 200 'bootstrap'; }
}
NGINX_BOOT
  mkdir -p /var/lib/letsencrypt
  systemctl enable --now nginx
  nginx -t && systemctl reload nginx

  if [[ ! -d /etc/letsencrypt/live/${ND_DOMAIN} ]]; then
    certbot certonly --webroot -w /var/lib/letsencrypt \
      -d "${ND_DOMAIN}" -m "${ND_EMAIL}" --agree-tos --non-interactive
  fi

  cat > /etc/nginx/conf.d/netdata.conf <<NGINX
server {
    listen 80;
    server_name ${ND_DOMAIN};
    location /.well-known/acme-challenge/ { root /var/lib/letsencrypt; }
    location / { return 301 https://\$host\$request_uri; }
}

server {
    listen 443 ssl http2;
    server_name ${ND_DOMAIN};

    ssl_certificate /etc/letsencrypt/live/${ND_DOMAIN}/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/${ND_DOMAIN}/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;
    add_header Strict-Transport-Security "max-age=31536000" always;

    location / {
        proxy_pass http://127.0.0.1:19999/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade \$http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host \$host;
        proxy_set_header X-Real-IP \$remote_addr;
        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_read_timeout 300s;
    }
}
NGINX

  nginx -t && systemctl reload nginx
  systemctl enable --now certbot-renew.timer 2>/dev/null || true
fi

echo "==> Final package update"
dnf -y update

echo
echo "========================================"
echo "DONE"
echo "========================================"
echo
echo "Role: $NETDATA_ROLE"
echo "Listeners:"
ss -lntp | grep -E ':(19999|443|80)\b' || true
echo
echo "Service:"
systemctl is-active netdata fail2ban chronyd || true
echo
echo "Netdata info:"
curl -s http://127.0.0.1:19999/api/v1/info | head -c 600 || true
echo

if [[ "$NETDATA_ROLE" == "parent" ]]; then
  echo "Public URL: https://${ND_DOMAIN}/"
  if [[ -n "$NETDATA_CLAIM_TOKEN" ]]; then
    echo "Netdata Cloud claim attempted with token (check app.netdata.cloud)"
  else
    echo "Netdata Cloud: not claimed. To claim later:"
    echo "  netdata-claim.sh -token=<token> -rooms=<room> -url=https://app.netdata.cloud"
  fi
else
  echo "Streaming to: ${NETDATA_PARENT_HOST}:19999"
  echo "Confirm on parent that hosts_available > 1"
fi
echo
echo "Retention sizing (parent):"
echo "  dbengine multihost disk space = 4096 MB"
echo "  ~ keeps about 30-90 days of per-second metrics for a 10-host fleet."
echo "  For larger fleets, bump this AND mount /var/cache/netdata on its own volume."

Make it executable and run it. On the parent first:

chmod 700 /root/setup-netdata-almalinux9.sh
NETDATA_ROLE=parent ND_DOMAIN=metrics.example.com ND_EMAIL=ops@example.com \
  NETDATA_STREAM_API_KEY=$(uuidgen) \
  NETDATA_CLAIM_TOKEN=<optional-cloud-token> \
  NETDATA_CLAIM_ROOMS=<optional-room-id> \
  /root/setup-netdata-almalinux9.sh

Then on each child VM, using the same API key:

NETDATA_ROLE=child NETDATA_PARENT_HOST=metrics.example.com \
  NETDATA_STREAM_API_KEY=<same-as-parent> \
  /root/setup-netdata-almalinux9.sh

The script prints the listener state, the service status, and the API info JSON. The dbengine on the parent is sized at 4 GB by default — roughly 30 to 90 days for a small fleet depending on chart density; raise it deliberately and put /var/cache/netdata on a separate volume before you do, because growth is non-trivial to roll back. The CPU/disk/memory alarm overrides bring the noisy defaults down to 85/95 % thresholds with a 15-minute hold-off, which is usually the right starting point — tune from there based on what actually pages.

Stack Harbor operates Netdata in parent/child topology as part of environment management — alarms tuned, retention sized, and the Cloud claim landing in the on-call rotation our Monitoring & Support practice runs. Book a topology review.