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 fi
# #
# Define variables and functions # Variables
# #
ubuntuversion="24.04" ubuntuversion="24.04"
zabbix_version="7.0" # Pinned LTS version (prevents 8.0 404 error) zabbix_version="7.0"
# #
# Function usage # Function: usage
# #
usage() { usage() {
printf -- "\nzabbixinstall (Ubuntu 24.04 + Zabbix 7.0 LTS)\n\n" printf -- "\nzabbixinstall (Ubuntu 24.04 + Zabbix 7.0 LTS)\n\n"
if [[ "$socketauth" == "yes" ]]; then if [[ "$socketauth" == "yes" ]]; then
printf -- "SOCKET DETECTED — no need for -a or -m\n\n" 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 -- "Usage:\n"
printf -- " sudo ./zabbixinstall -n <domain> -p <zabbix db password>\n\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 else
printf -- "NO SOCKET DETECTED — you must use -a and -m\n\n" 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 -- "Usage:\n"
printf -- " sudo ./zabbixinstall -n <domain> -p <zabbix db password> -a <adminuser> -m <adminpwd>\n\n" printf -- " sudo ./zabbixinstall -n <domain> -p <zabbix db password> -m <adminpwd> [-a <adminuser>]\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"
fi fi
printf -- "Options:\n" printf -- "Options:\n -h | -help | --help Show this help screen\n\n"
printf -- " -h | -help | --help Show this help screen\n\n"
} }
# #
@@ -72,9 +64,6 @@ usage() {
# #
clear clear
#
# Configure command line options
#
if [[ "$1" == "-help" || "$1" == "--help" ]]; then usage ; exit 0 ; fi if [[ "$1" == "-help" || "$1" == "--help" ]]; then usage ; exit 0 ; fi
if [[ $# -eq 0 || ! $1 =~ ^- ]]; then usage ; exit 1 ; fi if [[ $# -eq 0 || ! $1 =~ ^- ]]; then usage ; exit 1 ; fi
@@ -91,7 +80,7 @@ while getopts ":n:p:m:a:h" option; do
done done
# #
# Parse and validate input # Validate input
# #
if [[ -z "$hostname" || -z "$dbpass" ]]; then if [[ -z "$hostname" || -z "$dbpass" ]]; then
usage usage
@@ -99,47 +88,37 @@ if [[ -z "$hostname" || -z "$dbpass" ]]; then
exit 1 exit 1
fi fi
# Convert to lowercase (domains are case-insensitive)
hostname=$(echo "$hostname" | tr '[:upper:]' '[:lower:]') hostname=$(echo "$hostname" | tr '[:upper:]' '[:lower:]')
# Disallow leading hyphen
if [[ "$hostname" =~ ^- ]]; then if [[ "$hostname" =~ ^- ]]; then
printf "\nERROR: Domain cannot start with a hyphen.\n" printf "\nERROR: Domain cannot start with a hyphen.\n\n"
printf "Example of valid input: zabbix.example.com\n\n"
exit 1 exit 1
fi fi
# Disallow spaces, slashes, underscores
if [[ "$hostname" =~ [[:space:]/_] ]]; then if [[ "$hostname" =~ [[:space:]/_] ]]; then
printf "\nERROR: Domain cannot contain spaces, slashes, or underscores.\n\n" printf "\nERROR: Domain cannot contain spaces, slashes, or underscores.\n\n"
exit 1 exit 1
fi fi
# Validate domain format (RFC 1123)
if [[ ! "$hostname" =~ ^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$ ]]; then if [[ ! "$hostname" =~ ^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$ ]]; then
printf "\nERROR: Invalid domain format.\n" printf "\nERROR: Invalid domain format.\n\n"
printf "Example of valid input: zabbix.example.com\n\n"
exit 1 exit 1
fi fi
# Check for spaces in DB credentials
if [[ "$dbpass" =~ [[:space:]] ]]; then if [[ "$dbpass" =~ [[:space:]] ]]; then
printf "\nERROR: Database password cannot contain spaces.\n\n" printf "\nERROR: Database password cannot contain spaces.\n\n"
exit 1 exit 1
fi fi
#
# Print Zabbix version info
#
printf "Using Zabbix LTS version: %s\n\n" "$zabbix_version" 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 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" 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" 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 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 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" nginxsnippets="/etc/nginx/nginx-snippets"
repo="https://git.x-files.dk/webserver/nginx-snippets.git" 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 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}" mariadbadmin="${mariadbadmin:-root}"
printf "\nChecking MariaDB access method...\n" printf "\nChecking MariaDB access method...\n"
if [[ "$socketauth" == "yes" ]]; then if [[ "$socketauth" == "yes" ]]; then
dbmethod="socket" dbmethod="socket"
printf "Socket authentication detected (root)\n" printf "Socket authentication detected (root)\n"
elif [[ -n "$mariadbpwd" && -n "$mariadbadmin" ]]; then else
dbmethod="admin" dbmethod="admin"
printf "Using admin user authentication (%s)\n" "$mariadbadmin" 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 fi
# #
# Create Zabbix database # Create Zabbix DB
# #
case "$dbmethod" in case "$dbmethod" in
socket) socket)
@@ -204,7 +178,7 @@ EOF
esac esac
# #
# Import Zabbix database schema # Import schema
# #
schema="/usr/share/zabbix-sql-scripts/mysql/server.sql.gz" schema="/usr/share/zabbix-sql-scripts/mysql/server.sql.gz"
if [[ -f "$schema" ]]; then if [[ -f "$schema" ]]; then
@@ -233,7 +207,7 @@ EOF
esac esac
# #
# Configure Nginx and Zabbix # Configure Nginx + Zabbix
# #
cp "$nginxsnippets/hostfiles/zabbix.80.conf" /etc/nginx/conf.d/"$hostname".conf 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/^# 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 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 enable zabbix-server zabbix-agent
systemctl restart zabbix-server zabbix-agent systemctl restart zabbix-server zabbix-agent
@@ -249,38 +231,56 @@ systemctl restart "$phpfpm"
systemctl restart nginx 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 is running in PASSWORD authentication mode.
DATABASE PASSWORD = $dbpass
SETTINGS ------------------------------------------------------------------------------------------ When using the Zabbix WEB INSTALLER you MUST enter:
ZABBIX SERVER NAME = Your Sitename
LOGIN --------------------------------------------------------------------------------------------- Database host: 127.0.0.1
DEFAULT USER = Admin
DEFAULT PASSWORD = zabbix If you enter "localhost", Zabbix will attempt UNIX socket authentication and FAIL.
Database password: $dbpass
DEFAULT LOGIN:
User: Admin
Password: zabbix
--------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------
EOF EOF
) )
# else
# Display post install note
# 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" clear ; printf '%s\n' "$zabbixnotice"
#
# Cleaning up
#
rm -f "$tmpfile" rm -f "$tmpfile"
#
# All done
#
printf "\nAll Done...\n\n" printf "\nAll Done...\n\n"
# #