Home Database Mysql Tutorial 实战Zabbix-Server数据库MySQL的libdata1文件过大

实战Zabbix-Server数据库MySQL的libdata1文件过大

Jun 07, 2016 pm 04:42 PM
zabbix

今天我们的zabbix-server机器根空间不够了,我一步步排查结果发现是/var/lib/mysql/下的libdata1文件过大,已经达到了41G。我立即

今天我们的zabbix-server机器根空间不够了,我一步步排查结果发现是/var/lib/mysql/下的libdata1文件过大,已经达到了41G。我立即想到了zabbix的数据库原因,随后百度、谷歌才知道zabbix的数据库他的表模式是共享表空间模式,随着数据增长,ibdata1 越来越大,性能方面会有影响,而且innodb把数据和索引都放在ibdata1下。

共享表空间模式:

InnoDB 默认会将所有的数据库InnoDB引擎的表数据存储在一个共享空间中:ibdata1,这样就感觉不爽,增删数据库的时候,ibdata1文件不会自动收缩,单个数据库的备份也将成为问题。通常只能将数据使用mysqldump 导出,然后再导入解决这个问题。

独立表空间模式:

优点:
1.每个表都有自已独立的表空间。
2.每个表的数据和索引都会存在自已的表空间中。
3.可以实现单表在不同的数据库中移动。
4.空间可以回收(drop/truncate table方式操作表空间不能自动回收)
5.对于使用独立表空间的表,不管怎么删除,表空间的碎片不会太严重的影响性能,而且还有机会处理。
缺点:
单表增加比共享空间方式更大。

结论:
共享表空间在Insert操作上有一些优势,但在其它都没独立表空间表现好,所以我们要改成独立表空间。
当启用独立表空间时,请合理调整一下 innodb_open_files 参数。

下面我们来讲下如何讲zabbix数据库修改成独立表空间模式

1.查看文件大小

[root@localhost ~]#cd /var/lib/mysql

[root@localhost ~]#ls -lh

-rw-rw---- 1 mysql mysql 41G Nov 24 13:31 ibdata1

-rw-rw---- 1 mysql mysql 5.0M Nov 24 13:31 ib_logfile0

-rw-rw---- 1 mysql mysql 5.0M Nov 24 13:31 ib_logfile1

drwx------ 2 mysql mysql 1.8M Nov 24 13:31 zabbix

大家可以看到这是没修改之前的共享表数据空间文件ibdata1大小已经达到了41G

2.清除zabbix数据库历史数据

1)查看哪些表的历史数据比较多

[root@localhost ~]#mysql -uroot -p

mysql > select table_name, (data_length+index_length)/1024/1024 as total_mb, table_rows from information_schema.tables where table_schema='zabbix';

 

+-----------------------+---------------+------------+

| table_name            | total_mb      | table_rows |

+-----------------------+---------------+------------+

| acknowledges          |    0.06250000 |          0 |

....

| help_items            |    0.04687500 |        103 |

| history              | 1020.00000000 |  123981681 |

| history_log          |    0.04687500 |          0 |

...

| history_text          |    0.04687500 |          0 |

| history_uint          | 3400.98437500 |  34000562 |

| history_uint_sync    |    0.04687500 |          0 |

可以看到history和history_uint这两个表的历史数据最多。

另外就是trends,trends_uint中也存在一些数据。

由于数据量太大,按照普通的方式delete数据的话基本上不太可能。

所以决定直接采用truncate table的方式来快速清空这些表的数据,再使用mysqldump导出数据,删除共享表空间数据文件,重新导入数据。

2)停止相关服务,避免写入数据

[root@localhost ~]#/etc/init.d/zabbix_server stop

[root@localhost ~]#/etc/init.d/httpd stop

3)清空历史数据

[root@localhost ~]#mysql -uroot -p

mysql > use zabbix;

Database changed

 

mysql > truncate table history;

Query OK, 123981681 rows affected (0.23 sec)

 

mysql > optimize table history;

1 row in set (0.02 sec)

 

mysql > truncate table history_uint;

Query OK, 57990562 rows affected (0.12 sec)

mysql > optimize table history_uint;

1 row in set (0.03 sec)

3.备份数据库由于我/下的空间不足所以我挂载了一个NFS过来

[root@localhost ~]#mysqldump -uroot -p zabbix > /data/zabbix.sql

4.停止数据库并删除共享表空间数据文件

1)停止数据库

[root@localhost ~]#/etc/init.d/mysqld stop

2)删除共享表空间数据文件

[root@localhost ~]#cd /var/lib/mysql

[root@localhost ~]#rm -rf ib*


5.增加innodb_file_per_table参数

[root@localhost ~]#vi /etc/my.cnf

在[mysqld]下设置

innodb_file_per_table=1

6.启动mysql

[root@localhost ~]#/etc/init.d/mysqld start

7.查看innodb_file_per_table参数是否生效

[root@localhost ~]#mysql -uroot -p

mysql> show variables like '%per_table%';

+-----------------------+-------+

| Variable_name | Value |

+-----------------------+-------+

| innodb_file_per_table | ON |

+-----------------------+-------+

1 row in set (0.00 sec)


8.重新导入数据库

[root@localhost ~]#mysqldump -uroot -p zabbix

9.最后,恢复相关服务进程

[root@localhost ~]#/etc/init.d/zabbix_server start

[root@localhost ~]#/etc/init.d/httpd start

