Phapang pakeng tsa PostgreSQL le MySQL

Phapang pakeng tsa PostgreSQL le MySQL

Ke tla hlakisa phetisetso lipakeng tsa PostgreSQL le MySQL, hammoho le mekhoa ea ho theha phetisetso lipakeng tsa li-server tse peli tsa database. Ka tloaelo, li-database tse hatisitsoeng li bitsoa homogeneous, 'me ke mokhoa o bonolo oa ho tloha ho seva se seng sa RDBMS ho ea ho se seng.

Li-database tsa PostgreSQL le MySQL hangata li nkuoa e le tsa kamano, empa ka likeketso tse ling li fana ka bokhoni ba NoSQL. Mona re tla tšohla phetisetso lipakeng tsa PostgreSQL le MySQL ho latela pono ea DBMS ea kamano.

Re ke ke ra hlalosa ts'ebetso eohle ea kahare, feela melaoana ea mantlha e le hore u tle u fumane mohopolo oa ho hlophisa phetisetso lipakeng tsa li-server tsa database, melemo, mefokolo le linyeoe tsa ts'ebeliso.

Ka tloaelo, phetisetso lipakeng tsa li-server tse peli tse ts'oanang tsa database e etsoa ka mokhoa oa binary kapa ho sebelisoa lipotso lipakeng tsa monghali (aka mohoeletsi, monghali, kapa ea sebetsang) le lekhoba (mo ngolisitseng, ea emelang, kapa ea sa sebetseng). Sepheo sa ho pheta-pheta ke ho fana ka kopi ea nako ea sebele ea database ea master ka lehlakoreng la makhoba. Tabeng ena, data e fetisoa ho tloha ho monghali ho ea ho lekhoba, ke hore, ho tloha ho motho ea sebetsang ho ea ho motho ea sa sebetseng, hobane ho pheta-pheta ho etsoa ka tsela e le 'ngoe feela. Empa o ka theha phetisetso lipakeng tsa li-database tse peli ka mahlakoreng ka bobeli, e le hore data e fetisetsoe ho tloha ho lekhoba ho ea ho master ka tlhophiso e sebetsang e sebetsang. Tsena tsohle, ho kenyeletsoa le ho pheta-pheta, ho ka khoneha lipakeng tsa li-server tse peli kapa ho feta tse ts'oanang tsa database.

Tokiso e hlalositsoeng e ka khoneha lipakeng tsa li-server tse fapaneng tsa database. Seva e ka hlophisoa ho amohela lintlha tse phetoang ho tsoa ho seva se seng sa database mme e ntse e boloka linepe tsa nako ea nnete ea data e kopilitsoeng. MySQL le PostgreSQL li fana ka boholo ba litlhophiso tsena ka tlung kapa ka likatoloso tsa mokha oa boraro, ho kenyeletsoa mekhoa ea li-binary log, ho notlela li-disk, le mekhoa e thehiloeng ho polelo le mela.

Ho pheta-pheta lipakeng tsa MySQL le PostgreSQL hoa hlokahala bakeng sa ho falla ha nako e le 'ngoe ho tloha ho seva se seng sa database ho ea ho se seng. Li-database tsena li sebelisa li-protocol tse fapaneng, kahoo ha ho khonehe ho li hokahanya ka kotloloho. Ho theha phapanyetsano ea data, o ka sebelisa sesebelisoa sa kantle se bulehileng, mohlala pg_chameleon.

pg_chameleon ke eng

pg_chameleon ke mokhoa oa ho pheta-pheta ho tloha ho MySQL ho ea PostgreSQL ho Python 3. E sebelisa laebrari e bulehileng ea mysql-replication, hape e Python. Litšoantšo tsa mela li ntšoa litafoleng tsa MySQL ebe li bolokoa e le lintho tsa JSONB sebakeng sa polokelo ea litaba tsa PostgreSQL, ebe li hlakoloa ke ts'ebetso ea pl/pgsql ebe li hlahisoa hape polokelong ea PostgreSQL.

Likarolo tsa pg_chameleon

