Cómo migrar Zabbix de MySQL a PostgreSQL con un tiempo de inactividad mínimo

imagen



A la luz del hecho de que Zabbix ha sido compatible con TimescaleDB durante algún tiempo, y ahora se ha lanzado una nueva versión LTS de Zabbix, muchos probablemente estén interesados ​​en cómo migrar de MySQL a PostgreSQL.



A pesar del texto de la imagen, es muy posible simplemente tomar y migrar Zabbix de MySQL a PostgreSQL. Hay muchas recetas para tal migración en Internet, por ejemplo:



Informe de Zabbix Meetup

Video del canal de Youtube Dmitry Lambert



, downtime , , .



, .



, Zabbix 4.0. , , , .





, Zabbix : ( ). Zabbix . : , , ?





, , PostgreSQL. , , .



:



  • PostgreSQL, 12.
  • PgLoader 3.6.2. 3.6.1 - .


PostgreSQL , .

, , :





PostgreSQL.

Zabbix 4.0, , :

https://github.com/lesovsky/zabbix-extensions/tree/master/files/postgresql



, Zabbix, nodata, .. .



. , .



— Zabbix server:



systemctl stop zabbix-server




, Zabbix, schema.sql, database/postgresql zabbix, 2 :

CREATE, ALTER.



2 : create.sql, alter.sql



create.sql :



cat create.sql | psql -Uzabbix zabbix 


pgloader — zabbix.load.config



LOAD DATABASE
 FROM mysql://zabbix:zabbix-password@localhost/zabbix
 INTO postgresql://zabbix:zabbix-password@192.168.1.1:5432/zabbix
WITH include no drop,
truncate,
create no tables,
create no indexes,
no foreign keys,
reset sequences,
data only
SET MySQL PARAMETERS
 max_execution_time = '0'
SET PostgreSQL PARAMETERS
 maintenance_work_mem TO '1024MB', work_mem to '128MB'
EXCLUDING TABLE NAMES MATCHING ~/history.*/, ~/trend.*/
ALTER SCHEMA 'zabbix' RENAME TO 'public';




EXCLUDING TABLE NAMES MATCHING ~/history.*/, ~/trend.*/




:



pgloader zabbix.load.config


, , ( ):



imagen



alter.sql :



cat alter.sql | psql -Uzabbix zabbix 


, , alter.sql trend history. 4.0 . , , .. , alter.sql



Zabbix, MySQL , PostgreSQL. CentOS 7, , :



yum remove zabbix-server-mysql zabbix-web-mysql
yum install zabbix-server-pgsql zabbix-web-pgsql php-pgsql


:

https://www.zabbix.com/documentation/4.0/manual/installation/install_from_packages



Web Zabbix, :



rm /etc/zabbix/web/zabbix.conf.php


:



/etc/httpd/conf.d/zabbix.conf


zabbix_server.conf: DBHost, DBPort, DBUser, DBName, DBPassword.



Zabbix Server!



systemctl start zabbix-server


web- zabbix (http(s)://ip/zabbix), .



web- , , , .. . . , — .



, , , . , , , .

— .





, .



, .



Zabbix . Zabbix ( , ), . API 200 Zabbix icmp web checks . 1000 NVPS.



, Zabbix server PostgreSQL .



.



zabbix.load.data pgloader:



LOAD DATABASE
 FROM mysql://zabbix:zabbix-password@localhost/zabbix
 INTO postgresql://zabbix:zabbix-password@192.168.1.1:5432/zabbix
WITH include no drop,
no truncate,
create no tables,
create no indexes,
no foreign keys,
reset sequences,
data only,
prefetch rows = 5000,
multiple readers per thread

SET MySQL PARAMETERS
 max_execution_time = '0',
 net_read_timeout = ‘86400’,
 net_write_timeout = ‘86400’
SET PostgreSQL PARAMETERS
 maintenance_work_mem TO '1024MB', work_mem to '128MB'
INCLUDING ONLY TABLE NAMES MATCHING ~/history.*/, ~/trend.*/
ALTER SCHEMA 'zabbix' RENAME TO 'public';


:



no truncate


, . , .



INCLUDING ONLY TABLE NAMES MATCHING ~/history.*/, ~/trend.*/


, .





pgloader zabbix.load.data


, . 150 4-5 .



. , CPU PostgreSQL , ( load average 1 ):



imagen



Zabbix SELECT. , , web check, SELECT.



. zabbix.load.data:



prefetch_rows = 1000,
workers = 1,
concurrency = 1,
single reader per thread


, . .



PostgreSQL . , , pgloader:



imagen



tuples, PostgreSQL :



imagen



, , PostgreSQL . HighLoad:

https://www.youtube.com/watch?v=3h48iowNbwo



, , PostgreSQL (single-page cleanup). tuple. , tuple , CPU.



— , , , :



begin;
create table x(n numeric);


CPU:



imagen



— .

, . ? , , , .



. , PostgreSQL .



Zabbix. Zabbix . /. , .



, Zabbix Server PostgreSQL. , ! CPU, . - PostgreSQL . PostgreSQL ?





, Zabbix MySQL PostgreSQL downtime . , , .



, . , - .



feedback, .




All Articles