恢复完服务之后,查看/分区的容量就下去了,,之前是99%,处理完之后变成了12%。可见其成效

 

一些Zabbix相关教程集合:

安装部署分布式监控系统Zabbix 2.06

《安装部署分布式监控系统Zabbix 2.06》

CentOS 6.3下Zabbix安装部署

Zabbix分布式监控系统实践

CentOS 6.3下Zabbix监控apache server-status

CentOS 6.3下Zabbix监控MySQL数据库参数

64位CentOS 6.2下安装Zabbix 2.0.6   

ZABBIX 的详细介绍:请点这里
ZABBIX 的下载地址:请点这里

本文永久更新链接地址:

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to monitor redis memory in zabbix How to monitor redis memory in zabbix Jun 03, 2023 am 10:00 AM

1. Download the import template directly and import the template through the following steps: Click configuration->templates>import->Import the downloaded xml file. 2. Configure the client key on the monitored host, open the /etc/zabbix/zabbix_agentd.conf configuration file, and add in the last line: UserParameter=redis_stats[*],redis-cli-h127.0.0.1-p$1info |grep$2|cut-d:-f2 After the configuration is completed, pass /etc/init.d/zabbix_agentdre

How zabbix monitors traceroute data How zabbix monitors traceroute data May 19, 2023 am 11:10 AM

1. Zabbixserver and proxy install the mtrmtr script and place it in the following path of zabbixserver and proxy: execute chownzabbix:zabbixmtrtrace.shzabbix to create the mtrtrace template: 5. Associate the host to the template and observe the data in zabbix: [monitoring]-[latestdata]:

What are the network devices that Zabbix 3.0 monitors? What are the network devices that Zabbix 3.0 monitors? Jun 04, 2023 am 08:44 AM

Introduction to SNMP 1 Overview of SNMP SNMP has developed to become the most widely used network management protocol. The currently applied versions mainly include SNMPv1, SNMPv2c and SNMPv3. The main differences between the versions are in the definition of information, the operation of communication protocols and the security mechanism. At the same time, two extensions of SNMP applications, remote network monitoring RMON (Remote Network Monitoring) and RMON2, have also appeared. From the perspective of the physical layer, using SNMP to manage the network should include: network management station (NMS), agent (Agent), and proxy server (proxy). NMS can generate commands and receive notification information. There must be at least one in the network management

How to use Zabbix custom script to monitor nginx and WeChat alarms How to use Zabbix custom script to monitor nginx and WeChat alarms May 21, 2023 pm 05:10 PM

Project Description The purpose of this project is to build a zabbix monitoring system that can implement WeChat alarms, conveniently monitor the entire NGINX cluster, and at the same time deploy and manage the entire cluster in batches. Project steps: Install zabbixserver on the zabbix server (192.168.2.138), install zabbixagent (192.168.2.58) on the nginx side, configure the Nginx load balancing cluster, and turn on status statistics. Write a monitoring script on the nginx side to get the status of nginx. The server-side web adds monitoring items and outputs pictures. Register the enterprise WeChat and configure the WeChat interface. Add the interface push script to the zabbix server and test that the interface is normal. in we

Using Zabbix for monitoring and management in Java API development Using Zabbix for monitoring and management in Java API development Jun 18, 2023 am 08:25 AM

In JavaAPI development, monitoring management is a very important part. In order to ensure the stability and reliability of the application, we need to monitor various indicators, such as CPU usage, memory usage, network traffic, etc., and respond in a timely manner. In this case, Zabbix is ​​an excellent monitoring tool. Zabbix is ​​an open source monitoring solution that can monitor various parameters and services, including networks, servers, applications, databases, etc. It provides a powerful We

How to monitor Nginx/Tomcat/MySQL with zabbix How to monitor Nginx/Tomcat/MySQL with zabbix May 17, 2023 pm 08:31 PM

Zabbix monitors nginxa machine: zabbix server (192.168.234.128) b machine: zabbix client (192.168.234.125) Operation on b machine (zabbix client): edit nginx virtual host configuration file: [root@centos~]#vi/ etc/nginx/conf.d/default.conf Add the following content in server{}: location/nginx_status{stub_statuson;access_logoff;allow127.0.0.1;denyall;}Reload ngi

How to configure nginx monitoring in zabbix How to configure nginx monitoring in zabbix May 12, 2023 pm 08:31 PM

Case: zabbix configures nginx monitoring 1. Modify the configuration file vim/usr/local/nginx/conf/nginx.conflocation/nginx_status{stub_status;} Description: nginx_status custom field, access address (example: 192.168.169.131/nginx_status) stub_status fixed Parameter #Restart nginx./nginxreload Browser access status description: ActiveconnectionsNginx is processing the number of active links; important serverNginx starts to the present

How to use zabbix to monitor multiple mysql How to use zabbix to monitor multiple mysql Jun 02, 2023 pm 02:25 PM

The main tools used: Macros (divided into template macros, host macros, and automatically discovered macros) Host macro format: $MACRO (can fill in the value directly) Automatically discovered macros: #MACRO (needs to match the value of the created key) General structure 1. Agent host—the agent host creates the macro variable $MYSQLPORT. The value of the macro variable is the automatic discovery script parameter of Discoveryrules. 2. Template—Create automatic discovery rules in the template, relying on the automatic discovery script to obtain the automatic discovery macro variable. 3. Monitoring items – Create monitoring items in Discoveryrules. The names and key values ​​of the monitoring items are automatically sent.

See all articles