So migrieren Sie Zabbix von MySQL nach PostgreSQL mit minimalen Ausfallzeiten

Bild



Angesichts der Tatsache, dass Zabbix seit einiger Zeit TimescaleDB unterstützt und nun eine neue LTS-Version von Zabbix veröffentlicht wurde, sind viele wahrscheinlich daran interessiert, wie sie von MySQL zu PostgreSQL migrieren können.



Trotz des Textes im Bild ist es durchaus möglich, Zabbix einfach von MySQL nach PostgreSQL zu migrieren. Es gibt viele Rezepte für eine solche Migration im Internet, zum Beispiel:



Bericht vom Zabbix Meetup

Video vom Youtube-Kanal 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


, , ( ):



Bild



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 ):



Bild



Zabbix SELECT. , , web check, SELECT.



. zabbix.load.data:



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


, . .



PostgreSQL . , , pgloader:



Bild



tuples, PostgreSQL :



Bild



, , PostgreSQL . HighLoad:

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



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



— , , , :



begin;
create table x(n numeric);


CPU:



Bild



— .

, . ? , , , .



. , PostgreSQL .



Zabbix. Zabbix . /. , .



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





, Zabbix MySQL PostgreSQL downtime . , , .



, . , - .



feedback, .




All Articles