Add Windows PowerShell installer/updater

This commit is contained in:
2026-02-20 13:03:09 +01:00
parent 5bd28e5305
commit 758ec101f9
2 changed files with 267 additions and 4 deletions

View File

@ -1,26 +1,41 @@
# Zabbix Agent Deployment
Bash-Skripte zur automatischen Installation und Aktualisierung des Zabbix Agent 2 (Version 7.4) auf Debian/Ubuntu-Systemen lokal oder per SSH-Remote-Deployment.
Skripte zur automatischen Installation und Aktualisierung des Zabbix Agent 2 (Version 7.4) auf Linux- und Windows-Systemen lokal oder per SSH-Remote-Deployment.
---
## Voraussetzungen
**Linux:**
- Zielhost: Debian 11/12/13 oder Ubuntu 20.04 / 22.04 / 24.04
- SSH Key-Authentifizierung eingerichtet (`~/.ssh/config`)
- Zielhost muss als `root` erreichbar sein
- `wget` auf dem Zielhost vorhanden
**Windows:**
- Windows 10/11 oder Windows Server 2016+
- PowerShell 5.1 oder neuer
- Ausführung als Administrator erforderlich
---
## Konfiguration
In `install-zabbix-agent.sh` die Zabbix-Server-Adresse eintragen:
**Linux** in `install-zabbix-agent.sh` und `update-zabbix-agent.sh`:
```bash
ZABBIX_SERVER="zabbix.example.com" # Zeile 16
```
**Windows** in `install-update-zabbix-agent.ps1`:
```powershell
$ZabbixServer = "zabbix.example.com" # Zabbix-Server-Adresse
$ZabbixVersion = "7.4.2" # Bei neuen Releases anpassen
$ProxyList = @( # Proxy-Liste manuell pflegen
"http://proxy01.example.com:3128"
"http://proxy02.example.com:3128"
)
```
---
## Skripte
@ -87,6 +102,24 @@ bash deploy-update-zabbix-agent.sh webserver
---
### `install-update-zabbix-agent.ps1`
Installiert oder aktualisiert Zabbix Agent 2 auf Windows erkennt automatisch ob bereits eine Version vorhanden ist.
```powershell
PowerShell -ExecutionPolicy Bypass -File install-update-zabbix-agent.ps1
```
Was es tut:
- Erkennt automatisch: Neuinstallation oder Update
- Interaktive Eingabe des Zabbix-Hostnamens (Standard: Computername)
- Interaktive Proxy-Auswahl aus gepflegter Liste oder direkte Verbindung
- Lädt die MSI von `cdn.zabbix.com` herunter
- Installiert/aktualisiert still (`/qn`) ohne Benutzerinteraktion beim MSI
- Setzt `SERVER`, `SERVERACTIVE` und `HOSTNAME` direkt beim MSI-Aufruf
- Startet den Dienst automatisch
---
## Ablauf nach der Installation
Den Host im Zabbix-Frontend anlegen, falls noch nicht vorhanden:
@ -95,7 +128,7 @@ Den Host im Zabbix-Frontend anlegen, falls noch nicht vorhanden:
- Host name: identisch mit dem beim Skriptaufruf angegebenen `<zabbix-hostname>`
- Interface: Agent (aktiv) keine IP-Adresse notwendig bei reinem Aktiv-Modus
- Template: z.B. `Linux by Zabbix agent active`
- Template: z.B. `Linux by Zabbix agent active` bzw. `Windows by Zabbix agent active`
---

View File

