From 62440175207d2c5210d166dfbc3356256068c0f4 Mon Sep 17 00:00:00 2001 From: allan Date: Fri, 19 Dec 2025 15:05:49 +0100 Subject: [PATCH] latest commit --- LICENSE | 21 ++++ README.md | 179 +++++++++++++++++++++++++++ last-tested | 6 + zabbixinstall | 327 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 533 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 last-tested create mode 100755 zabbixinstall diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3eaaa81 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Allan Christensen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..9553ac4 --- /dev/null +++ b/README.md @@ -0,0 +1,179 @@ +# Zabbix 7.0 LTS for Ubuntu 24.04 Server +[![OS](https://img.shields.io/badge/ubuntu-24.04-E95420)](#) +[![Shell](https://img.shields.io/badge/shell-bash-121011)](#) +[![WebServer](https://img.shields.io/badge/server-nginx-009639)](#) +[![PHP](https://img.shields.io/badge/php-fpm-777BB4)](#) +[![MariaDB](https://img.shields.io/badge/db-mariadb-003545)](#) +[![MySQL](https://img.shields.io/badge/db-mysql-4479A1)](#) +[![Zabbix](https://img.shields.io/badge/app-zabbix_7.0_LTS-DC382D)](#) +[![License](https://img.shields.io/badge/license-MIT-green)](./LICENSE) + +Install Zabbix 7.0 LTS on Ubuntu 24.04 server. + +This is not a guide and not a toy. +Fully automated server + agent setup, including DB schema import and ready-to-use Nginx config. + +## Why this installer exists +Manual Zabbix setup is time-consuming, repetitive and error-prone. This script reduces it to one run. + +## What this installer does +✔ Creates database + user +✔ Imports schema automatically +✔ Generates + validates Nginx host config +✔ Detects socket vs password auth +✔ Enables Zabbix server & agent immediately + +## What this installer does *NOT* do +It won’t stop you from running the script without reading the documentation like there’s no tomorrow. +Skip the README, and whatever happens next is your headache, not a bug report. + +--- + +## Requirements + +You must already have: + +✔ Nginx running +✔ PHP-FPM running +✔ MariaDB/MySQL installed +✔ Root access (script checks and exits if missing) + +### Optional Installers (if you need them — saves you some googling) + +- [Install Nginx + PHP-FPM on Ubuntu](https://git.x-files.dk/webserver/nginx-ubuntu) +- [Install MariaDB on Ubuntu](https://git.x-files.dk/database/mariadb-ubuntu) +- [Install MySQL on Ubuntu](https://git.x-files.dk/database/mysql-ubuntu) + +--- + +## 1. Prepare the system + +``` +sudo apt update -y +``` + +## 2. Download the installer + +``` +git clone https://git.x-files.dk/network/zabbix-ubuntu.git +``` + +``` +cd zabbix-ubuntu +``` + +--- + +## 3. Run the installer + +``` +sudo ./zabbixinstall -n -p +``` + +Socket auth (default Ubuntu) — simplest mode: +``` +sudo ./zabbixinstall -n zabbix.example.com -p ZabbixPass123 +``` + +Password authentication: +``` +sudo ./zabbixinstall -n zabbix.example.com -p ZabbixPass123 -a root -m rootpwd +sudo ./zabbixinstall -n zabbix.example.com -p ZabbixPass123 -a admin -m adminpwd +``` + +### Options + +| Flag | Description | +|---|---| +| `-n` domain | Required — hostname used for nginx + UI access | +| `-p` password | Required — DB password for Zabbix user | +| `-a` username | DB admin (default `root`) | +| `-m` password | Required only without socket auth | +| `-h`, `--help` | Displays mode-aware help screen | + +--- + +## What the Installer Does + +✔ Installs Zabbix 7.0 LTS packages +✔ Creates DB + user securely with utf8mb4 +✔ Detects socket vs password auth automatically +✔ Imports schema — no UI import required +✔ Generates nginx host config in `/etc/nginx/conf.d/` +✔ Pulls **nginx-snippets** repo for TLS & caching support +✔ Enables + starts Zabbix server + agent +✔ Can be safely re-run — existing DB intact + +--- + +## First Login + +Open: + +``` +http:// +``` + +Default admin access: + +| User | Password | +|---|---| +| Admin | zabbix | + +If **socket auth NOT detected**, UI login must use: + +``` +DB Host = 127.0.0.1 +``` + +Entering `localhost` will fail. + +--- + +## File Paths + +| Path | Purpose | +|---|---| +| `/etc/zabbix/zabbix_server.conf` | Main server configuration | +| `/usr/share/zabbix-sql-scripts/mysql/server.sql.gz` | Schema imported automatically | +| `/etc/nginx/conf.d/.conf` | Web server config | +| `/etc/nginx/nginx-snippets/` | Shared reusable config modules | + +--- + +## HTTPS + TLS + +443 host file available: + +``` +https://git.x-files.dk/webserver/nginx-snippets/src/branch/main/hostfiles/zabbix.443.conf +``` + +Caching options included but disabled until uncommented: + +``` +# include cache-open-files.conf; +# include cache-js-css.conf; +# include cache-statics.conf; +``` + +--- + +## Troubleshooting + +| Issue | Cause | Fix | +|---|---|---| +| UI install fails | Socket disabled + used localhost | Replace with `127.0.0.1` | +| DB creation denied | No socket auth detected | Re-run with `-m` (and `-a` optional) | +| PHP errors | Wrong PHP-FPM version | `systemctl status php*-fpm` | +| Nginx restart fails | Config syntax error | Run `nginx -t` | + +--- +### More Information + +More guides and documentation can be found on [wiki.x-files.dk](https://wiki.x-files.dk) + +--- + +### License +Licensed under the [MIT License](./LICENSE). diff --git a/last-tested b/last-tested new file mode 100644 index 0000000..8496aad --- /dev/null +++ b/last-tested @@ -0,0 +1,6 @@ +------------------------------------ +Last tested: 19-12-2025 (DD-MM-YYYY) +Environment: Ubuntu Server 24.04 LTS +Database : MariaDB 10.11.13 +Database : MySQL 8.0.44-0 +------------------------------------ diff --git a/zabbixinstall b/zabbixinstall new file mode 100755 index 0000000..f7f2e60 --- /dev/null +++ b/zabbixinstall @@ -0,0 +1,327 @@ +#!/usr/bin/env bash + +# Author : Allan Christensen +# First Created : 11-01-2021 (DD-MM-YYYY) +# Description : Installs Zabbix on Ubuntu 24.04 (MariaDB or MySQL) +# License : MIT License + +# +# Are we root +# +if [[ $(id -u) -ne 0 ]]; then echo "" && echo "Must be root or use sudo" && echo "" ; exit 1 ; fi + +# +# Get PHP-FPM version +# +phpfpm=$(systemctl list-unit-files --type=service | awk '/php[0-9]+\.[0-9]+-fpm\.service/ {sub(".service","",$1); print $1; exit}') +if [[ -z "$phpfpm" ]]; then printf "\nUnable to detect php-fpm version. Is PHP-FPM installed?\n\n" ; exit 1 ; fi + +# +# Detect database engine (MariaDB or MySQL) +# +if systemctl list-unit-files | grep -q '^mariadb\.service'; then + db_engine="mariadb" + db_service="mariadb" +elif systemctl list-unit-files | grep -q '^mysql\.service'; then + db_engine="mysql" + db_service="mysql" +else + printf "\nNo supported database server found.\n\n" + printf "You must have MariaDB or MySQL installed and enabled.\n\n" + exit 1 +fi + +# +# Check if required services are running +# +for svc in nginx "$db_service" "$phpfpm"; do + systemctl is-active --quiet "$svc" || { + printf "\n%s is not running, cannot continue...\n\n" "${svc^}" + exit 1 + } +done + +# +# Check DB authentication method +# (local root access via socket / auth_socket / passwordless) +# +if mysql -u root -e ";" 2>/dev/null; then + socketauth="yes" +else + socketauth="no" +fi + +# +# Variables +# +ubuntuversion="24.04" +zabbix_version="7.0" + +# +# Function: usage +# +usage() { + printf -- "\nzabbixinstall (Ubuntu 24.04 + Zabbix 7.0 LTS)\n\n" + printf -- "Database engine detected: %s\n\n" "$db_engine" + + if [[ "$socketauth" == "yes" ]]; then + printf -- "LOCAL ROOT ACCESS DETECTED — no need for -a or -m\n\n" + printf -- "Usage:\n" + printf -- " sudo ./zabbixinstall -n -p \n\n" + else + printf -- "NO LOCAL ROOT ACCESS — you must use -a and -m\n\n" + printf -- "Usage:\n" + printf -- " sudo ./zabbixinstall -n -p -a -m \n\n" + fi + + printf -- "Options:\n" + printf -- " -h | -help | --help Show this help screen\n\n" +} + +# +# Let's go +# +clear + +if [[ "$1" == "-help" || "$1" == "--help" ]]; then usage ; exit 0 ; fi +if [[ $# -eq 0 || ! $1 =~ ^- ]]; then usage ; exit 1 ; fi + +while getopts ":n:p:m:a:h" option; do + case "$option" in + n) hostname=$(echo "$OPTARG" | tr '[:upper:]' '[:lower:]');; + p) dbpass="$OPTARG";; + m) db_admin_pwd="$OPTARG";; + a) db_admin_user="$OPTARG";; + h) usage; exit 0;; + :) usage; echo ""; echo "Error! Option -$OPTARG requires an argument."; echo ""; exit 1;; + \?) usage; echo ""; echo "Error! Invalid option: -$OPTARG"; echo ""; exit 1;; + esac +done + +# +# Validate input +# +if [[ -z "$hostname" || -z "$dbpass" ]]; then + usage + printf "\nERROR: Both -n (domain) and -p (database password) are required.\n\n" + exit 1 +fi + +hostname=$(echo "$hostname" | tr '[:upper:]' '[:lower:]') + +if [[ "$hostname" =~ ^- ]]; then + printf "\nERROR: Domain cannot start with a hyphen.\n\n" + exit 1 +fi + +if [[ "$hostname" =~ [[:space:]/_] ]]; then + printf "\nERROR: Domain cannot contain spaces, slashes, or underscores.\n\n" + exit 1 +fi + +if [[ ! "$hostname" =~ ^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$ ]]; then + printf "\nERROR: Invalid domain format.\n\n" + exit 1 +fi + +if [[ "$dbpass" =~ [[:space:]] ]]; then + printf "\nERROR: Database password cannot contain spaces.\n\n" + exit 1 +fi + +printf "Using Zabbix LTS version: %s\n" "$zabbix_version" +printf "Database engine detected: %s\n\n" "$db_engine" + +# +# Install prerequisites +# +for tool in curl wget; do dpkg -s "$tool" &>/dev/null || apt install -y -qq "$tool" ; done + +# +# Install Zabbix repo +# +tmpfile="/tmp/zabbix-release_latest_${zabbix_version}+ubuntu${ubuntuversion}_all.deb" +download="https://repo.zabbix.com/zabbix/${zabbix_version}/ubuntu/pool/main/z/zabbix-release/zabbix-release_latest_${zabbix_version}+ubuntu${ubuntuversion}_all.deb" + +wget --no-verbose -O "$tmpfile" "$download" +dpkg -i "$tmpfile" +apt update + +# +# Install Zabbix packages +# +apt install -y zabbix-server-mysql zabbix-frontend-php zabbix-nginx-conf zabbix-sql-scripts zabbix-agent fping + +# +# Clone nginx-snippets +# +nginxsnippets="/etc/nginx/nginx-snippets" +repo="https://git.x-files.dk/webserver/nginx-snippets.git" +if [[ -d "$nginxsnippets/.git" ]]; then + git -C "$nginxsnippets" pull --quiet +else + git clone --quiet "$repo" "$nginxsnippets" +fi + +# +# DB access method +# +db_admin_user="${db_admin_user:-root}" + +printf "\nChecking database access method...\n" +if [[ "$socketauth" == "yes" ]]; then + dbmethod="socket" + printf "Local root access detected (socket/auth_socket)\n" +else + dbmethod="admin" + printf "Using admin user authentication (%s)\n" "$db_admin_user" +fi + +# +# Create Zabbix DB +# +case "$dbmethod" in + socket) + mysql -u root <