Merero e mengata ea MySQL e tsoang sehlopheng se le seng e ka fetisetsoa ho database e le 'ngoe ea PostgreSQL ka tlhophiso e le 'ngoe ho isa ho tse ngata.
Mabitso a mohloli le sepheo sa schema a ke ke a tšoana.
Lintlha tsa ho pheta-pheta li ka fumanoa ho tsoa ho replica ea MySQL e senyehileng.
Litafole tse sa khoneng ho pheta-pheta kapa ho hlahisa liphoso ha li kenyelletsoe.
Mosebetsi o mong le o mong oa ho ikatisa o laoloa ke li-daemone.
Laola ka liparamente tse thehiloeng ho YAML le lifaele tsa tlhophiso.

Mohlala:

Moamoheli
vm1
vm2

Phetolelo ea OS
CentOS Linux 7.6 x86_64
CentOS Linux 7.5 x86_64

Mofuta oa seva oa DB
MySQL 5.7.26
PostgreSQL 10.5

DB boema-kepe
3306
5433

Aterese ea IP
192.168.56.102
192.168.56.106

Ho qala, lokisetsa likarolo tsohle tse hlokahalang ho kenya pg_chameleon. Mohlala ona o kenya Python 3.6.8, e etsang le ho kenya ts'ebetsong tikoloho ea sebele.

$> wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz
$> tar -xJf Python-3.6.8.tar.xz
$> cd Python-3.6.8
$> ./configure --enable-optimizations
$> make altinstall

Kamora ho kenya Python3.6 ka katleho, o hloka ho tlatsa litlhoko tse setseng, joalo ka ho theha le ho kenya tšebetsong tikoloho ea sebele. Ho feta moo, pip module e nchafalitsoe ho mofuta oa morao-rao mme e sebelisoa ho kenya pg_chameleon. Litaelo tse ka tlase ka boomo kenya pg_chameleon 2.0.9, le hoja phetolelo ea morao-rao e le 2.0.10. Sena sea hlokahala ho qoba liphoso tse ncha ho mofuta o ntlafalitsoeng.

$> python3.6 -m venv venv
$> source venv/bin/activate
(venv) $> pip install pip --upgrade
(venv) $> pip install pg_chameleon==2.0.9

Ebe re bitsa pg_chameleon (chameleon ke taelo) ka khang ea set_configuration_files ho thusa pg_chameleon le ho theha li-directory le lifaele tsa tlhophiso.

(venv) $> chameleon set_configuration_files
creating directory /root/.pg_chameleon
creating directory /root/.pg_chameleon/configuration/
creating directory /root/.pg_chameleon/logs/
creating directory /root/.pg_chameleon/pid/
copying configuration  example in /root/.pg_chameleon/configuration//config-example.yml

Hona joale re etsa kopi ea config-example.yml joalo ka default.yml hore e fetohe faele e hlophisitsoeng ea kamehla. Mohlala oa faele ea tlhophiso ea mohlala ona o fanoe ka tlase.

$> cat default.yml
---
#global settings
pid_dir: '~/.pg_chameleon/pid/'
log_dir: '~/.pg_chameleon/logs/'
log_dest: file
log_level: info
log_days_keep: 10
rollbar_key: ''
rollbar_env: ''

# type_override allows the user to override the default type conversion into a different one.
type_override:
  "tinyint(1)":
    override_to: boolean
    override_tables:
      - "*"

#postgres  destination connection
pg_conn:
  host: "192.168.56.106"
  port: "5433"
  user: "usr_replica"
  password: "pass123"
  database: "db_replica"
  charset: "utf8"

sources:
  mysql:
    db_conn:
      host: "192.168.56.102"
      port: "3306"
      user: "usr_replica"
      password: "pass123"
      charset: 'utf8'
      connect_timeout: 10
    schema_mappings:
      world_x: pgworld_x
    limit_tables:
#      - delphis_mediterranea.foo
    skip_tables:
#      - delphis_mediterranea.bar
    grant_select_to:
      - usr_readonly
    lock_timeout: "120s"
    my_server_id: 100
    replica_batch_size: 10000
    replay_max_rows: 10000
    batch_retention: '1 day'
    copy_max_memory: "300M"
    copy_mode: 'file'
    out_dir: /tmp
    sleep_loop: 1
    on_error_replay: continue
    on_error_read: continue
    auto_maintenance: "disabled"
    gtid_enable: No
    type: mysql
    skip_events:
      insert:
        - delphis_mediterranea.foo #skips inserts on the table delphis_mediterranea.foo
      delete:
        - delphis_mediterranea #skips deletes on schema delphis_mediterranea
      update:

