Initial commit: Zabbix producao com mariadb

This commit is contained in:
lmelo
2026-05-24 14:39:04 +00:00
commit 6cdd89371d
3 changed files with 170 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
# Secrets
env/
.credentials
# Data
data/
backups/
# OS/Logs
*.log
.DS_Store
+69
View File
@@ -0,0 +1,69 @@
services:
mariadb:
image: mariadb:10.11
container_name: zabbix-db
restart: unless-stopped
env_file: ./env/.env_db
volumes:
- ./data/db:/var/lib/mysql
- ./backups:/backups
command:
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_bin
- --log_bin_trust_function_creators=1
- --innodb_buffer_pool_size=512M
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
interval: 10s
timeout: 5s
retries: 12
start_period: 60s
deploy:
resources:
limits:
memory: 1G
zabbix-server:
image: zabbix/zabbix-server-mysql:alpine-7.4-latest
container_name: zabbix-server
restart: unless-stopped
depends_on:
mariadb:
condition: service_healthy
env_file: ./env/.env_server
ports:
- "10051:10051"
volumes:
- ./data/zabbix_server:/var/lib/zabbix
- /etc/localtime:/etc/localtime:ro
healthcheck:
test: ["CMD", "zabbix_server", "--runtime-control", "ping"]
interval: 30s
timeout: 10s
retries: 3
deploy:
resources:
limits:
memory: 512M
zabbix-web:
image: zabbix/zabbix-web-nginx-mysql:alpine-7.4-latest
container_name: zabbix-web
restart: unless-stopped
depends_on:
- mariadb
- zabbix-server
env_file: ./env/.env_web
ports:
- "0.0.0.0:8080:8080"
volumes:
- /etc/localtime:/etc/localtime:ro
deploy:
resources:
limits:
memory: 256M
networks:
default:
name: zabbix-net
driver: bridge
Executable
+90
View File
@@ -0,0 +1,90 @@
#!/bin/bash
set -e
# Detetar Docker Compose
if command -v docker &>/dev/null && docker compose version &>/dev/null 2>&1; then
COMPOSE_CMD="docker compose"
elif command -v docker-compose &>/dev/null; then
COMPOSE_CMD="docker-compose"
else
echo "❌ Docker Compose not found!"
exit 1
fi
ENV_DIR="./env"
CRED_FILE="./.credentials"
# Se já existe configuração, apenas inicia
if [[ -f "$ENV_DIR/.env_db" ]]; then
echo "[️] Configuration already exists. Starting services..."
$COMPOSE_CMD up -d
echo "✅ Running. Access: http://<IP>:8080 | Admin / zabbix"
exit 0
fi
echo "[+] Generating secure DB passwords..."
DB_ROOT_PASS=$(openssl rand -hex 16)
DB_ZABBIX_PASS=$(openssl rand -hex 16)
echo "[+] Creating directories..."
mkdir -p "$ENV_DIR" ./data/db ./data/zabbix_server ./backups
echo "[+] Writing environment files..."
cat <<EOF > "$ENV_DIR/.env_db"
MYSQL_ROOT_PASSWORD=${DB_ROOT_PASS}
MYSQL_DATABASE=zabbix
MYSQL_USER=zabbix
MYSQL_PASSWORD=${DB_ZABBIX_PASS}
MYSQL_CHARSET=utf8mb4
MYSQL_COLLATION=utf8mb4_bin
EOF
cat <<EOF > "$ENV_DIR/.env_server"
DB_SERVER_HOST=mariadb
MYSQL_DATABASE=zabbix
MYSQL_USER=zabbix
MYSQL_PASSWORD=${DB_ZABBIX_PASS}
ZBX_STARTPOLLERS=10
ZBX_STARTTRAPPERS=5
ZBX_CACHESIZE=256M
ZBX_HISTORYCACHESIZE=4M
ZBX_VALUECACHESIZE=8M
ZBX_TIMEOUT=30
EOF
cat <<EOF > "$ENV_DIR/.env_web"
DB_SERVER_HOST=mariadb
MYSQL_DATABASE=zabbix
MYSQL_USER=zabbix
MYSQL_PASSWORD=${DB_ZABBIX_PASS}
PHP_TZ=Europe/Lisbon
ZBX_SERVER_HOST=zabbix-server
ZBX_SERVER_PORT=10051
PHP_MAX_EXECUTION_TIME=300
PHP_MEMORY_LIMIT=128M
EOF
chmod 600 "$ENV_DIR"/.env_*
cat <<EOF > "$CRED_FILE"
# Zabbix Credentials - $(date)
[Database]
DB_ROOT_PASS: ${DB_ROOT_PASS}
DB_ZABBIX_PASS: ${DB_ZABBIX_PASS}
[Web]
User: Admin
Pass: zabbix ⚠️ CHANGE ON FIRST LOGIN
EOF
chmod 600 "$CRED_FILE"
echo "[+] Starting Zabbix stack..."
$COMPOSE_CMD up -d
echo ""
echo "=========================================="
echo "✅ ZABBIX DEPLOYED"
echo "=========================================="
echo "🌐 Access: http://<SERVER_IP>:8080"
echo "👤 Admin / 🔑 zabbix"
echo "🔐 DB credentials: $CRED_FILE"
echo ""