Zabbix Server Administration and Database Management Operations

System Resource Monitoring

Disk Usage Evaluation

Check the available storage on the root partition:

df -Th | grep '^/dev'

Memory Consumption Analysis

Display physical and swap memory utilization:

free --human

Processor Load Inspection

Monitor real-time CPU usage and running processes:

top -b -n 1 | head -n 5

Zabbix Database Volume Assessment

Connect to the database engine and execute the following query to determine storage allocation:

SELECT
    table_schema AS 'Database',
    SUM(table_rows) AS 'Total Rows',
    ROUND(SUM(data_length / 1024 / 1024), 2) AS 'Data Size (MB)',
    ROUND(SUM(index_length / 1024 / 1024), 2) AS 'Index Size (MB)' 
FROM information_schema.tables 
WHERE table_schema = 'zabbix_db';

Table Size Inspection and Cleanup

Identify the largest tables within the Zabbix schema to evaluate potential pruning:

USE zabbix_db;
SELECT
    table_name AS 'Table',
    ROUND(((data_length + index_length) / 1024 / 1024), 2) AS 'Total Size (MB)' 
FROM information_schema.TABLES 
WHERE table_schema = 'zabbix_db' 
ORDER BY Total_Size DESC;

Automated Database Backup Strategy

Create a dedicated directory and script for scheduled dumps:

mkdir -p /opt/db_backups
vim /opt/db_backups/run_backup.sh

Insert the following logic, adjusting credentials as needed:

#!/bin/bash

# Zabbix DB Backup Routine
DB_HOST="localhost"
DB_ADMIN="admin_user"
DB_PASS="secure_password"
DB_TARGET="zabbix_db"
DEST_PATH="/opt/db_backups"
TIMESTAMP=$(date +'%F')
ARCHIVE_NAME="${DB_TARGET}_${TIMESTAMP}.sql.gz"

# Execute dump and compress
mysqldump -h ${DB_HOST} -u ${DB_ADMIN} -p${DB_PASS} ${DB_TARGET} | gzip > "${DEST_PATH}/${ARCHIVE_NAME}"

# Purge archives older than two weeks
find "${DEST_PATH}" -type f -name "*.sql.gz" -mtime +14 -delete

Grant execution permissions:

chmod +x /opt/db_backups/run_backup.sh

Register a nightly cron job at 02:30:

crontab -e
30 2 * * * /opt/db_backups/run_backup.sh >> /opt/db_backups/execution.log 2>&1

Pruning Historical Trend Data

Remove records older than 24 hours from the history_uint table and reclaim disk space:

USE zabbix_db;
DELETE FROM history_uint WHERE clock < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 24 HOUR));
OPTIMIZE TABLE history_uint;

Confirm the storage reduction:

SELECT
    table_schema AS 'Database',
    table_name AS 'Table',
    table_rows AS 'Row Count',
    ROUND(data_length / 1024 / 1024, 2) AS 'Data (MB)',
    ROUND(index_length / 1024 / 1024, 2) AS 'Index (MB)' 
FROM information_schema.tables 
WHERE table_name = 'history_uint';

Helpful On line Utilities

  • Unix Timestamp Converter: https://www.epochconverter.com/
  • Crontab Schedule Generator: https://crontab-generator.org/

MariaDB Data Directory Migration

Ensure a full backup exists before altering the data location.

  1. Idantify the active storage path:
SHOW VARIABLES LIKE 'datadir';
  1. Halt the database service:
systemctl stop mariadb
  1. Transfer data to the target volume:
rsync -av /var/lib/mysql/ /data/mariadb/
  1. Update the configuration file /etc/my.cnf.d/server.cnf:
[mysqld]
datadir=/data/mariadb
socket=/data/mariadb/mysql.sock

[client]
socket=/data/mariadb/mysql.sock
  1. Assign correct ownership to the new directory:
chown -R mysql:mysql /data/mariadb
  1. Restart the service and verify the path change:
systemctl start mariadb
SHOW VARIABLES LIKE 'datadir';

Provisioning and Mounting Additional Storage

  1. Identify the newly attached block device:
lsblk
  1. Partitoin the drive using fdisk (e.g., /dev/sdb):
fdisk /dev/sdb
# Input: n (new), p (primary), 1, default start, default end, w (write)
  1. Format the partition with the XFS filesystem:
mkfs.xfs /dev/sdb1
  1. Create the mount point directory:
mkdir -p /mnt/storage_vol
  1. Mount the filesystem temporarily:
mount /dev/sdb1 /mnt/storage_vol
  1. Ensure persistent mounting across reboots by retrieving the UUID and appending it to /etc/fstab:
blkid /dev/sdb1
# Example output: UUID="a1b2c3d4"
echo "UUID=a1b2c3d4 /mnt/storage_vol xfs defaults 0 0" >> /etc/fstab
  1. Validate the mount operation:
df -hT | grep storage_vol

Tags: Zabbix Database Administration linux operations MariaDB Shell Scripting

Posted on Tue, 22 Sep 2026 16:56:58 +0000 by Rithotyn