Faele ea tlhophiso mohlaleng ona ke mohlala oa pg_chameleon faele e nang le liphetoho tse nyane ho lumellana le libaka tsa mohloli le tse shebiloeng, 'me ka tlase ke kakaretso ea likarolo tse fapaneng tsa faele ea tlhophiso.

Ho "default.yml configuration" ho na le karolo ea litlhophiso tsa lefats'e, moo o ka laolang litlhophiso tse kang sebaka sa faele ea senotlolo, sebaka sa li-log, nako ea ho boloka li-log, joalo-joalo. sehlopha sa melao bakeng sa ho fetisa mefuta nakong ya katiso. Mohlala o feto-fetoha ho mofuta oa molao oa ho fetisa o fetolelang tinyint(1) ho boleng ba boolean. Karolong e latelang, re hlakisa lintlha tsa khokahano ho database ea sepheo. Tabeng ea rona, ena ke database ea PostgreSQL, e khethiloeng pg_conn. Karolong ea ho qetela, re bonts'a lintlha tsa mohloli, ke hore, li-parameter tsa khokahanyo tsa mohloli oa mohloli, moralo oa 'mapa pakeng tsa mohloli le li-database tse lebisitsoeng, litafole tse lokelang ho tlōloa, nako ea ho leta, mohopolo, boholo ba sephutheloana. Hlokomela hore "mehloli" ke bongata, ho bolelang hore re ka kenya marang-rang a mangata sebakeng se le seng sa polokelo ea sepheo ho theha tlhophiso ea batho ba bangata ho ea ho e le 'ngoe.

Mohlala oa database world_x o na le litafole tse 4 tse nang le mela eo sechaba sa MySQL se fanang ka eona e le mehlala. E ka kopitsoa mona. Sebaka sa polokelo ea boitsebiso se tla e le polokelo ea tar le e hatelitsoeng e nang le litaelo tsa ho theha le ho kenya mela.

Ho database tsa MySQL le PostgreSQL, mosebelisi ea khethehileng o entsoe ka lebitso le tšoanang usr_replica. Ho MySQL, e fuoa litokelo tse eketsehileng tsa ho bala litafoleng tsohle tse phetoang.

mysql> CREATE USER usr_replica ;
mysql> SET PASSWORD FOR usr_replica='pass123';
mysql> GRANT ALL ON world_x.* TO 'usr_replica';
mysql> GRANT RELOAD ON *.* to 'usr_replica';
mysql> GRANT REPLICATION CLIENT ON *.* to 'usr_replica';
mysql> GRANT REPLICATION SLAVE ON *.* to 'usr_replica';
mysql> FLUSH PRIVILEGES;

Ka lehlakoreng la PostgreSQL, ho entsoe database ea db_replica e tla amohela liphetoho ho tsoa polokelong ea MySQL. Mosebelisi usr_replica ho PostgreSQL e hlophisoa ka bo eona e le mong'a li-schemas tse peli, pgworld_x le sch_chameleon, tse nang le litafole tsa 'nete tse phetoang le litafole tsa bukana ea phetisetso, ka ho latellana. Khang ea create_replica_schema e ikarabella bakeng sa tlhophiso ea boiketsetso, joalo ka ha u tla bona ka tlase.

postgres=# CREATE USER usr_replica WITH PASSWORD 'pass123';
CREATE ROLE
postgres=# CREATE DATABASE db_replica WITH OWNER usr_replica;
CREATE DATABASE

Sebaka sa polokelo ea polokelo ea MySQL se hlophisitsoe ka liphetoho tse ling tsa parameter ho e lokisetsa ho pheta-pheta joalokaha ho bontšitsoe ka tlase. U tla hloka ho qala seva sa database bocha hore liphetoho li tle li sebetse.

$> vi /etc/my.cnf
binlog_format= ROW
binlog_row_image=FULL
log-bin = mysql-bin
server-id = 1

Hona joale ke habohlokoa ho hlahloba khokahanyo ho li-server tse peli tsa database e le hore ho se ke ha e-ba le mathata ha u tsamaisa litaelo tsa pg_chameleon.

Ho node ea PostgreSQL:

$> mysql -u usr_replica -Ap'admin123' -h 192.168.56.102 -D world_x

Ho node ea MySQL:

$> psql -p 5433 -U usr_replica -h 192.168.56.106 db_replica