@ -0,0 +1,230 @@
#Requires -RunAsAdministrator
# =============================================================================
# Zabbix Agent 2 Windows Installer / Updater (Version 7.4)
#
# Aufruf:
# PowerShell -ExecutionPolicy Bypass -File install-update-zabbix-agent.ps1
#
# Interaktiv: Proxy-Auswahl, Hostname-Eingabe, automatische Install/Update-Erkennung
# =============================================================================
# ── Konfiguration (manuell anpassen) ─────────────────────────────────────────
$ZabbixServer = "zabbix.example.com" # Zabbix-Server-Adresse
$ZabbixVersion = "7.4.2" # Zabbix-Version (bei neuen Releases anpassen)
# Proxy-Liste hier manuell pflegen
$ProxyList = @(
"http://proxy01.example.com:3128"
"http://proxy02.example.com:3128"
# weitere Proxys einfach hier eintragen
)
# Installationspfade (normalerweise nicht ändern nötig)
$InstallDir = "C:\Program Files\Zabbix Agent 2"
$ConfigFile = "$InstallDir\zabbix_agent2.conf"
$ServiceName = "Zabbix Agent 2"
$TempDir = $env:TEMP
# ── Hilfsfunktionen ───────────────────────────────────────────────────────────
function Write-Info { param($msg) Write-Host "[INFO] $msg" -ForegroundColor Green }
function Write-Warn { param($msg) Write-Host "[WARN] $msg" -ForegroundColor Yellow }
function Write-Err { param($msg) Write-Host "[ERROR] $msg" -ForegroundColor Red }
function Show-Header {
Write-Host ""
Write-Host "=============================================" -ForegroundColor Cyan
Write-Host " Zabbix Agent 2 $ZabbixVersion Windows Setup" -ForegroundColor Cyan
Write-Host "=============================================" -ForegroundColor Cyan
Write-Host ""
}
# ── Installierte Version prüfen ───────────────────────────────────────────────
function Get-InstalledVersion {
$reg = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" `
-ErrorAction SilentlyContinue |
Where-Object { $_.DisplayName -like "Zabbix Agent 2*" } |
Select-Object -First 1
return $reg?.DisplayVersion
}
# ── Proxy-Auswahl ─────────────────────────────────────────────────────────────
function Select-Proxy {
Write-Host "Proxy-Einstellungen:" -ForegroundColor Cyan
Write-Host " [0] Kein Proxy (direkte Verbindung)"
for ($i = 0; $i -lt $ProxyList.Count; $i++) {
Write-Host " [$($i+1)] $($ProxyList[$i])"
}
Write-Host ""
do {
$choice = Read-Host "Auswahl [0-$($ProxyList.Count)]"
} while ($choice -notmatch "^\d+$" -or [int]$choice -gt $ProxyList.Count)
if ($choice -eq "0") {
return $null
} else {
return $ProxyList[[int]$choice - 1]
}
}
# ── Download ──────────────────────────────────────────────────────────────────
function Get-ZabbixMsi {
param(
[string]$Url,
[string]$Destination,
[string]$ProxyUrl
)
Write-Info "Lade MSI herunter ..."
Write-Info "URL: $Url"
try {
$webClient = New-Object System.Net.WebClient
if ($ProxyUrl) {
Write-Info "Verwende Proxy: $ProxyUrl"
$proxy = New-Object System.Net.WebProxy($ProxyUrl, $true)
$proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
$webClient.Proxy = $proxy
} else {
$webClient.Proxy = $null
Write-Info "Direktverbindung (kein Proxy)"
}
$webClient.DownloadFile($Url, $Destination)
Write-Info "Download abgeschlossen: $Destination"
} catch {
Write-Err "Download fehlgeschlagen: $_"
exit 1
} finally {
$webClient.Dispose()
}
}
# ── MSI Install / Update ──────────────────────────────────────────────────────
function Install-ZabbixMsi {
param(
[string]$MsiPath,
[string]$Hostname,
[bool]$IsUpdate
)
$action = if ($IsUpdate) { "Update" } else { "Installation" }
Write-Info "Starte $action ..."
# Bei Update: Dienst stoppen
if ($IsUpdate) {
$svc = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if ($svc -and $svc.Status -eq "Running") {
Write-Info "Stoppe Dienst '$ServiceName' ..."
Stop-Service -Name $ServiceName -Force
Start-Sleep -Seconds 2
}
}
$msiArgs = @(
"/i", $MsiPath,
"/qn", # Silent
"/l*v", "$TempDir\zabbix-install.log",
"SERVER=$ZabbixServer",
"SERVERACTIVE=$ZabbixServer",
"HOSTNAME=$Hostname",
"LISTENPORT=10050"
)
$proc = Start-Process -FilePath "msiexec.exe" -ArgumentList $msiArgs -Wait -PassThru
if ($proc.ExitCode -ne 0) {
Write-Err "MSI $action fehlgeschlagen (ExitCode: $($proc.ExitCode))"
Write-Err "Details: $TempDir\zabbix-install.log"
exit 1
}
Write-Info "MSI $action erfolgreich."
}
# ── Dienst starten ────────────────────────────────────────────────────────────
function Start-ZabbixService {
$svc = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if (-not $svc) {
Write-Err "Dienst '$ServiceName' nicht gefunden."
exit 1
}
Set-Service -Name $ServiceName -StartupType Automatic
Start-Service -Name $ServiceName
Start-Sleep -Seconds 2
$svc.Refresh()
return $svc.Status
}
# ── Hauptprogramm ─────────────────────────────────────────────────────────────
Show-Header
# Installierte Version ermitteln
$installedVersion = Get-InstalledVersion
$isUpdate = $null -ne $installedVersion
if ($isUpdate) {
Write-Info "Installierte Version gefunden: $installedVersion"
Write-Info "Modus: UPDATE auf $ZabbixVersion"
} else {
Write-Info "Kein Zabbix Agent gefunden."
Write-Info "Modus: NEUINSTALLATION von $ZabbixVersion"
}
Write-Host ""
# Hostname abfragen
$defaultHostname = $env:COMPUTERNAME
$inputHostname = Read-Host "Zabbix-Hostname eingeben [Standard: $defaultHostname]"
$agentHostname = if ($inputHostname.Trim() -eq "") { $defaultHostname } else { $inputHostname.Trim() }
Write-Info "Verwende Hostname: $agentHostname"
Write-Host ""
# Proxy-Auswahl
$selectedProxy = Select-Proxy
Write-Host ""
# MSI-Download-URL zusammenbauen
$arch = "amd64"
$msiFile = "zabbix_agent2-$ZabbixVersion-windows-$arch-openssl.msi"
$msiUrl = "https://cdn.zabbix.com/zabbix/binaries/stable/" +
"$($ZabbixVersion.Split('.')[0..1] -join '.')/$ZabbixVersion/$msiFile"
$msiDest = "$TempDir\$msiFile"
# Download
Get-ZabbixMsi -Url $msiUrl -Destination $msiDest -ProxyUrl $selectedProxy
# Installation / Update
Install-ZabbixMsi -MsiPath $msiDest -Hostname $agentHostname -IsUpdate $isUpdate
# Temporäre Datei aufräumen
Remove-Item -Path $msiDest -Force -ErrorAction SilentlyContinue
# Dienst starten
Write-Info "Starte Zabbix-Dienst ..."
$status = Start-ZabbixService
# Ergebnis
Write-Host ""
Write-Host "=============================================" -ForegroundColor Cyan
Write-Info " Zabbix Agent 2 erfolgreich eingerichtet!"
Write-Info " Hostname : $agentHostname"
Write-Info " Server : $ZabbixServer"
Write-Info " Version : $ZabbixVersion"
Write-Info " Modus : Aktiv"
Write-Info " Dienst : $status"
Write-Host "=============================================" -ForegroundColor Cyan
Write-Host ""
Write-Warn "Denk daran: Den Host '$agentHostname' im Zabbix-Frontend anlegen,"
Write-Warn "falls er noch nicht existiert (Configuration -> Hosts -> Create host)."
Write-Host ""