当前位置:网站首页>Zabbix6.0升级指南-数据库如何同步升级?
Zabbix6.0升级指南-数据库如何同步升级?
2022-06-27 19:56:00 【Zabbix】
张宇,ZCP高级认证工程师
Zabbix 6.0 LTS版本官方正式发布已经有一段时间了,相信很多小伙伴都已经尝试了新搭建一套测试环境练练。对于正式环境的想要升级,又需要保留数据,这时候该如何对数据库同步升级呢?
从Zabbix 6.0开始,主键用于新版本的所有表。本节提供如何手动将现有安装中的历史表升级到主键的说明。
MySQL 5.7+/8.0+
重命名旧表名创建一个新的表名。运行这个sql history_pk_prepare.sql. sql文件,二进制包安装方式地址:
/usr/share/doc/zabbix-sql-scripts/mysql/history_pk_prepare.sql
源码包里地址:zabbix-6.0.0/database/mysql/ history_pk_prepare.sql)
导出导入数据:
Mysqlsh应该安装。Mysqlsh(https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-install-linux-quick.html)应该能够连接到数据库。如果连接是通过套接字完成的,则可能需要它显式地声明到它的路径。
mysqlsh -uroot -S /run/mysqld/mysqld.sock --no-password -Dzabbix
运行:(CSVPATH功能需要被启用 参数local_infile = on):
CSVPATH="/var/lib/mysql-files";
util.exportTable("history_old", CSVPATH + "/history.csv", { dialect: "csv" });
util.importTable(CSVPATH + "/history.csv", {"dialect": "csv", "table": "history" });
util.exportTable("history_uint_old", CSVPATH + "/history_uint.csv", { dialect: "csv" });
util.importTable(CSVPATH + "/history_uint.csv", {"dialect": "csv", "table": "history_uint" });
util.exportTable("history_str_old", CSVPATH + "/history_str.csv", { dialect: "csv" });
util.importTable(CSVPATH + "/history_str.csv", {"dialect": "csv", "table": "history_str" });
util.exportTable("history_log_old", CSVPATH + "/history_log.csv", { dialect: "csv" });
util.importTable(CSVPATH + "/history_log.csv", {"dialect": "csv", "table": "history_log" });
util.exportTable("history_text_old", CSVPATH + "/history_text.csv", { dialect: "csv" });
util.importTable(CSVPATH + "/history_text.csv", {"dialect": "csv", "table": "history_text" });
验证每个步骤正常执行
删除旧的表:
DROP TABLE history_old;
DROP TABLE history_uint_old;
DROP TABLE history_str_old;
DROP TABLE history_log_old;
DROP TABLE history_text_old;
当MySQL <5.7, MariaDB (或者因为一些原因mysqlsh不能使用时)
这个选项更慢,更耗时,只有在有理由不使用mysqlsh时才使用。
重命名旧表,创建新的表执行 history_pk_prepare.sql。
mysql -uzabbix -p<password> zabbix < /usr/share/doc/zabbix-sql-scripts/mysql/history_pk_prepare.sql
导出和导入数据:
检查是否只对指定路径下的文件启用导入/导出:
mysql> SELECT @@secure_file_priv;
+-----------------------+
| @@secure_file_priv |
+-----------------------+
| /var/lib/mysql-files/ |
+-----------------------+
如果该值是目录的路径,则可以对该目录下的文件执行导出/导入操作。在这种情况下,应该相应地编辑查询中的文件路径。或者,secure_file_priv可以在升级期间禁用(设置为空字符串)。如果该值为空,则可以对位于任何位置的文件执行导出/导入操作。
*在导出数据之前应该禁用max_execution_time,以避免在导出期间超时 ***
SET @@max_execution_time=0;
SELECT * INTO OUTFILE '/var/lib/mysql-files/history.csv' FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n' FROM history_old;
LOAD DATA INFILE '/var/lib/mysql-files/history.csv' IGNORE INTO TABLE history FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n';
SELECT * INTO OUTFILE '/var/lib/mysql-files/history_uint.csv' FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n' FROM history_uint_old;
LOAD DATA INFILE '/var/lib/mysql-files/history_uint.csv' IGNORE INTO TABLE history_uint FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n';
SELECT * INTO OUTFILE '/var/lib/mysql-files/history_str.csv' FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n' FROM history_str_old;
LOAD DATA INFILE '/var/lib/mysql-files/history_str.csv' IGNORE INTO TABLE history_str FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n';
SELECT * INTO OUTFILE '/var/lib/mysql-files/history_log.csv' FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n' FROM history_log_old;
LOAD DATA INFILE '/var/lib/mysql-files/history_log.csv' IGNORE INTO TABLE history_log FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n';
SELECT * INTO OUTFILE '/var/lib/mysql-files/history_text.csv' FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n' FROM history_text_old;
LOAD DATA INFILE '/var/lib/mysql-files/history_text.csv' IGNORE INTO TABLE history_text FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n';
验证每个步骤正常执行
删除旧的表:
DROP TABLE history_old;
DROP TABLE history_uint_old;
DROP TABLE history_str_old;
DROP TABLE history_log_old;
DROP TABLE history_text_old;
提高性能一些参数设置:
在这两种情况下提高性能的案例:
***在[mysqld]部分的配置文件中增加bulk_insert_buffer_size缓冲区,或者在导入之前用set设置: ***
[mysqld]
bulk_insert_buffer_size=256M
mysql cli > SET SESSION bulk_insert_buffer_size= 1024 * 1024 * 256;
mysql cli > ... import queries ...
参见“优化InnoDB批量数据加载”:(MySQL5.7,MySQL8.0)
***禁用二进制日志记录(视情况而定): ***
mysql cli > SET SESSION SQL_LOG_BIN=0;
mysql cli > ... import queries ...
最后,祝大家升级一路畅通。 更多详细的数据库升级方案参考地址。https://www.zabbix.com/documentation/current/en/manual/appendix/install/db_primary_keys#mysql
边栏推荐
- Yarn performance tuning of CDH cluster
- Management system itclub (Part 2)
- 资深猎头团队管理者:面试3000顾问,总结组织出8大共性(茅生)
- Common APIs (Methods) for scope -number and string
- 微服务之服务网关
- Remote invocation of microservices
- 从学生到工程师的蜕变之路
- Penetration learning - shooting range chapter - detailed introduction to Pikachu shooting range (under continuous update - currently only the SQL injection part is updated)
- OpenSSL programming I: basic concepts
- DCC888 :Register Allocation
猜你喜欢