Litaelo tse tharo tse latelang tsa pg_chameleon (chameleon) li lokisa tikoloho, li eketsa mohloli, 'me li qale setšoantšo. Khang ea create_replica_schema ho pg_chameleon e theha schema ea kamehla (sch_chameleon) le schema replication (pgworld_x) polokelong ea polokelo ea PostgreSQL, joalo ka ha re se re buile. Phehisano ea add_source e eketsa database ea mohloli ho tlhophiso ka ho bala faele ea tlhophiso (default.yml), 'me molemong oa rona ke mysql,' me init_replica e qala tlhophiso e thehiloeng ho li-parameter ho faele ea tlhophiso.

$> chameleon create_replica_schema --debug
$> chameleon add_source --config default --source mysql --debug
$> chameleon init_replica --config default --source mysql --debug

Sephetho sa litaelo tsena tse tharo se bontša ka ho hlaka hore li ile tsa bolaoa ka katleho. Liphoso life kapa life kapa liphoso tsa syntax li tlalehoa ka melaetsa e bonolo, e hlakileng e nang le malebela a ho lokisa bothata.

Qetellong, re qala ho pheta-pheta re sebelisa start_replica mme re fumana molaetsa oa katleho.

$> chameleon start_replica --config default --source mysql 
output: Starting the replica process for source mysql

Boemo ba phetisetso bo ka botsoa ho sebelisoa khang ea show_status, 'me liphoso li ka bonoa ho sebelisoa khang ea show_errors.

Phello.

Joalokaha re se re boletse, mosebetsi o mong le o mong oa ho ikatisa o laoloa ke li-daemone. Ho li sheba, re botsa tafole ea ts'ebetso ka taelo ea Linux ps, joalo ka ha ho bonts'itsoe ka tlase.

Phello.

Replication ha e nkoe e hlophisitsoe ho fihlela re e leka ka nako ea nnete, joalo ka ha ho bonts'itsoe ka tlase. Re theha tafole, re kenya lirekoto tse 'maloa polokelong ea MySQL,' me re letsetsa khang ea sync_tables ho pg_chameleon ho nchafatsa li-daemone le ho pheta tafole ka lirekoto ho database ea PostgreSQL.

mysql> create table t1 (n1 int primary key, n2 varchar(10));
Query OK, 0 rows affected (0.01 sec)
mysql> insert into t1 values (1,'one');
Query OK, 1 row affected (0.00 sec)
mysql> insert into t1 values (2,'two');
Query OK, 1 row affected (0.00 sec)

$> chameleon sync_tables --tables world_x.t1 --config default --source mysql
Sync tables process for source mysql started.

Ho netefatsa liphetho tsa liteko, re botsa tafole ho tsoa ho database ea PostgreSQL ebe re hlahisa mela.

$> psql -p 5433 -U usr_replica -d db_replica -c "select * from pgworld_x.t1";
 n1 |  n2
----+-------
  1 | one
  2 | two

Haeba re ntse re falla, litaelo tse latelang tsa pg_chameleon e tla ba pheletso ea eona. Litaelo li hloka ho phethoa ka mor'a hore re be le bonnete ba hore mela ea litafole tsohle tse shebiloeng e phetiloe, 'me sephetho e tla ba polokelo ea polokelo ea PostgreSQL e fallisitsoeng ka makhethe ntle le litšupiso tsa database ea mohloli kapa morero oa ho pheta-pheta (sch_chameleon).

$> chameleon stop_replica --config default --source mysql 
$> chameleon detach_replica --config default --source mysql --debug

Haeba o lakatsa, o ka sebelisa litaelo tse latelang ho hlakola moralo oa mantlha oa tlhophiso le phetisetso.

$> chameleon drop_source --config default --source mysql --debug
$> chameleon drop_replica_schema --config default --source mysql --debug

Melemo ea pg_chameleon

Ho seta habonolo le ho hlophisoa.
Rarolla mathata habonolo 'me u khetholle liphapang ka melaetsa e hlakileng ea liphoso.
Litafole tse ling tse khethehileng li ka eketsoa ho pheta-pheta ka mor'a ho qala ntle le ho fetola tlhophiso e setseng.
Hoa khoneha ho hlophisa li-database tsa mehloli e mengata bakeng sa polokelo ea boitsebiso e le 'ngoe, 'me sena se molemo haholo haeba u kopanya data ho tloha ho e le' ngoe kapa tse ngata tsa database tsa MySQL ho database e le 'ngoe ea PostgreSQL.
Ha ua tlameha ho pheta litafole tse khethiloeng.

