From 3704c74f83a120ea83281adf3be96fcd85f61a64 Mon Sep 17 00:00:00 2001 From: p2913020 Date: Mon, 29 Jun 2026 12:45:14 -0400 Subject: [PATCH 1/5] updated --- .../deploy_zabbix_agent_linux_arm.sh | 65 +++++++++++++++++-- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/zabbix-autoregister/deploy_zabbix_agent_linux_arm.sh b/zabbix-autoregister/deploy_zabbix_agent_linux_arm.sh index af4144c..5b97e7c 100644 --- a/zabbix-autoregister/deploy_zabbix_agent_linux_arm.sh +++ b/zabbix-autoregister/deploy_zabbix_agent_linux_arm.sh @@ -10,7 +10,7 @@ set -euo pipefail ZABBIX_SERVER="zabbix.snarfnet.net" -ZABBIX_VERSION="7.0.0" +ZABBIX_VERSION="7.0.27" PSK_IDENTITY="PSK_autoregister" PSK_FILE="/etc/zabbix/zabbix_agent2.psk" AGENT_CONF="/etc/zabbix/zabbix_agent2.conf" @@ -61,17 +61,68 @@ install_agent_package_manager() { case "${OS_ID}" in debian|ubuntu|raspbian) log "Installing via apt (Debian/Ubuntu/Raspbian)..." - # Determine arch string for the repo local dpkg_arch dpkg_arch=$(dpkg --print-architecture) - wget -q "https://repo.zabbix.com/zabbix/7.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_latest+ubuntu_all.deb" -O /tmp/zabbix-release.deb 2>/dev/null || \ - wget -q "https://repo.zabbix.com/zabbix/7.0/debian/pool/main/z/zabbix-release/zabbix-release_latest+debian${OS_VERSION}_all.deb" -O /tmp/zabbix-release.deb 2>/dev/null || true + # Zabbix provides separate repos for ARM architectures: + # - debian-arm64 / ubuntu-arm64 for aarch64 + # - raspbian for armhf (Raspberry Pi OS) + # The standard debian/ubuntu repos only carry amd64. + local repo_distro="" + case "${dpkg_arch}" in + arm64) + if [ "${OS_ID}" = "ubuntu" ]; then + repo_distro="ubuntu-arm64" + else + repo_distro="debian-arm64" + fi + ;; + armhf) + repo_distro="raspbian" + ;; + *) + log "Unexpected dpkg arch '${dpkg_arch}' on ARM script. Falling back to binary..." + install_agent_binary + return 0 + ;; + esac + + # Determine release codename (e.g. bullseye, bookworm, jammy) + local codename="" + if [ -f /etc/os-release ]; then + codename=$(. /etc/os-release && echo "${VERSION_CODENAME:-}") + fi + if [ -z "${codename}" ]; then + log "Could not determine release codename. Falling back to binary..." + install_agent_binary + return 0 + fi + + # Disable defunct backports repos to prevent apt-get update 404 errors (Debian EOL releases) + local backports_list + backports_list=$(grep -rl 'backports' /etc/apt/sources.list /etc/apt/sources.list.d/ 2>/dev/null || true) + if [ -n "${backports_list}" ]; then + log "Disabling defunct backports repositories to avoid 404 errors..." + for f in ${backports_list}; do + sed -i '/backports/s/^[^#]/#&/' "${f}" + done + fi + + # Download and install the Zabbix release package for the ARM-specific repo + local release_url="https://repo.zabbix.com/zabbix/7.0/${repo_distro}/pool/main/z/zabbix-release/zabbix-release_latest+${OS_ID}${OS_VERSION}_all.deb" + log "Adding Zabbix repository: ${repo_distro} (${codename})" + log "Release package URL: ${release_url}" + + if wget -q "${release_url}" -O /tmp/zabbix-release.deb 2>/dev/null || \ + curl -sL "${release_url}" -o /tmp/zabbix-release.deb 2>/dev/null; then - if [ -f /tmp/zabbix-release.deb ]; then dpkg -i /tmp/zabbix-release.deb - apt-get update - apt-get install -y zabbix-agent2 && { rm -f /tmp/zabbix-release.deb; return 0; } + apt-get update -o Acquire::AllowInsecureRepositories=false 2>&1 | grep -v "^W:" || true + if apt-get install -y zabbix-agent2; then + rm -f /tmp/zabbix-release.deb + log "Package installation successful." + return 0 + fi fi log "Package manager install failed, falling back to binary tarball..." From 81279ec63c4186aef49927087b3c34c37cc8b565 Mon Sep 17 00:00:00 2001 From: p2913020 Date: Mon, 29 Jun 2026 12:50:39 -0400 Subject: [PATCH 2/5] Updated again, OS is EOL --- .../deploy_zabbix_agent_linux_arm.sh | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/zabbix-autoregister/deploy_zabbix_agent_linux_arm.sh b/zabbix-autoregister/deploy_zabbix_agent_linux_arm.sh index 5b97e7c..46aafeb 100644 --- a/zabbix-autoregister/deploy_zabbix_agent_linux_arm.sh +++ b/zabbix-autoregister/deploy_zabbix_agent_linux_arm.sh @@ -65,7 +65,7 @@ install_agent_package_manager() { dpkg_arch=$(dpkg --print-architecture) # Zabbix provides separate repos for ARM architectures: - # - debian-arm64 / ubuntu-arm64 for aarch64 + # - debian-arm64 / ubuntu-arm64 for aarch64 (Bookworm/Trixie+ only) # - raspbian for armhf (Raspberry Pi OS) # The standard debian/ubuntu repos only carry amd64. local repo_distro="" @@ -98,6 +98,17 @@ install_agent_package_manager() { return 0 fi + # The arm64 Zabbix repos only support Debian 12+ (bookworm, trixie). + # For older/EOL releases like bullseye, skip directly to binary install. + case "${codename}" in + buster|bullseye|stretch|jessie) + log "Zabbix arm64 apt repo not available for EOL release '${codename}'." + log "Falling back to binary tarball..." + install_agent_binary + return 0 + ;; + esac + # Disable defunct backports repos to prevent apt-get update 404 errors (Debian EOL releases) local backports_list backports_list=$(grep -rl 'backports' /etc/apt/sources.list /etc/apt/sources.list.d/ 2>/dev/null || true) @@ -109,15 +120,23 @@ install_agent_package_manager() { fi # Download and install the Zabbix release package for the ARM-specific repo - local release_url="https://repo.zabbix.com/zabbix/7.0/${repo_distro}/pool/main/z/zabbix-release/zabbix-release_latest+${OS_ID}${OS_VERSION}_all.deb" + local release_url="https://repo.zabbix.com/zabbix/7.0/${repo_distro}/pool/main/z/zabbix-release/zabbix-release_latest_7.0+${OS_ID}${OS_VERSION}_all.deb" log "Adding Zabbix repository: ${repo_distro} (${codename})" log "Release package URL: ${release_url}" if wget -q "${release_url}" -O /tmp/zabbix-release.deb 2>/dev/null || \ - curl -sL "${release_url}" -o /tmp/zabbix-release.deb 2>/dev/null; then + curl -sfL "${release_url}" -o /tmp/zabbix-release.deb 2>/dev/null; then + + # Verify we actually got a .deb and not an error page + if ! dpkg-deb --info /tmp/zabbix-release.deb >/dev/null 2>&1; then + log "Downloaded file is not a valid .deb package. Falling back to binary..." + rm -f /tmp/zabbix-release.deb + install_agent_binary + return 0 + fi dpkg -i /tmp/zabbix-release.deb - apt-get update -o Acquire::AllowInsecureRepositories=false 2>&1 | grep -v "^W:" || true + apt-get update if apt-get install -y zabbix-agent2; then rm -f /tmp/zabbix-release.deb log "Package installation successful." From e10c291958903719f2aaa333b1d2d3f1839b4790 Mon Sep 17 00:00:00 2001 From: p2913020 Date: Mon, 29 Jun 2026 13:00:24 -0400 Subject: [PATCH 3/5] Big update --- .../deploy_zabbix_agent_linux_arm.sh | 102 +++++++++++++++--- 1 file changed, 89 insertions(+), 13 deletions(-) diff --git a/zabbix-autoregister/deploy_zabbix_agent_linux_arm.sh b/zabbix-autoregister/deploy_zabbix_agent_linux_arm.sh index 46aafeb..79c86c8 100644 --- a/zabbix-autoregister/deploy_zabbix_agent_linux_arm.sh +++ b/zabbix-autoregister/deploy_zabbix_agent_linux_arm.sh @@ -156,20 +156,99 @@ install_agent_package_manager() { } install_agent_binary() { - log "Installing Zabbix Agent 2 from pre-compiled binary..." + log "Installing Zabbix Agent 2 from direct .deb package (bookworm arm64)..." - local tarball_url="https://cdn.zabbix.com/zabbix/binaries/stable/7.0/${ZABBIX_VERSION}/zabbix_agent2-${ZABBIX_VERSION}-${TARBALL_ARCH}-static.tar.gz" - local tarball_path="/tmp/zabbix_agent2.tar.gz" + # Zabbix does not publish static binary tarballs for ARM architectures. + # Instead, we fetch the .deb package directly from the debian-arm64 bookworm pool. + # Agent 2 is a Go binary with minimal libc dependencies, so installing a bookworm + # .deb on bullseye works reliably. - log "Downloading from: ${tarball_url}" - if ! wget -q "${tarball_url}" -O "${tarball_path}" 2>/dev/null && \ - ! curl -sL "${tarball_url}" -o "${tarball_path}" 2>/dev/null; then - log "ERROR: Failed to download Zabbix Agent 2 binary." - log " URL: ${tarball_url}" - log " You may need to check https://www.zabbix.com/download for the correct ARM binary." + local deb_path="/tmp/zabbix_agent2.deb" + local pool_base="https://repo.zabbix.com/zabbix/7.0/debian-arm64/pool/main/z/zabbix" + + # Try multiple URL patterns for the .deb package + local deb_urls=( + "${pool_base}/zabbix-agent2_${ZABBIX_VERSION}-1+debian12_arm64.deb" + "${pool_base}/zabbix-agent2_${ZABBIX_VERSION}-1%2Bdebian12_arm64.deb" + ) + + local downloaded=false + for url in "${deb_urls[@]}"; do + log "Trying: ${url}" + if wget -q "${url}" -O "${deb_path}" 2>/dev/null; then + if dpkg-deb --info "${deb_path}" >/dev/null 2>&1; then + downloaded=true + break + fi + fi + if curl -sfL "${url}" -o "${deb_path}" 2>/dev/null; then + if dpkg-deb --info "${deb_path}" >/dev/null 2>&1; then + downloaded=true + break + fi + fi + rm -f "${deb_path}" + done + + # Fallback: try the CDN static tarball path (may work for some versions) + if [ "${downloaded}" = false ]; then + local tarball_url="https://cdn.zabbix.com/zabbix/binaries/stable/7.0/${ZABBIX_VERSION}/zabbix_agent2-${ZABBIX_VERSION}-${TARBALL_ARCH}-static.tar.gz" + local tarball_path="/tmp/zabbix_agent2.tar.gz" + + log "Trying CDN tarball: ${tarball_url}" + if wget -q "${tarball_url}" -O "${tarball_path}" 2>/dev/null || \ + curl -sfL "${tarball_url}" -o "${tarball_path}" 2>/dev/null; then + # Verify it's actually a gzip file + if file "${tarball_path}" 2>/dev/null | grep -q gzip; then + install_from_tarball "${tarball_path}" + return 0 + fi + fi + rm -f "${tarball_path}" + + log "ERROR: Failed to download Zabbix Agent 2 for ${ARCH_LABEL}." + log " No static binary or .deb package found." + log " Options:" + log " 1. Upgrade to Debian 12 (Bookworm) and re-run this script" + log " 2. Manually download from https://www.zabbix.com/download" + log " 3. Install from Debian's own repos: apt install zabbix-agent2" exit 1 fi + # Install the .deb package + log "Installing .deb package..." + mkdir -p /etc/zabbix + mkdir -p /var/log/zabbix + mkdir -p /var/run/zabbix + + # Create zabbix user if it doesn't exist + if ! id -u zabbix &>/dev/null; then + useradd -r -s /sbin/nologin -d /var/lib/zabbix -M zabbix + fi + + # Install with --force-depends to handle minor dependency version mismatches + # between bookworm and bullseye + if ! dpkg -i --force-depends "${deb_path}" 2>&1; then + log "dpkg install had issues, attempting to fix dependencies..." + apt-get install -f -y 2>/dev/null || true + fi + + rm -f "${deb_path}" + + # Verify the binary is in place + if command -v zabbix_agent2 >/dev/null 2>&1 || [ -f /usr/sbin/zabbix_agent2 ]; then + log "Package installation complete." + chown -R zabbix:zabbix /var/log/zabbix /var/run/zabbix 2>/dev/null || true + else + log "ERROR: zabbix_agent2 binary not found after package install." + exit 1 + fi +} + +install_from_tarball() { + local tarball_path="$1" + log "Extracting tarball..." + # Create directories mkdir -p "${INSTALL_DIR}/bin" mkdir -p /etc/zabbix @@ -182,7 +261,7 @@ install_agent_binary() { # Find the binary local agent_bin - agent_bin=$(find "${INSTALL_DIR}" -name "zabbix_agent2" -type f | head -1) + agent_bin=$(find "${INSTALL_DIR}" -name "zabbix_agent2" -type f 2>/dev/null | head -1) if [ -z "${agent_bin}" ]; then log "ERROR: Could not find zabbix_agent2 binary in extracted archive." exit 1 @@ -200,9 +279,6 @@ install_agent_binary() { chown -R zabbix:zabbix /var/log/zabbix /var/run/zabbix - # Set config path for binary installs - AGENT_CONF="/etc/zabbix/zabbix_agent2.conf" - # Create systemd service create_systemd_service From 37d8f2c5b7386a12793df0f8bc74426d13331f2d Mon Sep 17 00:00:00 2001 From: p2913020 Date: Mon, 29 Jun 2026 13:06:18 -0400 Subject: [PATCH 4/5] last update --- .../deploy_zabbix_agent_linux_arm.sh | 131 ++++++++++++++---- 1 file changed, 103 insertions(+), 28 deletions(-) diff --git a/zabbix-autoregister/deploy_zabbix_agent_linux_arm.sh b/zabbix-autoregister/deploy_zabbix_agent_linux_arm.sh index 79c86c8..0acbaa4 100644 --- a/zabbix-autoregister/deploy_zabbix_agent_linux_arm.sh +++ b/zabbix-autoregister/deploy_zabbix_agent_linux_arm.sh @@ -99,11 +99,31 @@ install_agent_package_manager() { fi # The arm64 Zabbix repos only support Debian 12+ (bookworm, trixie). - # For older/EOL releases like bullseye, skip directly to binary install. + # For older/EOL releases like bullseye, try Debian's own repos first, + # then fall back to extracting from the bookworm .deb. case "${codename}" in buster|bullseye|stretch|jessie) log "Zabbix arm64 apt repo not available for EOL release '${codename}'." - log "Falling back to binary tarball..." + log "Attempting install from Debian's own repositories..." + + # Disable defunct backports repos first + local backports_list + backports_list=$(grep -rl 'backports' /etc/apt/sources.list /etc/apt/sources.list.d/ 2>/dev/null || true) + if [ -n "${backports_list}" ]; then + log "Disabling defunct backports repositories..." + for f in ${backports_list}; do + sed -i '/backports/s/^[^#]/#&/' "${f}" + done + fi + + # Try installing from existing repos (Debian's own packages) + apt-get update 2>&1 | grep -v "^W:" || true + if apt-get install -y zabbix-agent2 2>/dev/null; then + log "Installed from Debian repositories." + return 0 + fi + + log "Not available in Debian repos. Falling back to binary extraction..." install_agent_binary return 0 ;; @@ -156,17 +176,16 @@ install_agent_package_manager() { } install_agent_binary() { - log "Installing Zabbix Agent 2 from direct .deb package (bookworm arm64)..." + log "Installing Zabbix Agent 2 from direct .deb package..." # Zabbix does not publish static binary tarballs for ARM architectures. - # Instead, we fetch the .deb package directly from the debian-arm64 bookworm pool. - # Agent 2 is a Go binary with minimal libc dependencies, so installing a bookworm - # .deb on bullseye works reliably. + # Strategy: download the .deb and extract the binary without running post-install + # scripts (which try to start the service before we've configured it). local deb_path="/tmp/zabbix_agent2.deb" local pool_base="https://repo.zabbix.com/zabbix/7.0/debian-arm64/pool/main/z/zabbix" - # Try multiple URL patterns for the .deb package + # Try bookworm (Debian 12) arm64 .deb local deb_urls=( "${pool_base}/zabbix-agent2_${ZABBIX_VERSION}-1+debian12_arm64.deb" "${pool_base}/zabbix-agent2_${ZABBIX_VERSION}-1%2Bdebian12_arm64.deb" @@ -190,15 +209,14 @@ install_agent_binary() { rm -f "${deb_path}" done - # Fallback: try the CDN static tarball path (may work for some versions) if [ "${downloaded}" = false ]; then + # Fallback: try CDN static tarball (may work for some versions/arches) local tarball_url="https://cdn.zabbix.com/zabbix/binaries/stable/7.0/${ZABBIX_VERSION}/zabbix_agent2-${ZABBIX_VERSION}-${TARBALL_ARCH}-static.tar.gz" local tarball_path="/tmp/zabbix_agent2.tar.gz" log "Trying CDN tarball: ${tarball_url}" if wget -q "${tarball_url}" -O "${tarball_path}" 2>/dev/null || \ curl -sfL "${tarball_url}" -o "${tarball_path}" 2>/dev/null; then - # Verify it's actually a gzip file if file "${tarball_path}" 2>/dev/null | grep -q gzip; then install_from_tarball "${tarball_path}" return 0 @@ -207,42 +225,99 @@ install_agent_binary() { rm -f "${tarball_path}" log "ERROR: Failed to download Zabbix Agent 2 for ${ARCH_LABEL}." - log " No static binary or .deb package found." log " Options:" log " 1. Upgrade to Debian 12 (Bookworm) and re-run this script" log " 2. Manually download from https://www.zabbix.com/download" - log " 3. Install from Debian's own repos: apt install zabbix-agent2" exit 1 fi - # Install the .deb package - log "Installing .deb package..." - mkdir -p /etc/zabbix - mkdir -p /var/log/zabbix - mkdir -p /var/run/zabbix + # Extract the .deb contents manually instead of dpkg -i. + # This avoids post-install scripts that try to start the service before config is ready, + # and avoids glibc version issues by testing the binary directly. + log "Extracting .deb package contents..." + local extract_dir="/tmp/zabbix_agent2_extract" + rm -rf "${extract_dir}" + mkdir -p "${extract_dir}" + dpkg-deb -x "${deb_path}" "${extract_dir}" + + # Check if the binary actually runs on this system (glibc compatibility) + local agent_bin="${extract_dir}/usr/sbin/zabbix_agent2" + if [ ! -f "${agent_bin}" ]; then + agent_bin=$(find "${extract_dir}" -name "zabbix_agent2" -type f 2>/dev/null | head -1) + fi + + if [ -z "${agent_bin}" ] || [ ! -f "${agent_bin}" ]; then + log "ERROR: Could not find zabbix_agent2 binary in package." + rm -rf "${extract_dir}" "${deb_path}" + exit 1 + fi + + # Test if the binary can actually execute on this system + chmod +x "${agent_bin}" + if ! "${agent_bin}" --version >/dev/null 2>&1; then + log "WARNING: Bookworm binary incompatible with this system (likely glibc mismatch)." + log "Attempting full dpkg install with dependency resolution..." + rm -rf "${extract_dir}" + + # Stop any existing broken service + systemctl stop zabbix-agent2 2>/dev/null || true + systemctl disable zabbix-agent2 2>/dev/null || true + + # Try full install — may work if deps can be satisfied + dpkg -i --force-depends "${deb_path}" 2>/dev/null || true + + # Check if binary landed and works + if [ -f /usr/sbin/zabbix_agent2 ] && /usr/sbin/zabbix_agent2 --version >/dev/null 2>&1; then + log "Package installation succeeded despite warnings." + rm -f "${deb_path}" + return 0 + fi + + # Clean up the broken install + dpkg --remove --force-remove-reinstreq zabbix-agent2 2>/dev/null || true + + log "ERROR: Zabbix Agent 2 binary from Debian 12 is not compatible with this system." + log " Your system runs glibc $(ldd --version 2>&1 | head -1 | grep -oP '\\d+\\.\\d+$' || echo 'unknown') but the package requires glibc 2.36+." + log " Options:" + log " 1. Upgrade to Debian 12 (Bookworm): https://www.debian.org/releases/bookworm/" + log " 2. Use Zabbix Agent (v1) instead: apt install zabbix-agent" + log " 3. Build from source: https://www.zabbix.com/documentation/current/en/manual/installation/install" + rm -f "${deb_path}" + exit 1 + fi + + # Binary works! Install files to their proper locations. + log "Binary compatibility verified. Installing files..." # Create zabbix user if it doesn't exist if ! id -u zabbix &>/dev/null; then useradd -r -s /sbin/nologin -d /var/lib/zabbix -M zabbix fi - # Install with --force-depends to handle minor dependency version mismatches - # between bookworm and bullseye - if ! dpkg -i --force-depends "${deb_path}" 2>&1; then - log "dpkg install had issues, attempting to fix dependencies..." - apt-get install -f -y 2>/dev/null || true + # Copy binary + cp "${agent_bin}" /usr/sbin/zabbix_agent2 + chmod +x /usr/sbin/zabbix_agent2 + + # Copy config files and directories + mkdir -p /etc/zabbix + if [ -d "${extract_dir}/etc/zabbix" ]; then + cp -rn "${extract_dir}/etc/zabbix/"* /etc/zabbix/ 2>/dev/null || true fi - rm -f "${deb_path}" + # Set up directories + mkdir -p /var/log/zabbix /var/run/zabbix /var/lib/zabbix + chown -R zabbix:zabbix /var/log/zabbix /var/run/zabbix /var/lib/zabbix - # Verify the binary is in place - if command -v zabbix_agent2 >/dev/null 2>&1 || [ -f /usr/sbin/zabbix_agent2 ]; then - log "Package installation complete." - chown -R zabbix:zabbix /var/log/zabbix /var/run/zabbix 2>/dev/null || true + # Install systemd service from package or create our own + if [ -f "${extract_dir}/lib/systemd/system/zabbix-agent2.service" ]; then + cp "${extract_dir}/lib/systemd/system/zabbix-agent2.service" /lib/systemd/system/ + systemctl daemon-reload else - log "ERROR: zabbix_agent2 binary not found after package install." - exit 1 + create_systemd_service fi + + rm -rf "${extract_dir}" "${deb_path}" + log "Installation complete." } install_from_tarball() { From 5f0492d5a3bcd0773b0e3990265af41a18c7c367 Mon Sep 17 00:00:00 2001 From: p2913020 Date: Wed, 1 Jul 2026 16:16:40 -0400 Subject: [PATCH 5/5] New update for 32-bit ARM --- .../deploy_zabbix_agent_linux_arm.sh | 208 ++++++++++++++++-- 1 file changed, 185 insertions(+), 23 deletions(-) diff --git a/zabbix-autoregister/deploy_zabbix_agent_linux_arm.sh b/zabbix-autoregister/deploy_zabbix_agent_linux_arm.sh index 0acbaa4..d8ade91 100644 --- a/zabbix-autoregister/deploy_zabbix_agent_linux_arm.sh +++ b/zabbix-autoregister/deploy_zabbix_agent_linux_arm.sh @@ -1,7 +1,9 @@ #!/bin/bash # -# Zabbix Agent 2 Deployment Script - Linux ARM (aarch64 / armhf) +# Zabbix Agent 2 Deployment Script - Linux ARM (aarch64 / armhf / armv6) # Installs and configures Zabbix Agent 2 with PSK auto-registration +# For armhf/armv6: falls back to Zabbix Agent (v1) since Agent 2 is not +# available for 32-bit ARM (see ZBX-24905). # Target server: zabbix.snarfnet.net # # Usage: sudo bash deploy_zabbix_agent_linux_arm.sh [psk_key] @@ -16,6 +18,7 @@ PSK_FILE="/etc/zabbix/zabbix_agent2.psk" AGENT_CONF="/etc/zabbix/zabbix_agent2.conf" HOST_METADATA="Linux" INSTALL_DIR="/opt/zabbix-agent2" +USING_AGENT_V1=false # --- Functions --- @@ -66,9 +69,11 @@ install_agent_package_manager() { # Zabbix provides separate repos for ARM architectures: # - debian-arm64 / ubuntu-arm64 for aarch64 (Bookworm/Trixie+ only) - # - raspbian for armhf (Raspberry Pi OS) + # - raspbian for armhf (Raspberry Pi OS) — but NOTE: Zabbix 7.0 does NOT + # ship zabbix-agent2 for armhf (see ZBX-24905). Only zabbix-agent (v1). # The standard debian/ubuntu repos only carry amd64. local repo_distro="" + local has_agent2=true case "${dpkg_arch}" in arm64) if [ "${OS_ID}" = "ubuntu" ]; then @@ -79,6 +84,9 @@ install_agent_package_manager() { ;; armhf) repo_distro="raspbian" + # Zabbix 7.0 raspbian repo does NOT include zabbix-agent2 for armhf. + # Only zabbix-agent (v1) is available. + has_agent2=false ;; *) log "Unexpected dpkg arch '${dpkg_arch}' on ARM script. Falling back to binary..." @@ -103,8 +111,13 @@ install_agent_package_manager() { # then fall back to extracting from the bookworm .deb. case "${codename}" in buster|bullseye|stretch|jessie) - log "Zabbix arm64 apt repo not available for EOL release '${codename}'." - log "Attempting install from Debian's own repositories..." + if [ "${has_agent2}" = true ]; then + log "Zabbix arm64 apt repo not available for EOL release '${codename}'." + log "Attempting install from Debian's own repositories..." + else + log "Zabbix raspbian repo not available for EOL release '${codename}'." + log "Attempting install from Debian's own repositories..." + fi # Disable defunct backports repos first local backports_list @@ -119,9 +132,19 @@ install_agent_package_manager() { # Try installing from existing repos (Debian's own packages) apt-get update 2>&1 | grep -v "^W:" || true if apt-get install -y zabbix-agent2 2>/dev/null; then - log "Installed from Debian repositories." + log "Installed zabbix-agent2 from Debian repositories." return 0 fi + # On armhf, try zabbix-agent (v1) as well + if [ "${has_agent2}" = false ]; then + log "zabbix-agent2 not available. Trying zabbix-agent (v1)..." + if apt-get install -y zabbix-agent 2>/dev/null; then + log "Installed zabbix-agent (v1) from Debian repositories." + AGENT_CONF="/etc/zabbix/zabbix_agentd.conf" + USING_AGENT_V1=true + return 0 + fi + fi log "Not available in Debian repos. Falling back to binary extraction..." install_agent_binary @@ -139,8 +162,9 @@ install_agent_package_manager() { done fi - # Download and install the Zabbix release package for the ARM-specific repo - local release_url="https://repo.zabbix.com/zabbix/7.0/${repo_distro}/pool/main/z/zabbix-release/zabbix-release_latest_7.0+${OS_ID}${OS_VERSION}_all.deb" + # Download and install the Zabbix release package for the ARM-specific repo. + # URL format: zabbix-release_latest+debian12_all.deb (for both raspbian & debian-arm64) + local release_url="https://repo.zabbix.com/zabbix/7.0/${repo_distro}/pool/main/z/zabbix-release/zabbix-release_latest+debian${OS_VERSION}_all.deb" log "Adding Zabbix repository: ${repo_distro} (${codename})" log "Release package URL: ${release_url}" @@ -157,11 +181,25 @@ install_agent_package_manager() { dpkg -i /tmp/zabbix-release.deb apt-get update - if apt-get install -y zabbix-agent2; then + + # Try zabbix-agent2 first + if apt-get install -y zabbix-agent2 2>/dev/null; then rm -f /tmp/zabbix-release.deb - log "Package installation successful." + log "zabbix-agent2 package installation successful." return 0 fi + + # On armhf, agent2 won't exist — fall back to zabbix-agent (v1) + if [ "${has_agent2}" = false ]; then + log "zabbix-agent2 not available for armhf. Installing zabbix-agent (v1)..." + if apt-get install -y zabbix-agent; then + rm -f /tmp/zabbix-release.deb + AGENT_CONF="/etc/zabbix/zabbix_agentd.conf" + USING_AGENT_V1=true + log "zabbix-agent (v1) package installation successful." + return 0 + fi + fi fi log "Package manager install failed, falling back to binary tarball..." @@ -175,20 +213,93 @@ install_agent_package_manager() { esac } +install_agent_v1_armhf() { + # Zabbix 7.0 raspbian repo provides zabbix-agent (v1) for armhf but NOT agent2. + # This function installs agent v1 as a fallback for 32-bit ARM systems. + detect_os + local codename="" + if [ -f /etc/os-release ]; then + codename=$(. /etc/os-release && echo "${VERSION_CODENAME:-}") + fi + + # Try adding the raspbian repo and installing zabbix-agent (v1) + local release_url="https://repo.zabbix.com/zabbix/7.0/raspbian/pool/main/z/zabbix-release/zabbix-release_latest+debian${OS_VERSION}_all.deb" + log "Trying Zabbix raspbian repo for zabbix-agent (v1)..." + log "Release URL: ${release_url}" + + if wget -q "${release_url}" -O /tmp/zabbix-release.deb 2>/dev/null || \ + curl -sfL "${release_url}" -o /tmp/zabbix-release.deb 2>/dev/null; then + if dpkg-deb --info /tmp/zabbix-release.deb >/dev/null 2>&1; then + dpkg -i /tmp/zabbix-release.deb 2>/dev/null || true + apt-get update 2>/dev/null || true + if apt-get install -y zabbix-agent 2>/dev/null; then + rm -f /tmp/zabbix-release.deb + AGENT_CONF="/etc/zabbix/zabbix_agentd.conf" + USING_AGENT_V1=true + log "Installed zabbix-agent (v1) successfully from raspbian repository." + return 0 + fi + fi + fi + rm -f /tmp/zabbix-release.deb + + # Also try installing directly if it's already in repos + if apt-get install -y zabbix-agent 2>/dev/null; then + AGENT_CONF="/etc/zabbix/zabbix_agentd.conf" + USING_AGENT_V1=true + log "Installed zabbix-agent (v1) from existing repositories." + return 0 + fi + + log "Could not install zabbix-agent (v1) either." + return 1 +} + install_agent_binary() { log "Installing Zabbix Agent 2 from direct .deb package..." # Zabbix does not publish static binary tarballs for ARM architectures. # Strategy: download the .deb and extract the binary without running post-install # scripts (which try to start the service before we've configured it). + # + # IMPORTANT: Zabbix 7.0 only provides zabbix-agent2 for arm64, NOT armhf. + # For armhf/armv6 systems, we try arm64 .deb extraction (unlikely to work due to + # arch mismatch), then fall back to zabbix-agent (v1) from the raspbian repo, + # or suggest upgrading to a 64-bit OS. local deb_path="/tmp/zabbix_agent2.deb" - local pool_base="https://repo.zabbix.com/zabbix/7.0/debian-arm64/pool/main/z/zabbix" + local dpkg_arch + dpkg_arch=$(dpkg --print-architecture 2>/dev/null || echo "unknown") + + # Select the correct pool and architecture for the .deb download + local pool_base="" + local deb_arch="" + case "${dpkg_arch}" in + arm64) + pool_base="https://repo.zabbix.com/zabbix/7.0/debian-arm64/pool/main/z/zabbix" + deb_arch="arm64" + ;; + armhf) + # Zabbix 7.0 does NOT publish agent2 for armhf. Try the raspbian pool + # for zabbix-agent (v1) first, then fall back to arm64 extraction attempt. + log "NOTE: Zabbix 7.0 does not provide zabbix-agent2 for armhf (32-bit ARM)." + log "Attempting to install zabbix-agent (v1) from raspbian repository..." + if install_agent_v1_armhf; then + return 0 + fi + # Last resort: try arm64 binary (won't work on 32-bit kernel) + pool_base="https://repo.zabbix.com/zabbix/7.0/debian-arm64/pool/main/z/zabbix" + deb_arch="arm64" + ;; + *) + pool_base="https://repo.zabbix.com/zabbix/7.0/debian-arm64/pool/main/z/zabbix" + deb_arch="arm64" + ;; + esac - # Try bookworm (Debian 12) arm64 .deb local deb_urls=( - "${pool_base}/zabbix-agent2_${ZABBIX_VERSION}-1+debian12_arm64.deb" - "${pool_base}/zabbix-agent2_${ZABBIX_VERSION}-1%2Bdebian12_arm64.deb" + "${pool_base}/zabbix-agent2_${ZABBIX_VERSION}-1+debian12_${deb_arch}.deb" + "${pool_base}/zabbix-agent2_${ZABBIX_VERSION}-1%2Bdebian12_${deb_arch}.deb" ) local downloaded=false @@ -276,10 +387,18 @@ install_agent_binary() { # Clean up the broken install dpkg --remove --force-remove-reinstreq zabbix-agent2 2>/dev/null || true + # On armhf, try zabbix-agent (v1) before giving up + if [ "${dpkg_arch}" = "armhf" ]; then + log "Attempting zabbix-agent (v1) as final fallback..." + if install_agent_v1_armhf; then + return 0 + fi + fi + log "ERROR: Zabbix Agent 2 binary from Debian 12 is not compatible with this system." log " Your system runs glibc $(ldd --version 2>&1 | head -1 | grep -oP '\\d+\\.\\d+$' || echo 'unknown') but the package requires glibc 2.36+." log " Options:" - log " 1. Upgrade to Debian 12 (Bookworm): https://www.debian.org/releases/bookworm/" + log " 1. Upgrade to a 64-bit OS (Raspberry Pi OS 64-bit): https://www.raspberrypi.com/software/" log " 2. Use Zabbix Agent (v1) instead: apt install zabbix-agent" log " 3. Build from source: https://www.zabbix.com/documentation/current/en/manual/installation/install" rm -f "${deb_path}" @@ -404,7 +523,35 @@ configure_agent() { # Back up existing config if present [ -f "${AGENT_CONF}" ] && cp "${AGENT_CONF}" "${AGENT_CONF}.bak.$(date +%s)" - cat > "${AGENT_CONF}" << EOF + if [ "${USING_AGENT_V1}" = true ]; then + # Zabbix Agent (v1) configuration — slightly different directives + cat > "${AGENT_CONF}" << EOF +# Zabbix Agent (v1) Configuration +# Auto-generated by ARM deployment script on $(date '+%Y-%m-%d %H:%M:%S') +# Architecture: ${ARCH} (${ARCH_LABEL}) +# Note: Agent v1 installed because Agent 2 is not available for armhf + +Server=${ZABBIX_SERVER} +ServerActive=${ZABBIX_SERVER} +HostnameItem=system.hostname +HostMetadata=${HOST_METADATA} + +# PSK Encryption +TLSConnect=psk +TLSAccept=psk +TLSPSKIdentity=${PSK_IDENTITY} +TLSPSKFile=${PSK_FILE} + +# Logging +LogFile=/var/log/zabbix/zabbix_agentd.log +LogFileSize=10 + +# Performance +BufferSend=5 +BufferSize=100 +EOF + else + cat > "${AGENT_CONF}" << EOF # Zabbix Agent 2 Configuration # Auto-generated by ARM deployment script on $(date '+%Y-%m-%d %H:%M:%S') # Architecture: ${ARCH} (${ARCH_LABEL}) @@ -428,24 +575,34 @@ LogFileSize=10 BufferSend=5 BufferSize=100 EOF + fi chown root:zabbix "${AGENT_CONF}" chmod 644 "${AGENT_CONF}" } start_agent() { - log "Enabling and starting zabbix-agent2..." - systemctl enable zabbix-agent2 - systemctl restart zabbix-agent2 + local service_name="zabbix-agent2" + if [ "${USING_AGENT_V1}" = true ]; then + service_name="zabbix-agent" + fi + + log "Enabling and starting ${service_name}..." + systemctl enable "${service_name}" + systemctl restart "${service_name}" sleep 2 - if systemctl is-active --quiet zabbix-agent2; then - log "Zabbix Agent 2 is running." - systemctl status zabbix-agent2 --no-pager + if systemctl is-active --quiet "${service_name}"; then + log "${service_name} is running." + systemctl status "${service_name}" --no-pager else log "WARNING: Agent may not have started. Check logs:" - log " journalctl -u zabbix-agent2 -n 20" - log " cat /var/log/zabbix/zabbix_agent2.log" + log " journalctl -u ${service_name} -n 20" + if [ "${USING_AGENT_V1}" = true ]; then + log " cat /var/log/zabbix/zabbix_agentd.log" + else + log " cat /var/log/zabbix/zabbix_agent2.log" + fi fi } @@ -480,6 +637,11 @@ configure_agent "${PSK_KEY}" start_agent log "=== Deployment Complete ===" +if [ "${USING_AGENT_V1}" = true ]; then + log "Agent Version: Zabbix Agent (v1) — agent2 not available for ${ARCH_LABEL}" +else + log "Agent Version: Zabbix Agent 2" +fi log "PSK Identity: ${PSK_IDENTITY}" log "PSK Key: ${PSK_KEY}" log ""