马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
标题征象
使用CentOS 9摆设Zabbix 7.0使用一段时间后,查询汗青数据时出现报错,Zabbix图形汗青数据表现非常。而且Zabbix对接了Grafana,在Grafana汗青图形中出现图像数据不连续的征象。
Zabbix前端Top hosts by CPU untilization表现赤色告警框,告警内容如下:- Error in query [SELECT * FROM history_uint h WHERE h.itemid='42253' AND h.clock>1739060872 ORDER BY h.clock DESC,h.ns DESC LIMIT 1]
- [Index for table 'history_uint' is corrupt; try to repair it]
- [zabbix.php:17 → require_once() → ZBase->run() → ZBase->processRequest() → CController->run() →
- Widgets\TopHosts\Actions\WidgetView->doAction() → Widgets\TopHosts\Actions\WidgetView->getData() →
- Widgets\TopHosts\Actions\WidgetView->getitemValues() → CHistoryManager->getLastValues() →
- CHistoryManager->getLastValuesFromSqlWithPk() → DBselect() → trigger_error() in include/db.inc.php:243]
复制代码 进入数据库查抄表状态,表空间破坏丢失。- MariaDB [(none)]> use zabbix;
- MariaDB [zabbix]> check table history_uint;
- +---------------------+-------+----------+------------------------------------------------------------------------------+
- | Table | Op | Msg_type | Msg_text |
- +---------------------+-------+----------+------------------------------------------------------------------------------+
- | zabbix.history_uint | check | Error | Got error 194 "Tablespace is missing for a table" from storage engine InnoDB |
- | zabbix.history_uint | check | error | Corrupt |
- +---------------------+-------+----------+------------------------------------------------------------------------------+
- 2 rows in set (0.000 sec)
复制代码 修复方法
可以通过启用innodb_force_recovery暂时模式启动数据库,删除破坏表并重修表布局即可修复history_uint表破坏标题。
1、克制Zabbix服务- [root@localhost ~]# systemctl stop zabbix-server
复制代码 2、启用InnoDB逼迫规复模式
编辑MySQL主设置文件/etc/my.cnf
- [root@localhost ~]# vim /etc/my.cnf
复制代码 在主设置文件中添加以下内容:- [mysqld]
- innodb_force_recovery=1
复制代码 3、重启数据库服务- [root@localhost ~]# systemctl stop mariadb.service
- [root@localhost ~]# systemctl start mariadb.service
复制代码 4、删除并重修history_uint表
进入数据库:- [root@localhost ~]# mysql -uroot -p
复制代码 实验以下SQL语句:- USE zabbix;
- DROP TABLE history_uint;
- CREATE TABLE `history_uint` (
- `itemid` bigint(20) unsigned NOT NULL,
- `clock` int(11) NOT NULL DEFAULT 0,
- `value` bigint(20) unsigned NOT NULL DEFAULT 0,
- `ns` int(11) NOT NULL DEFAULT 0,
- PRIMARY KEY (`itemid`,`clock`,`ns`)
- ) ENGINE=InnoDB
- DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
复制代码 5、关闭规复模式并重启数据库
删除/etc/my.cnf设置文件中新增的以下内容:- [mysqld]
- innodb_force_recovery=1
复制代码 重启数据库服务:- [root@localhost ~]# systemctl stop mariadb.service
- [root@localhost ~]# systemctl start mariadb.service
复制代码 6、启动Zabbix服务- [root@localhost ~]# systemctl start zabbix-server
复制代码 至此,即可完成history_uint表破坏导致汗青数据查询非常的标题。
脚本修复
1、创建一个名为zabbix_db_tools.sh的文件2、将以下内容复制到文件中,按下Esc键,然后按下Shift+:键,输入wq!生存
[code]#!/bin/bash# ===============================================# Zabbix 数据库修复脚本 (history_uint 表破坏修复)# 使用前请确认运行用户有root权限# ===============================================MYSQL_CONF="/etc/my.cnf"MYSQL_CMD="/usr/bin/mariadb -uroot"ZABBIX_DB="zabbix"echo "==============================="echo "开始实验 Zabbix 数据库修复流程..."echo "==============================="# Step 1: 克制 Zabbix 服务echo "[1/10] 克制 Zabbix 服务..."systemctl stop zabbix-server 2>/dev/nullsystemctl stop zabbix-agent 2>/dev/null# Step 2: 启用 innodb_force_recoveryecho "[2/10] 启用 innodb_force_recovery=1 ..."if grep -q "innodb_force_recovery" "$MYSQL_CONF"; then sed -i 's/^#\?\s*innodb_force_recovery=.*/innodb_force_recovery=1/' "$MYSQL_CONF"else sed -i '/^\[mysqld\]/a innodb_force_recovery=1' "$MYSQL_CONF"fi# Step 3: 克制数据库服务echo "[3/10] 克制 MariaDB 数据库..."systemctl stop mariadb.service# Step 4: 启动数据库(规复模式)echo "[4/10] 启动 MariaDB (规复模式)..."systemctl start mariadb.servicesleep 3# Step 5-6: 删除并重修表echo "[5/10] 毗连数据库并修复表..."$MYSQL_CMD |