Mathata a pg_chameleon

E tšehetsoa feela ka MySQL 5.5 le ka holimo e le mohloli le PostgreSQL 9.5 le ka holimo e le database ea sepheo.
Tafole e 'ngoe le e' ngoe e tlameha ho ba le senotlolo sa mantlha kapa se ikhethileng, ho seng joalo litafole li qalisoa nakong ea ts'ebetso ea init_replica empa ha li phetisoe.
Ho pheta-pheta ka tsela e le 'ngoe - feela ho tloha MySQL ho ea PostgreSQL. Ka hona, e loketse feela potoloho ea "active-passive".
Mohloli e ka ba database ea MySQL feela, 'me tšehetso bakeng sa database ea PostgreSQL e le mohloli ke liteko feela le mefokolo (ithute haholoanyane mona)

Liphetho tsa pg_chameleon

Mokhoa oa ho pheta-pheta ho pg_chameleon o motle bakeng sa ho fallisa database ho tloha MySQL ho ea PostgreSQL. Taba ea bohlokoa ke hore ho pheta-pheta ke mokhoa o le mong feela, kahoo litsebi tsa database ha li na monyetla oa ho batla ho li sebelisa bakeng sa eng kapa eng ntle le ho falla. Empa bothata ba ho pheta-pheta ka tsela e le 'ngoe bo ka rarolloa ka sesebelisoa se seng se bulehileng - SymmetricDS.

Bala haholoanyane litokomaneng tsa molao mona. Thuso ea mohala oa taelo e ka fumanoa mona.

Kakaretso ea SymmetricDS

SymmetricDS ke sesebelisoa sa mohloli o bulehileng o phetang database efe kapa efe ho database efe kapa efe e tloaelehileng: Oracle, MongoDB, PostgreSQL, MySQL, SQL Server, MariaDB, DB2, Sybase, Greenplum, Informix, H2, Firebird le maemo a mang a database a maru, mohlala, Redshift, le Azure, joalo-joalo Likarolo tse teng: khokahano ea database le lifaele, phetisetso ea database ea li-multi-master, khokahano e tlhotliloeng, phetoho le tse ling. Sena ke sesebelisoa sa Java 'me se hloka tokollo e tloaelehileng ea JRE kapa JDK (mofuta oa 8.0 kapa ho feta). Mona, liphetoho tsa data ho li-triggers ho database ea mohloli li ka tlalehoa 'me tsa romelloa ho database e nepahetseng ea sepheo ka mokhoa oa lihlopha.

Likarolo tsa SymmetricDS

Sesebelisoa ke sethala se ikemetseng, ho bolelang hore li-database tse peli kapa ho feta tse fapaneng li ka fapanyetsana data.
Li-database tsa likamano li hokahanngoa ho sebelisoa lirekoto tsa phetoho ea data, ha li-database tse thehiloeng tsamaisong ea lifaele li sebelisa khokahano ea faele.
Ho pheta-pheta ka litsela tse peli ka ho sebelisa mekhoa ea Push le Pull e thehiloeng ho sehlopha sa melao.
Ho fetisoa ha data hoa khoneha ka marang-rang a sireletsehileng le a tlaase.
Ho hlaphoheloa ka tsela e iketsang ha li-node li qala ts'ebetso ka mor'a ho hloleha le ho rarolla likhohlano ka boiketsetso.
Li-API tse tsamaisanang le Cloud le tse matla.

Mohlala:

SymmetricDS e ka hlophisoa ka e 'ngoe ea litsela tse peli:
Node e kholo (motsoali) e hokahanyang ho pheta-pheta ha data pakeng tsa li-node tse peli tsa lekhoba (ngoana), 'me puisano pakeng tsa li-node tsa bana e etsahala feela ka motsoali.
Node e sebetsang (Node 1) e ka buisana bakeng sa ho pheta-pheta le node e 'ngoe e sebetsang (Node 2) ntle le mokena-lipakeng.

Likhethong tseo ka bobeli, phapanyetsano ea data e etsahala ho sebelisoa Push le Hula. Mohlaleng ona re tla nahana ka tlhophiso e sebetsang e sebetsang. Ho ka nka nako e telele haholo ho hlalosa meralo eohle, kahoo etsa lipatlisiso tsa hau. tsamaisoho ithuta haholoanyane ka sesebelisoa sa SymmetricDS.

