doc:appunti:linux:sa:mysql_replica_master_master
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
doc:appunti:linux:sa:mysql_replica_master_master [2011/09/08 12:48] – created niccolo | doc:appunti:linux:sa:mysql_replica_master_master [2025/03/12 15:03] (current) – [Verifica dello stato SLAVE] niccolo | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== MySQL replica master-master ====== | ====== MySQL replica master-master ====== | ||
+ | |||
+ | Riferimenti web: | ||
+ | |||
+ | * **[[http:// | ||
+ | * **[[http:// | ||
+ | |||
+ | ===== Configurare la replica master-master ===== | ||
+ | |||
+ | Con questa configurazione si tiene replicato **un solo database**. | ||
+ | |||
+ | < | ||
+ | -- Su server1 | ||
+ | GRANT REPLICATION SLAVE ON *.* TO ' | ||
+ | FLUSH PRIVILEGES; | ||
+ | |||
+ | CREATE DATABASE exampledb; | ||
+ | CONNECT exampledb; | ||
+ | |||
+ | CREATE TABLE clienti ( | ||
+ | id INTEGER NOT NULL AUTO_INCREMENT, | ||
+ | name CHAR(100), | ||
+ | PRIMARY KEY (id) | ||
+ | ) ENGINE=INNODB; | ||
+ | |||
+ | CREATE TABLE fatture ( | ||
+ | id INTEGER NOT NULL AUTO_INCREMENT, | ||
+ | cliente_id INTEGER, | ||
+ | PRIMARY KEY (id), | ||
+ | FOREIGN KEY (cliente_id) REFERENCES clienti(id) | ||
+ | ) ENGINE=INNODB; | ||
+ | |||
+ | SHOW TABLE STATUS; | ||
+ | |||
+ | INSERT INTO clienti (name) VALUES (' | ||
+ | INSERT INTO fatture (cliente_id) VALUES (1); | ||
+ | DELETE FROM clienti; | ||
+ | |||
+ | vi / | ||
+ | # Vedere la man page di my.cnf, che non esiste. | ||
+ | / | ||
+ | |||
+ | -- Su server2 | ||
+ | GRANT REPLICATION SLAVE ON *.* TO ' | ||
+ | FLUSH PRIVILEGES; | ||
+ | |||
+ | vi / | ||
+ | # Vedere la man page di my.cnf, che non esiste. | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | Per vedere se si sono assegnati i permessi di replica: | ||
+ | |||
+ | < | ||
+ | SHOW GRANTS FOR ' | ||
+ | </ | ||
+ | |||
+ | Ovviamente è opportuno concedere i grant non dall' | ||
+ | ===== Sincronizzare il db ===== | ||
+ | |||
+ | < | ||
+ | -- Su server1 | ||
+ | USE exampledb; | ||
+ | FLUSH TABLES WITH READ LOCK; | ||
+ | SHOW MASTER STATUS; | ||
+ | -- Prendere nota dello status. | ||
+ | -- Fare un dump e copiarlo sull' | ||
+ | UNLOCK TABLES; | ||
+ | |||
+ | -- Su server2 | ||
+ | -- mysqladmin --user=root --password stop-slave | ||
+ | CREATE DATABASE exampledb; | ||
+ | -- mysql -u root -p exampledb < exampledb.sql | ||
+ | USE exampledb; | ||
+ | FLUSH TABLES WITH READ LOCK; | ||
+ | SHOW MASTER STATUS; | ||
+ | -- Prendere nota dello status. | ||
+ | UNLOCK TABLES; | ||
+ | CHANGE MASTER TO MASTER_HOST=' | ||
+ | MASTER_PASSWORD=' | ||
+ | MASTER_LOG_POS=106; | ||
+ | START SLAVE; | ||
+ | SHOW SLAVE STATUS; | ||
+ | |||
+ | -- Su server1 | ||
+ | STOP SLAVE; | ||
+ | CHANGE MASTER TO MASTER_HOST=' | ||
+ | MASTER_PASSWORD=' | ||
+ | MASTER_LOG_POS=2359; | ||
+ | START SLAVE; | ||
+ | SHOW SLAVE STATUS; | ||
+ | </ | ||
+ | ===== Verifica dello stato SLAVE ===== | ||
+ | |||
+ | Come utente Unix root ci si collega al database MASTER/ | ||
+ | |||
+ | < | ||
+ | mysql dbname | ||
+ | </ | ||
+ | |||
+ | Per vedere lo stato di slave: | ||
+ | |||
+ | <code sql> | ||
+ | SHOW STATUS LIKE ' | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | +---------------+-------+ | ||
+ | | Variable_name | Value | | ||
+ | +---------------+-------+ | ||
+ | | Slave_running | ON | | ||
+ | +---------------+-------+ | ||
+ | </ | ||
+ | |||
+ | Per verificare lo stato di slave e in particolare il numero di log in corso di replica (**Relay_Master_Log_File**): | ||
+ | |||
+ | <code sql> | ||
+ | SHOW SLAVE STATUS\G; | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | MariaDB [dbname]> | ||
+ | *************************** 1. row *************************** | ||
+ | | ||
+ | Master_Host: | ||
+ | Master_User: | ||
+ | Master_Port: | ||
+ | Connect_Retry: | ||
+ | Master_Log_File: | ||
+ | Read_Master_Log_Pos: | ||
+ | | ||
+ | Relay_Log_Pos: | ||
+ | Relay_Master_Log_File: | ||
+ | | ||
+ | Slave_SQL_Running: | ||
+ | Replicate_Do_DB: | ||
+ | Replicate_Ignore_DB: | ||
+ | | ||
+ | | ||
+ | Replicate_Wild_Do_Table: | ||
+ | Replicate_Wild_Ignore_Table: | ||
+ | | ||
+ | | ||
+ | | ||
+ | Exec_Master_Log_Pos: | ||
+ | Relay_Log_Space: | ||
+ | Until_Condition: | ||
+ | | ||
+ | Until_Log_Pos: | ||
+ | | ||
+ | | ||
+ | | ||
+ | Master_SSL_Cert: | ||
+ | Master_SSL_Cipher: | ||
+ | | ||
+ | Seconds_Behind_Master: | ||
+ | Master_SSL_Verify_Server_Cert: | ||
+ | Last_IO_Errno: | ||
+ | Last_IO_Error: | ||
+ | | ||
+ | | ||
+ | Replicate_Ignore_Server_Ids: | ||
+ | | ||
+ | </ | ||
+ | |||
+ | Se **durante la sincronizzazione uno statement fallisce** si vede l' | ||
+ | |||
+ | <code sql> | ||
+ | STOP SLAVE; | ||
+ | SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; | ||
+ | START SLAVE; | ||
+ | </ | ||
===== Crash test ===== | ===== Crash test ===== |
doc/appunti/linux/sa/mysql_replica_master_master.1315478898.txt.gz · Last modified: 2011/09/08 12:48 by niccolo