关于davwa的SQL注入时报错:Illegal mix of collations for operation ‘UNION‘原因剖析与验证

结构化机器学习项目(一)- 机器学习策略

元气森林的5元有矿之死

深度学习又有新坑了!悉尼大学提出全新跨模态任务,用文本指导图像进行抠图

微服务之服务网关

Penetration learning - shooting range chapter - detailed introduction to Pikachu shooting range (under continuous update - currently only the SQL injection part is updated)

01 golang environment construction

Secret script of test case design without leakage -- module test

average-population-of-each-continent

99 multiplication table - C language
随机推荐
\W and [a-za-z0-9_], \Are D and [0-9] equivalent?
Introduction to MySQL operation (IV) -- data sorting (ascending, descending, and multi field sorting)
Dialogue with Qiao Xinyu: the user is the product manager of Wei brand, and zero anxiety defines luxury
Go from introduction to practice -- shared memory concurrency mechanism (notes)
网易云“情怀”底牌失守
Go from introduction to actual combat - execute only once (note)
Fill in the blank of rich text test
最虚的华人首富更虚了
DCC888 :Register Allocation
MySQL greater than less than or equal to symbol representation
Windwos 8.1系统安装vmware tool插件报错的解决方法
ABAP essay-excel-3-batch import (breaking through 9999 lines of standard functions)
Crawler notes (1) - urllib
Golang uses regularity to match substring functions
CUDA error:out of memory caused by insufficient video memory of 6G graphics card
改善深层神经网络:超参数调试、正则化以及优化(三)- 超参数调试、Batch正则化和程序框架
Gartner focuses on low code development in China how UNIPRO practices "differentiation"
Basics of operators
《7天学会Go并发编程》第7天 go语言并发编程Atomic原子实战操作含ABA问题
关于davwa的SQL注入时报错:Illegal mix of collations for operation ‘UNION‘原因剖析与验证