Ho kenya SymmetricDS ho bonolo haholo: khoasolla mofuta o bulehileng oa faele ea zip ho tloha mona mme o e ntshe hohle moo o batlang. Tafole e ka tlase e fana ka leseli mabapi le sebaka sa ho kengoa le mofuta oa SymmetricDS mohlaleng ona, hammoho le liphetolelo tsa database, liphetolelo tsa Linux, liaterese tsa IP, le likou tsa li-node ka bobeli.

Moamoheli
vm1
vm2

Phetolelo ea OS
CentOS Linux 7.6 x86_64
CentOS Linux 7.6 x86_64

Mofuta oa seva oa DB
MySQL 5.7.26
PostgreSQL 10.5

DB boema-kepe
3306
5832

Aterese ea IP
192.168.1.107
192.168.1.112

Mofuta oa SymmetricDS
SymmetricDS 3.9
SymmetricDS 3.9

Tsela ea ho kenya SymmetricDS
/usr/local/symmetric-server-3.9.20
/usr/local/symmetric-server-3.9.20

SymmetricDS lebitso la node
corp-000
lebenkele-001

Mona re kenya SymmetricDS ho /usr/local/symmetric-server-3.9.20, 'me li-subdirectories le lifaele tse fapaneng li tla bolokoa moo. Re thahasella mehlala le likaroloana tsa lienjine. Sengoloa sa lisampole se na le lifaele tsa tlhophiso tse nang le thepa ea node, hammoho le mohlala oa mangolo a SQL ho u qalisa kapele.

Bukeng ea sampole re bona lifaele tse tharo tsa tlhophiso tse nang le thepa ea node - lebitso le bonts'a mofuta oa node ka morero o itseng.

corp-000.properties
store-001.properties
store-002.properties

SymmetricDS e na le lifaele tsohle tse hlokahalang tsa tlhophiso bakeng sa moralo oa mantlha oa 3-node (khetho ea 1), 'me lifaele tse tšoanang li ka sebelisoa bakeng sa moralo oa 2-node (khetho ea 2). Kopitsa faele ea tlhophiso e hlokahalang ho tsoa bukeng ea lisampole ho ea ho lienjineri tse ho moamoheli oa vm1. E shebahala tjena:

$> cat engines/corp-000.properties
engine.name=corp-000
db.driver=com.mysql.jdbc.Driver
db.url=jdbc:mysql://192.168.1.107:3306/replica_db?autoReconnect=true&useSSL=false
db.user=root
db.password=admin123
registration.url=
sync.url=http://192.168.1.107:31415/sync/corp-000
group.id=corp
external.id=000

Node ena ho tlhophiso ea SymmetricDS e bitsoa corp-000, mme khokahano ea database e sebetsoa ke mokhanni oa mysql jdbc, ea sebelisang khoele ea khokahano e kaholimo le lintlha tsa ho kena. Re hokela ho replica_db database mme litafole li tla etsoa nakong ea ho theha schema. sync.url e bonts'a moo u ka ikopanyang le node bakeng sa kamahanyo.

Node 2 ho host vm2 e hlophisitsoe joalo ka lebenkele-001 'me tse ling kaofela li hlalositsoe ho file ea node.properties e ka tlase. Node store-001 e tsamaisa database ea PostgreSQL 'me pgdb_replica ke polokelo ea boitsebiso. registration.url e lumella host vm2 ho ikopanya le moamoheli vm1 le ho fumana lintlha tsa tlhophiso ho tsoa ho eona.

$> cat engines/store-001.properties
engine.name=store-001
db.driver=org.postgresql.Driver
db.url=jdbc:postgresql://192.168.1.112:5832/pgdb_replica
db.user=postgres
db.password=admin123
registration.url=http://192.168.1.107:31415/sync/corp-000
group.id=store
external.id=001

Mohlala o phethiloeng oa SymmetricDS o na le liparamente tsa ho theha phetisetso ea litsela tse peli lipakeng tsa li-server tse peli tsa database (node ​​tse peli). Mehato e ka tlase e etsoa ho moamoheli vm1 (corp-000), e tla etsa mohlala oa schema ka litafole tse 4. Ebe o tsamaisa litafole tsa "sym-sym" ka taelo ea symadmin e theha litafole tsa directory moo melao le tataiso ea ho pheta-pheta lipakeng tsa li-node li tla bolokoa. Qetellong, data ea mohlala e kenngoa litafoleng.

