You've already forked zabbix-ubuntu
initial 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.
|
||||
180
README.md
Normal file
180
README.md
Normal file
@@ -0,0 +1,180 @@
|
||||
# Zabbix for Ubuntu 24.04 Server
|
||||
[](#)
|
||||
[](#)
|
||||
[](#)
|
||||
[](#)
|
||||
[](#)
|
||||
[](#)
|
||||
[](./LICENSE)
|
||||
|
||||
Installs and configures the **latest available Zabbix LTS release** on Ubuntu 24.04 Server.
|
||||
|
||||
This is a **production-focused installer**, not a demo.
|
||||
|
||||
It assumes Nginx, PHP-FPM, and MariaDB are already installed and running.
|
||||
|
||||
---
|
||||
|
||||
## Related Installers
|
||||
|
||||
If you don’t have the required components, you can use these compatible installers:
|
||||
|
||||
- [Nginx + PHP-FPM Installer](https://git.x-files.dk/webserver/nginx-ubuntu)
|
||||
- [MariaDB Installer](https://git.x-files.dk/database/mariadb-ubuntu)
|
||||
|
||||
---
|
||||
|
||||
### Download the Script
|
||||
|
||||
Clone this repository to your server:
|
||||
|
||||
```
|
||||
git clone https://git.x-files.dk/network/zabbix-ubuntu.git
|
||||
```
|
||||
|
||||
```
|
||||
cd zabbix-ubuntu
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Usage
|
||||
|
||||
Run the script using:
|
||||
|
||||
```
|
||||
sudo ./zabbixinstall -n <domain> -p <zabbix db password> [options]
|
||||
```
|
||||
|
||||
### Examples
|
||||
|
||||
The installer automatically detects if socket authentication is active. Only include `-a` and `-m` if your MariaDB setup does **not** use socket authentication.
|
||||
|
||||
```
|
||||
sudo ./zabbixinstall -n zabbix.example.com -p zabbixdbpwd
|
||||
sudo ./zabbixinstall -n zabbix.example.com -p zabbixdbpwd -m rootpwd
|
||||
sudo ./zabbixinstall -n zabbix.example.com -p zabbixdbpwd -a admin -m adminpwd
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
| Flag | Description |
|
||||
|------|--------------|
|
||||
| `-p <password>` | Zabbix database user password |
|
||||
| `-a <username>` | Optional MariaDB admin username (defaults to `root` if not specified) |
|
||||
| `-m <password>` | MariaDB root or admin password — *required only if socket authentication is disabled* |
|
||||
| `-h`, `--help` | Show the help screen (reflects detected socket status) |
|
||||
|
||||
### Configuration
|
||||
|
||||
Once the installer completes, visit:
|
||||
|
||||
```
|
||||
http://<domain>
|
||||
```
|
||||
|
||||
And complete the setup.
|
||||
|
||||
---
|
||||
|
||||
### Features
|
||||
|
||||
- Installs and configures Zabbix LTS automatically
|
||||
- Creates the MariaDB database and user with the correct privileges
|
||||
- Enables and starts Zabbix server and agent services
|
||||
- Detects MariaDB socket or password authentication automatically
|
||||
- Generates an Nginx host configuration dynamically
|
||||
- Integrates cleanly with PHP-FPM and Nginx setups
|
||||
- Supports re-runs via `IF NOT EXISTS` logic for safe idempotency
|
||||
|
||||
---
|
||||
|
||||
### Configuration Details
|
||||
|
||||
#### File Locations
|
||||
|
||||
| File | Description |
|
||||
|------|--------------|
|
||||
| `/etc/zabbix/zabbix_server.conf` | Main Zabbix server configuration file |
|
||||
| `/usr/share/zabbix-sql-scripts/mysql/server.sql.gz` | Database schema file imported by installer |
|
||||
| `/etc/nginx/conf.d/<domain>.conf` | Generated Nginx host configuration file |
|
||||
| `/etc/nginx/nginx-snippets` | Shared include snippets and templates |
|
||||
|
||||
---
|
||||
|
||||
#### Behavior
|
||||
|
||||
- The installer checks if **MariaDB socket authentication** is active.
|
||||
If available, it connects locally as `root` (no password).
|
||||
- If socket authentication is **not detected**, use `-a` and `-m` to supply credentials.
|
||||
- Automatically sets and resets `log_bin_trust_function_creators` during import.
|
||||
- Nginx configuration is validated (`nginx -t`) before restarting.
|
||||
|
||||
---
|
||||
|
||||
### Nginx Integration
|
||||
|
||||
The generated Zabbix configuration file listens on port 80.
|
||||
To enable HTTPS (port 443), use the example provided [here](https://git.x-files.dk/webserver/nginx-snippets/src/branch/main/hostfiles/zabbix.443.conf).
|
||||
|
||||
> **NOTE**
|
||||
> The file also includes optional caching directives (commented out by default).
|
||||
> You can enable them to improve load times and performance if needed.
|
||||
> The lines you are looking for are at the bottom of the generated config file and look like this:
|
||||
> ```
|
||||
> ##### Cache js css static content and open files start #####################
|
||||
> # include /etc/nginx/nginx-snippets/cache-open-files.conf;
|
||||
> # include /etc/nginx/nginx-snippets/cache-statics.conf;
|
||||
> # include /etc/nginx/nginx-snippets/cache-js-css.conf;
|
||||
> ##### Cache js css static content and open files stop ######################
|
||||
|
||||
---
|
||||
|
||||
### Troubleshooting
|
||||
|
||||
**Nginx fails to restart**
|
||||
Run `nginx -t` and review any syntax errors reported in `/etc/nginx/conf.d/<domain>.conf`.
|
||||
|
||||
**Access denied during database creation**
|
||||
Your MariaDB setup likely does not use socket authentication.
|
||||
Re-run the installer with the `-m` flag (and optionally `-a`) to provide credentials.
|
||||
The installer will automatically re-detect your configuration.
|
||||
|
||||
**PHP version mismatch**
|
||||
The script automatically detects your installed PHP version,
|
||||
but ensure that the PHP-FPM service (e.g., `php8.3-fpm`) is active.
|
||||
|
||||
**Schema import fails**
|
||||
Verify that `/usr/share/zabbix-sql-scripts/mysql/server.sql.gz` exists.
|
||||
If missing, reinstall the `zabbix-sql-scripts` package.
|
||||
|
||||
---
|
||||
|
||||
### FAQ
|
||||
|
||||
**Q:** Why doesn’t the script ask for a MariaDB password by default?
|
||||
**A:** Ubuntu 24.04’s MariaDB defaults to *socket authentication*,
|
||||
allowing the local `root` user to connect without a password.
|
||||
The installer detects this automatically and skips password prompts when applicable.
|
||||
|
||||
**Q:** Can I run the installer multiple times?
|
||||
**A:** Yes. Database and user creation use `IF NOT EXISTS`, making re-runs safe.
|
||||
Existing Nginx configuration files are replaced, but no data is deleted.
|
||||
|
||||
**Q:** Does this modify existing Nginx settings?
|
||||
**A:** No. It adds a standalone host file in `/etc/nginx/conf.d/`
|
||||
and validates configuration changes before applying them.
|
||||
|
||||
---
|
||||
|
||||
### 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).
|
||||
|
||||
---
|
||||
248
zabbixinstall
Executable file
248
zabbixinstall
Executable file
@@ -0,0 +1,248 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Author : Allan Christensen
|
||||
# First Created : 11012021 (DD-MM-YYYY)
|
||||
# Description : Installs Zabbix on Ubuntu 24.04
|
||||
# License : MIT License (see LICENSE file for details)
|
||||
|
||||
#
|
||||
# Are we root
|
||||
#
|
||||
if [[ $(id -u) -ne 0 ]]; then echo "" && echo "Must be root or use sudo" && echo "" ; exit 1 ; fi
|
||||
|
||||
#
|
||||
# Define variables and functions
|
||||
#
|
||||
phpver=$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;' 2>/dev/null || echo "8.3") ; phpfpm="php$phpver-fpm"
|
||||
ubuntuversion="24.04"
|
||||
fallbackversion="7.0"
|
||||
|
||||
#
|
||||
# Function usage
|
||||
#
|
||||
usage () {
|
||||
printf -- "\nzabbixinstall (Ubuntu 24.04 + Zabbix 7.0 LTS)\n\n"
|
||||
printf -- "%s\n\n" "$socket"
|
||||
printf -- "Usage:\n"
|
||||
printf -- "sudo ./zabbixinstall -n <domain> -p <zabbix db password> [options]\n\n"
|
||||
printf -- "Options:\n"
|
||||
printf -- " -a <mariadb admin user> Optional admin username $socketusage\n"
|
||||
printf -- " -m <mariadb admin password> Optional admin password $socketusage\n"
|
||||
printf -- " -h | -help | --help Show this help screen\n\n"
|
||||
printf -- "Examples:\n"
|
||||
printf -- " sudo ./zabbixinstall -n zabbix.something.xyz -p zabbixdbpwd\n"
|
||||
printf -- " sudo ./zabbixinstall -n zabbix.something.xyz -p zabbixdbpwd -a admin -m adminpwd\n\n"
|
||||
}
|
||||
|
||||
#
|
||||
# Function to check if a service is already running or not
|
||||
#
|
||||
serviceno () { printf "\n%s" "$service" ; printf " is not running cannot continue...\n\n"; }
|
||||
servicedead () { status=$(systemctl is-active "$service"); if [[ "$status" != "active" ]]; then serviceno ; exit 1 ; fi; }
|
||||
|
||||
#
|
||||
# Function inputcheck
|
||||
#
|
||||
inputcheck () {
|
||||
[[ -z "$hostname" ]] && { usage; echo ""; echo "Error! Hostname empty."; echo ""; exit 1; }
|
||||
[[ -z "$dbpass" ]] && { usage; echo ""; echo "Error! Database password empty."; echo ""; exit 1; }
|
||||
}
|
||||
|
||||
#
|
||||
# If Nginx and MariaDB is not running then die
|
||||
#
|
||||
service="mariadb" ; servicedead ; service="nginx" ; servicedead
|
||||
|
||||
#
|
||||
# Check MariaDB authentication method (socket or not)
|
||||
#
|
||||
if mysql -u root -e ";" 2>/dev/null; then
|
||||
socket="SOCKET DETECTED — no need for -a or -m"
|
||||
socketusage="SOCKET DETECTED — this flag is not needed"
|
||||
socketauth="yes"
|
||||
else
|
||||
socket="NO SOCKET DETECTED — you must use -a and -m"
|
||||
socketusage="NO SOCKET DETECTED — these flags are required"
|
||||
socketauth="no"
|
||||
fi
|
||||
|
||||
#
|
||||
# Let's go
|
||||
#
|
||||
clear
|
||||
|
||||
#
|
||||
# Try to determine the latest Zabbix version
|
||||
#
|
||||
zabbix_version=$(curl -s https://repo.zabbix.com/zabbix/ | grep -oP '(?<=href=")[0-9]+\.[0]' | sort -V | tail -1)
|
||||
|
||||
# Use fallback version if fetch failed
|
||||
if [[ -z "$zabbix_version" ]]; then printf "Could not determine latest Zabbix version. Falling back to version %s\n\n" "$fallbackversion" ; zabbix_version="$fallbackversion" ; fi
|
||||
|
||||
printf "Using Zabbix version: %s\n\n" "$zabbix_version"
|
||||
|
||||
#
|
||||
# Configure command line options
|
||||
#
|
||||
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) mariadbpwd="$OPTARG";;
|
||||
a) mariadbadmin="$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
|
||||
inputcheck "$hostname" "$dbpass"
|
||||
|
||||
#
|
||||
# Download and install the Zabbix repository
|
||||
#
|
||||
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 components
|
||||
#
|
||||
apt install -y zabbix-server-mysql zabbix-frontend-php zabbix-nginx-conf zabbix-sql-scripts zabbix-agent fping
|
||||
|
||||
#
|
||||
# Clone nginx-snippets; if nginx-snippets exists then just pull latest changes
|
||||
#
|
||||
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
|
||||
|
||||
#
|
||||
# Determine MariaDB login method
|
||||
#
|
||||
mariadbadmin="${mariadbadmin:-root}"
|
||||
|
||||
printf "\nChecking MariaDB access method...\n"
|
||||
|
||||
if [[ "$socketauth" == "yes" ]]; then
|
||||
dbmethod="socket"
|
||||
printf "Socket authentication detected (root)\n"
|
||||
elif [[ -n "$mariadbpwd" && -n "$mariadbadmin" ]]; then
|
||||
dbmethod="admin"
|
||||
printf "Using admin user authentication (%s)\n" "$mariadbadmin"
|
||||
else
|
||||
printf "\nERROR: No valid MariaDB authentication method found.\n"
|
||||
printf "Tried socket, admin user, and root password.\n\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#
|
||||
# Create Zabbix database
|
||||
#
|
||||
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 "${mariadbadmin}" -p"${mariadbpwd}" <<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 Zabbix database 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 "${mariadbadmin}" -p"${mariadbpwd}" <<EOF
|
||||
SET GLOBAL log_bin_trust_function_creators = 0;
|
||||
FLUSH PRIVILEGES;
|
||||
EOF
|
||||
;;
|
||||
esac
|
||||
|
||||
#
|
||||
# Configure Nginx and 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/" /etc/nginx/conf.d/"$hostname".conf
|
||||
rm -f /etc/nginx/conf.d/zabbix.conf
|
||||
|
||||
#
|
||||
# Enable and start Zabbix
|
||||
#
|
||||
systemctl enable zabbix-server zabbix-agent
|
||||
systemctl restart zabbix-server zabbix-agent
|
||||
systemctl restart "$phpfpm" && systemctl restart nginx
|
||||
|
||||
#
|
||||
# Zabbix postinstall notice
|
||||
#
|
||||
zabbixnotice=$(cat <<EOF
|
||||
---------------------------------------------------------------------------------------------------
|
||||
IMPORTANT: Go to http://$hostname and modify the following settings:
|
||||
|
||||
DATABASE SETTINGS ---------------------------------------------------------------------------------
|
||||
DATABASE PASSWORD = $dbpass
|
||||
|
||||
SETTINGS ------------------------------------------------------------------------------------------
|
||||
ZABBIX SERVER NAME = Your Sitename
|
||||
|
||||
LOGIN ---------------------------------------------------------------------------------------------
|
||||
DEFAULT USER = Admin
|
||||
DEFAULT PASSWORD = zabbix
|
||||
---------------------------------------------------------------------------------------------------
|
||||
EOF
|
||||
)
|
||||
|
||||
#
|
||||
# Display post install note
|
||||
#
|
||||
printf '%s\n' "$zabbixnotice"
|
||||
|
||||
#
|
||||
# Cleaning up
|
||||
#
|
||||
rm -f "$tmpfile"
|
||||
|
||||
#
|
||||
# All done
|
||||
#
|
||||
printf "\nAll Done...\n\n"
|
||||
|
||||
#
|
||||
# End of script
|
||||
Reference in New Issue
Block a user