From 3ccc4abcd18484a503d63538d28afcbc5ba2eacc Mon Sep 17 00:00:00 2001 From: allan Date: Sun, 23 Nov 2025 16:34:38 +0000 Subject: [PATCH] minor changes due to socket auth --- README.md | 139 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 72 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index e161c03..7e6d2aa 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,8 @@ [![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)](#) -[![DB](https://img.shields.io/badge/server-mariadb-003545)](#) +[![MariaDB](https://img.shields.io/badge/db-mariadb-003545)](#) +[![MySQL](https://img.shields.io/badge/db-mysql-4479A1)](#) [![App](https://img.shields.io/badge/app-zabbix-DC382D)](#) [![License](https://img.shields.io/badge/License-MIT-green)](./LICENSE) @@ -11,7 +12,9 @@ Installs and configures the **latest available Zabbix LTS release** on Ubuntu 24 This is a **production-focused installer**, not a demo. -It assumes Nginx, PHP-FPM, and MariaDB are already installed and running. +It assumes Nginx, PHP-FPM, and either **MariaDB or MySQL** are already installed and running. + +This script works with both MariaDB and MySQL, with or without **socket authentication**. --- @@ -24,7 +27,7 @@ If you don’t have the required components, you can use these compatible instal --- -### Download the Script +## Download the Script Clone this repository to your server: @@ -38,111 +41,114 @@ cd zabbix-ubuntu --- -### Usage +## Usage -Run the script using: +Run the installer using: ``` -sudo ./zabbixinstall -n -p [options] +sudo ./zabbixinstall -n -p [ -a ] [ -m ] ``` -### Examples +--- -The installer automatically detects if socket authentication is active. Only include `-a` and `-m` if your MariaDB setup does **not** use socket authentication. +## Examples + +The installer automatically detects whether socket authentication is active. ``` +# Socket authentication enabled: sudo ./zabbixinstall -n zabbix.example.com -p zabbixdbpwd + +# Socket authentication disabled (root password): sudo ./zabbixinstall -n zabbix.example.com -p zabbixdbpwd -m rootpwd + +# Socket authentication disabled (admin user): sudo ./zabbixinstall -n zabbix.example.com -p zabbixdbpwd -a admin -m adminpwd ``` -### Options +--- + +## Options | Flag | Description | -|------|--------------| +|------|-------------| | `-p ` | Zabbix database user password | -| `-a ` | Optional MariaDB admin username (defaults to `root` if not specified) | -| `-m ` | 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:// -``` - -And complete the setup. +| `-a ` | Optional database admin username (defaults to `root`) | +| `-m ` | Database root or admin password — *required only if socket authentication is disabled* | +| `-h`, `--help` | Show help screen (reflects detected socket status) | --- -### Features +## 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 +- Works with both MariaDB and MySQL +- Supports socket and password-based authentication +- Creates database and user with correct privileges +- Imports Zabbix schema automatically +- Generates Nginx host configuration dynamically +- Integrates cleanly with PHP-FPM +- Enables and starts Zabbix services +- Safe to re-run due to `IF NOT EXISTS` logic --- -### Configuration Details +## Configuration Details -#### File Locations +### 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/.conf` | Generated Nginx host configuration file | +|------|-------------| +| `/etc/zabbix/zabbix_server.conf` | Main Zabbix server configuration | +| `/usr/share/zabbix-sql-scripts/mysql/server.sql.gz` | Database schema imported by installer | +| `/etc/nginx/conf.d/.conf` | Generated Nginx virtual host | | `/etc/nginx/nginx-snippets` | Shared include snippets and templates | --- -#### Behavior +## 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. +- The installer automatically detects whether **socket authentication** is active. + If active, it connects as `root` without requiring a password. +- If socket authentication is **not** detected, you must supply database admin credentials using `-m` (and optionally `-a`). +- This applies **equally to both MariaDB and MySQL** — the authentication logic is identical. +- Automatically sets and resets `log_bin_trust_function_creators` during schema import. +- Validates Nginx configuration (`nginx -t`) before restarting. --- -### Nginx Integration +## 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). +The generated Zabbix config file listens on port 80. +To enable HTTPS (port 443), use the example provided: + +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: +> The generated config includes optional caching directives (commented out). +> You may enable them for improved performance. +> Look for: > ``` > ##### 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 +## Troubleshooting **Nginx fails to restart** -Run `nginx -t` and review any syntax errors reported in `/etc/nginx/conf.d/.conf`. +Run `nginx -t` and check any errors in `/etc/nginx/conf.d/.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. +Your database (MariaDB or MySQL) is likely **not** using socket authentication. +Re-run with the `-m` flag and optional `-a` to supply credentials. **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. +Ensure your PHP-FPM service (`php8.3-fpm`, etc.) is running. **Schema import fails** Verify that `/usr/share/zabbix-sql-scripts/mysql/server.sql.gz` exists. @@ -150,26 +156,25 @@ If missing, reinstall the `zabbix-sql-scripts` package. --- -### FAQ +## 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:** Why doesn’t the installer ask for a database password by default? +**A:** Ubuntu uses socket authentication for MariaDB and MySQL, allowing `root` to connect without a password. +The installer detects this automatically. -**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:** Can I safely re-run the installer? +**A:** Yes. Database and user creation use `IF NOT EXISTS`. +Existing Nginx configuration is overwritten, but no data is removed. -**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. +**Q:** Does the installer modify existing Nginx settings? +**A:** No. It adds a standalone file in `/etc/nginx/conf.d/` and validates the config before applying changes. --- ### More Information -More guides and documentation can be found on [wiki.x-files.dk](https://wiki.x-files.dk) +More guides and documentation can be found on +[wiki.x-files.dk](https://wiki.x-files.dk) ---