vm1$> cd /usr/local/symmetric-server-3.9.20/bin
vm1$> ./dbimport --engine corp-000 --format XML create_sample.xml
vm1$> ./symadmin --engine corp-000 create-sym-tables
vm1$> ./dbimport --engine corp-000 insert_sample.sql

Mohlala, litafole tsa thepa le item_selling_price li hlophisitsoe ka bo eona hore li ka ikatisetsa ho tloha ho corp-000 ho isa ho store-001, 'me litafole tsa thekiso (sale_transaction and sale_return_line_item) li hlophisoa ka bo eona hore li ka ikatisetsa ho tloha ho store-001 ho isa ho corp-000. Hona joale re theha schema polokelong ea polokelo ea PostgreSQL ho host vm2 (store-001) ho e lokisa ho fumana data ho tsoa ho corp-000.

vm2$> cd /usr/local/symmetric-server-3.9.20/bin
vm2$> ./dbimport --engine store-001 --format XML create_sample.xml

Etsa bonnete ba ho hlahloba hore database ea MySQL ho vm1 e na le litafole tsa mohlala le litafole tsa lethathamo la SymmetricDS. Hlokomela hore litafole tsa SymmetricDS system (prefixed with sym_) li fumaneha feela ho node corp-000 hobane ke moo re mametseng taelo ea li-sym-tables mme re tla be re laola phetisetso. 'Me polokelong ea polokelo ea node-001 ho tla ba le litafole tse 4 feela tsa mohlala ntle le data.

Tsohle. Tikoloho e se e loketse ho tsamaisa lits'ebetso tsa sym server ho li-node ka bobeli joalo ka ha ho bonts'itsoe ka tlase.

vm1$> cd /usr/local/symmetric-server-3.9.20/bin
vm1$> sym 2>&1 &

Maikutlo a li-log a romelloa ho faele ea log e ka morao (symmetric.log) ka har'a foldara ea li-log bukeng eo SymmetricDS e kentsoeng ho eona, hammoho le tlhahiso e tloaelehileng. Seva ea sym joale e ka qalisoa ho node store-001.

vm2$> cd /usr/local/symmetric-server-3.9.20/bin
vm2$> sym 2>&1 &

Haeba o tsamaisa ts'ebetso ea seva ea sym ho moamoheli oa vm2, e tla boela e thehe litafole tsa lethathamo la SymmetricDS polokelong ea polokelo ea PostgreSQL. Haeba o tsamaisa ts'ebetso ea seva ea sym ho li-node ka bobeli, li hokahana ho pheta-pheta data ho tloha corp-000 ho boloka-001. Haeba ka mor'a metsotsoana e seng mekae re botsa litafole tsohle tse 4 mahlakoreng ka bobeli, re tla bona hore phetisetso e atlehile. Kapa o ka romela bootstrap ho node store-001 ho tloha corp-000 ka taelo e latelang.

vm1$> ./symadmin --engine corp-000 reload-node 001

Mothating ona, rekoto e ncha e kentsoe ka har'a tafole ea thepa ho database ea MySQL ho node corp-000 (moamoheli: vm1), mme o ka lekola phetiso ea eona ho database ea PostgreSQL ho node store-001 (host: vm2). Re bona ts'ebetso ea Pull ho tsamaisa data ho tloha corp-000 ho ea ho store-001.

mysql> insert into item values ('22000002','Jelly Bean');
Query OK, 1 row affected (0.00 sec)

vm2$> psql -p 5832 -U postgres pgdb_replica -c "select * from item"
 item_id  |   name
----------+-----------
 11000001 | Yummy Gum
 22000002 | Jelly Bean
(2 rows)

Ho etsa ts'ebetso ea Push ho tlosa data ho tloha store-001 ho ea ho corp-000, re kenya rekoto ho sale_transaction table, 'me re netefatsa hore phetisetso e atlehile.

Phello.

Re bona ho hlophisoa ka katleho ha mekhoa e 'meli ea phetisetso ea litafole tsa mohlala lipakeng tsa database tsa MySQL le PostgreSQL. Ho theha phetisetso bakeng sa litafole tse ncha tsa basebelisi, latela mehato ena: Re theha tafole t1 ka mohlala mme re hlophisa melao ea eona ea ho ikatisa ka tsela e latelang. Ka tsela ena re hlophisa phetiso feela ho tloha ho corp-000 ho isa ho store-001.

