bug fix for no socket auth

This commit is contained in:
2025-11-23 15:17:33 +00:00
parent 510f258cee
commit 24e2cbe0d7

View File

@@ -35,36 +35,28 @@ else
fi
#
# Define variables and functions
# Variables
#
ubuntuversion="24.04"
zabbix_version="7.0" # Pinned LTS version (prevents 8.0 404 error)
zabbix_version="7.0"
#
# Function usage
# Function: usage
#
usage() {
printf -- "\nzabbixinstall (Ubuntu 24.04 + Zabbix 7.0 LTS)\n\n"
if [[ "$socketauth" == "yes" ]]; then
printf -- "SOCKET DETECTED — no need for -a or -m\n\n"
printf -- "Installs Zabbix Server using MariaDB socket authentication.\n\n"
printf -- "Usage:\n"
printf -- " sudo ./zabbixinstall -n <domain> -p <zabbix db password>\n\n"
printf -- "Example:\n"
printf -- " sudo ./zabbixinstall -n zabbix.something.xyz -p zabbixdbpwd\n\n"
else
printf -- "NO SOCKET DETECTED — you must use -a and -m\n\n"
printf -- "Installs Zabbix Server using MariaDB admin credentials.\n\n"
printf -- "Usage:\n"
printf -- " sudo ./zabbixinstall -n <domain> -p <zabbix db password> -a <adminuser> -m <adminpwd>\n\n"
printf -- "Examples:\n"
printf -- " sudo ./zabbixinstall -n zabbix.something.xyz -p zabbixdbpwd -a root -m rootpwd\n"
printf -- " sudo ./zabbixinstall -n zabbix.something.xyz -p zabbixdbpwd -a admin -m adminpwd\n\n"
printf -- " sudo ./zabbixinstall -n <domain> -p <zabbix db password> -m <adminpwd> [-a <adminuser>]\n\n"
fi
printf -- "Options:\n"
printf -- " -h | -help | --help Show this help screen\n\n"
printf -- "Options:\n -h | -help | --help Show this help screen\n\n"
}
#
@@ -72,9 +64,6 @@ usage() {
#
clear
#
# Configure command line options
#
if [[ "$1" == "-help" || "$1" == "--help" ]]; then usage ; exit 0 ; fi
if [[ $# -eq 0 || ! $1 =~ ^- ]]; then usage ; exit 1 ; fi
@@ -91,7 +80,7 @@ while getopts ":n:p:m:a:h" option; do
done
#
# Parse and validate input
# Validate input
#
if [[ -z "$hostname" || -z "$dbpass" ]]; then
usage
@@ -99,47 +88,37 @@ if [[ -z "$hostname" || -z "$dbpass" ]]; then
exit 1
fi
# Convert to lowercase (domains are case-insensitive)
hostname=$(echo "$hostname" | tr '[:upper:]' '[:lower:]')
# Disallow leading hyphen
if [[ "$hostname" =~ ^- ]]; then
printf "\nERROR: Domain cannot start with a hyphen.\n"
printf "Example of valid input: zabbix.example.com\n\n"
printf "\nERROR: Domain cannot start with a hyphen.\n\n"
exit 1
fi
# Disallow spaces, slashes, underscores
if [[ "$hostname" =~ [[:space:]/_] ]]; then
printf "\nERROR: Domain cannot contain spaces, slashes, or underscores.\n\n"
exit 1
fi
# Validate domain format (RFC 1123)
if [[ ! "$hostname" =~ ^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$ ]]; then
printf "\nERROR: Invalid domain format.\n"
printf "Example of valid input: zabbix.example.com\n\n"
printf "\nERROR: Invalid domain format.\n\n"
exit 1
fi
# Check for spaces in DB credentials
if [[ "$dbpass" =~ [[:space:]] ]]; then
printf "\nERROR: Database password cannot contain spaces.\n\n"
exit 1
fi
#
# Print Zabbix version info
#
printf "Using Zabbix LTS version: %s\n\n" "$zabbix_version"
#
# Ensure curl and wget are installed
# Install prerequisites
#
for tool in curl wget; do dpkg -s "$tool" &>/dev/null || apt install -y -qq "$tool" ; done
#
# Download and install the Zabbix repository
# 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"
@@ -149,38 +128,33 @@ dpkg -i "$tmpfile"
apt update
#
# Install Zabbix components
# Install Zabbix packages
#
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
# 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
#
# Determine MariaDB login method
# MariaDB access 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
else
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
# Create Zabbix DB
#
case "$dbmethod" in
socket)
@@ -204,7 +178,7 @@ EOF
esac
#
# Import Zabbix database schema
# Import schema
#
schema="/usr/share/zabbix-sql-scripts/mysql/server.sql.gz"
if [[ -f "$schema" ]]; then
@@ -233,7 +207,7 @@ EOF
esac
#
# Configure Nginx and Zabbix
# 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
@@ -241,7 +215,15 @@ sed -i -- "s/DOMAIN/$hostname/g" /etc/nginx/conf.d/"$hostname".conf
rm -f /etc/nginx/conf.d/zabbix.conf
#
# Enable and start Zabbix
# 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
@@ -249,38 +231,56 @@ systemctl restart "$phpfpm"
systemctl restart nginx
#
# Zabbix postinstall notice
# Post-install notic
#
zabbixnotice=$(cat <<EOF
if [[ "$socketauth" == "no" ]]; then
zabbixnotice=$(cat <<EOF
---------------------------------------------------------------------------------------------------
IMPORTANT: Go to http://$hostname and modify the following settings:
IMPORTANT (NO SOCKET AUTH DETECTED):
DATABASE SETTINGS ---------------------------------------------------------------------------------
DATABASE PASSWORD = $dbpass
Database is running in PASSWORD authentication mode.
SETTINGS ------------------------------------------------------------------------------------------
ZABBIX SERVER NAME = Your Sitename
When using the Zabbix WEB INSTALLER you MUST enter:
LOGIN ---------------------------------------------------------------------------------------------
DEFAULT USER = Admin
DEFAULT PASSWORD = zabbix
Database host: 127.0.0.1
If you enter "localhost", Zabbix will attempt UNIX socket authentication and FAIL.
Database password: $dbpass
DEFAULT LOGIN:
User: Admin
Password: zabbix
---------------------------------------------------------------------------------------------------
EOF
)
#
# Display post install note
#
else
zabbixnotice=$(cat <<EOF
---------------------------------------------------------------------------------------------------
Zabbix installation completed successfully.
Database socket authentication detected — the Zabbix frontend installer
will work with the default settings:
Database host: localhost
Database user: zabbix
DEFAULT LOGIN:
User: Admin
Password: zabbix
---------------------------------------------------------------------------------------------------
EOF
)
fi
clear ; printf '%s\n' "$zabbixnotice"
#
# Cleaning up
#
rm -f "$tmpfile"
#
# All done
#
printf "\nAll Done...\n\n"
#