last update

This commit is contained in:
p2913020
2026-06-29 13:06:18 -04:00
parent e10c291958
commit 37d8f2c5b7

View File

@@ -99,11 +99,31 @@ install_agent_package_manager() {
fi fi
# The arm64 Zabbix repos only support Debian 12+ (bookworm, trixie). # 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 case "${codename}" in
buster|bullseye|stretch|jessie) buster|bullseye|stretch|jessie)
log "Zabbix arm64 apt repo not available for EOL release '${codename}'." 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 install_agent_binary
return 0 return 0
;; ;;
@@ -156,17 +176,16 @@ install_agent_package_manager() {
} }
install_agent_binary() { 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. # Zabbix does not publish static binary tarballs for ARM architectures.
# Instead, we fetch the .deb package directly from the debian-arm64 bookworm pool. # Strategy: download the .deb and extract the binary without running post-install
# Agent 2 is a Go binary with minimal libc dependencies, so installing a bookworm # scripts (which try to start the service before we've configured it).
# .deb on bullseye works reliably.
local deb_path="/tmp/zabbix_agent2.deb" local deb_path="/tmp/zabbix_agent2.deb"
local pool_base="https://repo.zabbix.com/zabbix/7.0/debian-arm64/pool/main/z/zabbix" 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=( local deb_urls=(
"${pool_base}/zabbix-agent2_${ZABBIX_VERSION}-1+debian12_arm64.deb" "${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%2Bdebian12_arm64.deb"
@@ -190,15 +209,14 @@ install_agent_binary() {
rm -f "${deb_path}" rm -f "${deb_path}"
done done
# Fallback: try the CDN static tarball path (may work for some versions)
if [ "${downloaded}" = false ]; then 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_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" local tarball_path="/tmp/zabbix_agent2.tar.gz"
log "Trying CDN tarball: ${tarball_url}" log "Trying CDN tarball: ${tarball_url}"
if wget -q "${tarball_url}" -O "${tarball_path}" 2>/dev/null || \ if wget -q "${tarball_url}" -O "${tarball_path}" 2>/dev/null || \
curl -sfL "${tarball_url}" -o "${tarball_path}" 2>/dev/null; then 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 if file "${tarball_path}" 2>/dev/null | grep -q gzip; then
install_from_tarball "${tarball_path}" install_from_tarball "${tarball_path}"
return 0 return 0
@@ -207,42 +225,99 @@ install_agent_binary() {
rm -f "${tarball_path}" rm -f "${tarball_path}"
log "ERROR: Failed to download Zabbix Agent 2 for ${ARCH_LABEL}." log "ERROR: Failed to download Zabbix Agent 2 for ${ARCH_LABEL}."
log " No static binary or .deb package found."
log " Options:" log " Options:"
log " 1. Upgrade to Debian 12 (Bookworm) and re-run this script" log " 1. Upgrade to Debian 12 (Bookworm) and re-run this script"
log " 2. Manually download from https://www.zabbix.com/download" log " 2. Manually download from https://www.zabbix.com/download"
log " 3. Install from Debian's own repos: apt install zabbix-agent2"
exit 1 exit 1
fi fi
# Install the .deb package # Extract the .deb contents manually instead of dpkg -i.
log "Installing .deb package..." # This avoids post-install scripts that try to start the service before config is ready,
mkdir -p /etc/zabbix # and avoids glibc version issues by testing the binary directly.
mkdir -p /var/log/zabbix log "Extracting .deb package contents..."
mkdir -p /var/run/zabbix 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 # Create zabbix user if it doesn't exist
if ! id -u zabbix &>/dev/null; then if ! id -u zabbix &>/dev/null; then
useradd -r -s /sbin/nologin -d /var/lib/zabbix -M zabbix useradd -r -s /sbin/nologin -d /var/lib/zabbix -M zabbix
fi fi
# Install with --force-depends to handle minor dependency version mismatches # Copy binary
# between bookworm and bullseye cp "${agent_bin}" /usr/sbin/zabbix_agent2
if ! dpkg -i --force-depends "${deb_path}" 2>&1; then chmod +x /usr/sbin/zabbix_agent2
log "dpkg install had issues, attempting to fix dependencies..."
apt-get install -f -y 2>/dev/null || true # 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 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 # Install systemd service from package or create our own
if command -v zabbix_agent2 >/dev/null 2>&1 || [ -f /usr/sbin/zabbix_agent2 ]; then if [ -f "${extract_dir}/lib/systemd/system/zabbix-agent2.service" ]; then
log "Package installation complete." cp "${extract_dir}/lib/systemd/system/zabbix-agent2.service" /lib/systemd/system/
chown -R zabbix:zabbix /var/log/zabbix /var/run/zabbix 2>/dev/null || true systemctl daemon-reload
else else
log "ERROR: zabbix_agent2 binary not found after package install." create_systemd_service
exit 1
fi fi
rm -rf "${extract_dir}" "${deb_path}"
log "Installation complete."
} }
install_from_tarball() { install_from_tarball() {