You've already forked zabbix-ubuntu
latest commit
This commit is contained in:
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -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.
|
||||
179
README.md
Normal file
179
README.md
Normal file
@@ -0,0 +1,179 @@
|
||||
# Zabbix 7.0 LTS for Ubuntu 24.04 Server
|
||||
[](#)
|
||||
[](#)
|
||||
[](#)
|
||||
[](#)
|
||||
[](#)
|
||||
[](#)
|
||||
[](#)
|
||||
[](./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 <domain> -p <zabbixdbpassword>
|
||||
```
|
||||
|
||||
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://<domain>
|
||||
```
|
||||
|
||||
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/<domain>.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).
|
||||
6
last-tested
Normal file
6
last-tested
Normal file
@@ -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
|
||||
------------------------------------
|
||||
327
zabbixinstall
Executable file
327
zabbixinstall
Executable file
@@ -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 <domain> -p <zabbixdbpassword>\n\n"
|
||||
else
|
||||
printf -- "NO LOCAL ROOT ACCESS — you must use -a and -m\n\n"
|
||||
printf -- "Usage:\n"
|
||||
printf -- " sudo ./zabbixinstall -n <domain> -p <zabbixdbpassword> -a <adminuser> -m <adminpwd>\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 <<EOF
|
||||
CREATE DATABASE IF NOT EXISTS zabbix CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
|
||||
CREATE USER IF NOT EXISTS 'zabbix'@'localhost' IDENTIFIED BY '${dbpass//\'/\'\\\'\'}';
|
||||
GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost';
|
||||
SET GLOBAL log_bin_trust_function_creators = 1;
|
||||
FLUSH PRIVILEGES;
|
||||
EOF
|
||||
;;
|
||||
admin)
|
||||
mysql -u "${db_admin_user}" -p"${db_admin_pwd}" <<EOF
|
||||
CREATE DATABASE IF NOT EXISTS zabbix CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
|
||||
CREATE USER IF NOT EXISTS 'zabbix'@'localhost' IDENTIFIED BY '${dbpass//\'/\'\\\'\'}';
|
||||
GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost';
|
||||
SET GLOBAL log_bin_trust_function_creators = 1;
|
||||
FLUSH PRIVILEGES;
|
||||
EOF
|
||||
;;
|
||||
esac
|
||||
|
||||
#
|
||||
# Import schema
|
||||
#
|
||||
schema="/usr/share/zabbix-sql-scripts/mysql/server.sql.gz"
|
||||
if [[ -f "$schema" ]]; then
|
||||
zcat "$schema" | mysql --default-character-set=utf8mb4 -uzabbix -p"$dbpass" zabbix
|
||||
else
|
||||
echo "" ; echo "Error! Could not find Zabbix schema file at $schema" ; echo ""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#
|
||||
# Disable trust
|
||||
#
|
||||
case "$dbmethod" in
|
||||
socket)
|
||||
mysql -u root <<EOF
|
||||
SET GLOBAL log_bin_trust_function_creators = 0;
|
||||
FLUSH PRIVILEGES;
|
||||
EOF
|
||||
;;
|
||||
admin)
|
||||
mysql -u "${db_admin_user}" -p"${db_admin_pwd}" <<EOF
|
||||
SET GLOBAL log_bin_trust_function_creators = 0;
|
||||
FLUSH PRIVILEGES;
|
||||
EOF
|
||||
;;
|
||||
esac
|
||||
|
||||
#
|
||||
# Configure Nginx + Zabbix
|
||||
#
|
||||
cp "$nginxsnippets/hostfiles/zabbix.80.conf" /etc/nginx/conf.d/"$hostname".conf
|
||||
sed -i "s/^# DBPassword=.*/DBPassword=$dbpass/" /etc/zabbix/zabbix_server.conf
|
||||
sed -i -- "s/DOMAIN/$hostname/g" /etc/nginx/conf.d/"$hostname".conf
|
||||
rm -f /etc/nginx/conf.d/zabbix.conf
|
||||
|
||||
#
|
||||
# Adjust DB_HOST depending on Database auth type
|
||||
#
|
||||
if [[ "$socketauth" == "no" ]]; then
|
||||
sed -i "s/^# DBHost=.*/DBHost=127.0.0.1/" /etc/zabbix/zabbix_server.conf
|
||||
sed -i "s/^DBHost=.*/DBHost=127.0.0.1/" /etc/zabbix/zabbix_server.conf
|
||||
fi
|
||||
|
||||
#
|
||||
# Enable + restart services
|
||||
#
|
||||
systemctl enable zabbix-server zabbix-agent
|
||||
systemctl restart zabbix-server zabbix-agent
|
||||
systemctl restart "$phpfpm"
|
||||
systemctl restart nginx
|
||||
|
||||
#
|
||||
# Web installer URL
|
||||
#
|
||||
zabbix_url="http://${hostname}/"
|
||||
|
||||
#
|
||||
# Post-install notice
|
||||
#
|
||||
if [[ "$socketauth" == "no" ]]; then
|
||||
|
||||
zabbixnotice=$(cat <<EOF
|
||||
---------------------------------------------------------------------------------------------------
|
||||
IMPORTANT (NO LOCAL ROOT DB ACCESS DETECTED):
|
||||
|
||||
Access the Zabbix web installer at:
|
||||
|
||||
$zabbix_url
|
||||
|
||||
Database is using password authentication mode.
|
||||
|
||||
When using the Zabbix Web installer you MUST enter:
|
||||
|
||||
Database host: 127.0.0.1
|
||||
Database user: zabbix
|
||||
Database password: $dbpass
|
||||
|
||||
DEFAULT LOGIN:
|
||||
User: Admin
|
||||
Password: zabbix
|
||||
---------------------------------------------------------------------------------------------------
|
||||
EOF
|
||||
)
|
||||
|
||||
else
|
||||
|
||||
zabbixnotice=$(cat <<EOF
|
||||
---------------------------------------------------------------------------------------------------
|
||||
Zabbix installation completed successfully.
|
||||
|
||||
Access the Zabbix web installer at:
|
||||
|
||||
$zabbix_url
|
||||
|
||||
Local root database access detected (socket/auth_socket) — the Zabbix frontend installer
|
||||
will work with the default settings:
|
||||
|
||||
Database host: localhost
|
||||
Database user: zabbix
|
||||
Database password: $dbpass
|
||||
|
||||
DEFAULT LOGIN:
|
||||
User: Admin
|
||||
Password: zabbix
|
||||
---------------------------------------------------------------------------------------------------
|
||||
EOF
|
||||
)
|
||||
|
||||
fi
|
||||
|
||||
clear ; printf '%s\n' "$zabbixnotice"
|
||||
|
||||
rm -f "$tmpfile"
|
||||
|
||||
#
|
||||
# All done
|
||||
#
|
||||
printf "\nAll Done...\n"
|
||||
|
||||
#
|
||||
# End of script
|
||||
#
|
||||
Reference in New Issue
Block a user