mysql> create table  t1 (no integer);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into sym_channel (channel_id,create_time,last_update_time) 
values ('t1',current_timestamp,current_timestamp);
Query OK, 1 row affected (0.01 sec)

mysql> insert into sym_trigger (trigger_id, source_table_name,channel_id,
last_update_time, create_time) values ('t1', 't1', 't1', current_timestamp,
current_timestamp);
Query OK, 1 row affected (0.01 sec)

mysql> insert into sym_trigger_router (trigger_id, router_id,
Initial_load_order, create_time,last_update_time) values ('t1',
'corp-2-store-1', 1, current_timestamp,current_timestamp);
Query OK, 1 row affected (0.01 sec)

Tlhophiso e tsebisoa ka phetoho ea schema, ke hore, ho eketsoa ha tafole e ncha, ho sebelisoa taelo ea symadmin ka khang ea sync-triggers, e khutlisetsang lintho tse susumetsang ho etsa 'mapa oa litlhaloso tsa tafole. send-schema e etsoa ho romella liphetoho tsa schema lebenkeleng la node-001, 'me phetisetso ea tafole t1 e lokiselitsoe.

vm1$> ./symadmin -e corp-000 --node=001 sync-triggers    
vm1$> ./symadmin send-schema -e corp-000 --node=001 t1

Melemo ea SymmetricDS

Ho kenya habonolo le ho hlophisoa, ho kenyelletsa le sete e lokiselitsoeng ea lifaele tse nang le litekanyetso tsa ho theha potoloho ea li-node tse tharo kapa tse peli.
Mananeo a marang-rang a marang-rang le boikemelo ba sethala, ho kenyeletsoa li-server, lilaptop le lisebelisoa tsa mehala.
Pheta database efe kapa efe ho database efe kapa efe sebakeng sa heno, ho WAN kapa marung.
Monyetla oa mosebetsi o nepahetseng ka li-database tse 'maloa kapa likete tse' maloa bakeng sa ho ikatisetsa habonolo.
Mofuta o lefelloang o nang le GUI le tšehetso e ntle haholo.

Mefokolo ea SymmetricDS

U hloka ho hlalosa ka letsoho melao le tataiso ea ho pheta-pheta molaong oa taelo ka lipolelo tsa SQL ho kenya litafole tsa lethathamo la libuka, tse ka bang khathatso.
Ho theha litafole tse ngata bakeng sa ho pheta-pheta ho ka ba ntho e tenang ntle le haeba u sebelisa mangolo ho etsa lipolelo tsa SQL tse hlalosang melao le tataiso ea ho pheta-pheta.
Ho na le tlhahisoleseding e ngata haholo e tlalehiloeng ka har'a li-log, 'me ka linako tse ling u lokela ho hlophisa faele ea log e le hore e se ke ea nka sebaka se sengata.

Liphetho tsa SymmetricDS

SymmetricDS e u lumella ho theha katoloso ea litsela tse peli lipakeng tsa li-node tse peli, tse tharo, kapa tse likete tse 'maloa ho hatisa le ho hokahanya lifaele. Ena ke sesebelisoa se ikhethang se ikemetseng se etsang mesebetsi e mengata, e kang ho hlaphoheloa ha data ka mokhoa o itekanetseng ka mor'a nako e telele ea nako e telele ho node, phapanyetsano e sireletsehileng le e sebetsang hantle ea data pakeng tsa li-node ka HTTPS, tsamaiso ea likhohlano e ikemetseng e thehiloeng melaong ea melao, joalo-joalo SymmetricDS e etsa joalo. Ho pheta-pheta lipakeng tsa li-database life kapa life, ka hona, e ka sebelisoa bakeng sa maemo a fapaneng a fapaneng, ho kenyeletsoa ho falla, ho falla, ho ajoa, ho sefa, le phetoho ea data ho pholletsa le sethala.

Mohlala o thehiloe holim'a ofisiri tataiso e potlakileng ka SymmetricDS. IN bukana ya mosebedisi E hlalosa ka ho qaqileng mehopolo e fapaneng e amehang ho theha boikatiso le SymmetricDS.

Source: www.habr.com

Eketsa ka tlhaloso