Vous êtes sur la page 1sur 7

Comment configurer la réplication Symetrique

Synchrone MySQL

Dr SARR Edouard Ngor


UASZ

Ce TP explique comment installer et configurer la réplication symetrique synchrone


sous MySQL. En effet, la réplication MySQL est une solution qui peut garantir une
politique de haute disponibilité. En plus de cela, la réplication MySQL est également
capable d'aider les administrateurs de base de données à répartir la charge sur
plusieurs serveurs de base de données en équilibrant la charge des requêtes READ et
WRITE. Malheureusement, la réplication de base ne peut offrir des avantages que
sur les requêtes READ. Pour cette raison, la réplication multi-maître synchrone
MySQL a été introduite pour offrir également la réplication pour les requêtes WRITE.

Phase de configuration du Serveur DB1 en tant que


Master de DB2
Allons dans le fichier de configuration MySQL my.cnf et apportons les modifications
comme ci-dessous sur le serveur DB1.

server-id = 11
log_bin = mysql/log/mysql-bin.log
binlog_do_db = test_rep

Voici l'explication de la configuration:


• server-id ==> L'ID de réplication
• log_bin ==> Le fichier journal à utiliser pour l'activité de réplication
• binlog_do_db ==> La base de données liée au processus de réplication

Une fois cela fait, allons dans l'environnement du serveur MySQL et créons la base
de données associée et affectons un utilisateur pour le processus de réplication.

mysql> create database test_rep;


Query OK, 1 row affected (0.01 sec)

mysql> create user 'replicator'@'DB2' identified by 'Rep1234';


Query OK, 0 rows affected (0.01 sec)
mysql> grant replication slave on *.* to 'replicator'@'DB2';
Query OK, 0 rows affected (0.00 sec)

Terminé, redémarrez maintenant le serveur MySQL et voyez si la configuration a été


activée ou non. Voici les étapes:

mysql> show master status;


+-------------------+----------+--------------+------------------+---------
----------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+---------
----------+
| mysql-bin.000001 | 854 | test_rep | | |
+-------------------+----------+--------------+------------------+---------
----------+
1 row in set (0.00 sec)

Configuration du Serveur DB2 en tant que Slave de DB1


puis DB2 en tant que Master de DB1

Excellent, maintenant configurons le serveur DB2 en tant que serveur esclave pour le
maître de réplication DB1 et, en plus de cela, configurons le serveur DB2 également
en tant que maître pour le serveur DB1. Voici les étapes:

server-id = 12
log_bin = mysql/log/mysql-bin.log
binlog_do_db = test_rep

Identique à la configuration dans DB1, allons à l'intérieur de l'environnement du


serveur MySQL et créons la base de données associée et affectons un utilisateur pour
le processus de réplication.

mysql> create database test_rep;


Query OK, 1 row affected (0.01 sec)

mysql> create user 'replicator'@'DB1' identified by 'Rep1234';


Query OK, 0 rows affected (0.01 sec)

mysql> grant replication slave on *.* to 'replicator'@'DB1';


Query OK, 0 rows affected (0.00 sec)

mysql> show slave status;


Empty set (0.01 sec)

C'est fait, redémarrons maintenant le serveur DB2 MySQL et voyons si la


configuration a été activée ou non. Si oui, nous continuons à créer l'esclave pour le
serveur DB1. Publicité
mysql> show master status;
+-------------------+----------+--------------+------------------+---------
----------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+---------
----------+
| mysql-bin.000001 | 553 | test_rep | | |
+-------------------+----------+--------------+------------------+---------
----------+
1 row in set (0.00 sec)

mysql> stop slave;


Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> CHANGE MASTER TO MASTER_HOST = 'IP de DB1', MASTER_PORT = 3306, MAST


ER_USER = 'replicator', MASTER_PASSWORD = 'Rep1234', MASTER_LOG_FILE = 'mys
ql-bin.000001', MASTER_LOG_POS = 854;
Query OK, 0 rows affected, 2 warnings (0.07 sec)

mysql> start slave;


Query OK, 0 rows affected (0.04 sec)

mysql> show slave status\G;


*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: DB1
Master_User: replicator
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 854
Relay_Log_File: mysqld-relay-bin.000002
Relay_Log_Pos: 284
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 854
Relay_Log_Space: 459
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 11
Master_UUID: 6e143d91-3635-11e7-b9ad-08002742c04c
Master_Info_File: /var/lib/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slav
e I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec)

ERROR:
No query specified

mysql> show slave status;


+----------------------------------+---------------+-------------+---------
----+---------------+-------------------+---------------------+------------
--------------+---------------+-----------------------+------------------+-
------------------+-----------
| Slave_IO_State | Master_Host | Master_User | Master_Port | Connect_Retry
| Master_Log_File | Read_Master_Log_Pos | Relay_Log_File | Relay_Log_Pos |
Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do
_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | R
eplicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Er
ror | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Conditio
n | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_Fil
e | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_K
ey | Seconds_Behind_Master | Master_SSL_Verify_Server_Cert | Last_IO_Errno
| Last_IO_Error | Last_SQL_Errno | Last_SQL_Error | Replicate_Ignore_Server
_Ids | Master_Server_Id | Master_UUID | Master_Info_File | SQL_Delay | SQL_
Remaining_Delay | Slave_SQL_Running_State | Master_Retry_Count | Master_Bin
d | Last_IO_Error_Timestamp | Last_SQL_Error_Timestamp | Master_SSL_Crl | M
aster_SSL_Crlpath | Retrieved_Gtid_Set | Executed_Gtid_Set | Auto_Position
|
+----------------------------------+---------------+-------------+---------
----+---------------+-------------------+---------------------+------------
--------------+---------------+-----------------------+------------------+-
------------------+-----------
| Waiting for master to send event | DB1 | replicator | 3306 | 60 | mysql-b
in.000001 | 854 | mysqld-relay-bin.000002 | 284 | mysql-bin.000001 | Yes |
Yes | | | | | | | 0 | | 0 | 854 | 459 | None | | 0 | No | | | | | | 0 | No
| 0 | | 0 | | | 11 | 6e143d91-3635-11e7-b9ad-08002742c04c | /var/lib/mysql/
master.info | 0 | NULL | Slave has read all relay log; waiting for the slav
e I/O thread to update it | 86400 | | | | | | | | 0 |
+----------------------------------+---------------+-------------+---------
----+---------------+-------------------+---------------------+------------
--------------+---------------+-----------------------+------------------+-
------------------+-----------
1 row in set (0.00 sec)

Configuration du Serveur DB1 en tant que Slave de DB2

Comme tout a été configuré pour le serveur DB2, revenons au serveur DB1 et
effectuez la configuration esclave du serveur DB2.

mysql> show master status;


+-------------------+----------+--------------+------------------+---------
----------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+---------
----------+
| mysql-bin.000001 | 854 | test_rep | | |
+-------------------+----------+--------------+------------------+---------
----------+
1 row in set (0.01 sec)

mysql> stop slave;


Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> CHANGE MASTER TO MASTER_HOST = 'DB2', MASTER_PORT = 3306, MASTER_USE


R = 'replicator', MASTER_PASSWORD = 'Rep1234', MASTER_LOG_FILE = 'mysql-bin
.000001', MASTER_LOG_POS = 553;
Query OK, 0 rows affected, 2 warnings (0.25 sec)

mysql> start slave;


Query OK, 0 rows affected (0.03 sec)

mysql> show slave status;


+----------------------------------+---------------+-------------+---------
----+---------------+-------------------+---------------------+------------
--------------+---------------+-----------------------+------------------+-
------------------+-----------
| Slave_IO_State | Master_Host | Master_User | Master_Port | Connect_Retry
| Master_Log_File | Read_Master_Log_Pos | Relay_Log_File | Relay_Log_Pos |
Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do
_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | R
eplicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Er
ror | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Conditio
n | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_Fil
e | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_K
ey | Seconds_Behind_Master | Master_SSL_Verify_Server_Cert | Last_IO_Errno
| Last_IO_Error | Last_SQL_Errno | Last_SQL_Error | Replicate_Ignore_Server
_Ids | Master_Server_Id | Master_UUID | Master_Info_File | SQL_Delay | SQL_
Remaining_Delay | Slave_SQL_Running_State | Master_Retry_Count | Master_Bin
d | Last_IO_Error_Timestamp | Last_SQL_Error_Timestamp | Master_SSL_Crl | M
aster_SSL_Crlpath | Retrieved_Gtid_Set | Executed_Gtid_Set | Auto_Position
|
+----------------------------------+---------------+-------------+---------
----+---------------+-------------------+---------------------+------------
--------------+---------------+-----------------------+------------------+-
------------------+-----------
| Waiting for master to send event | DB2 | replicator | 3306 | 60 | mysql-b
in.000001 | 553 | mysqld-relay-bin.000002 | 284 | mysql-bin.000001 | Yes |
Yes | | | | | | | 0 | | 0 | 553 | 459 | None | | 0 | No | | | | | | 0 | No
| 0 | | 0 | | | 12 | 14f5ab41-3c7b-11e7-a293-08002742c04c | /var/lib/mysql/
master.info | 0 | NULL | Slave has read all relay log; waiting for the slav
e I/O thread to update it | 86400 | | | | | | | | 0 |
+----------------------------------+---------------+-------------+---------
----+---------------+-------------------+---------------------+------------
--------------+---------------+-----------------------+------------------+-
------------------+-----------
1 row in set (0.01 sec)

mysql> show slave status\G;


*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: DB2
Master_User: replicator
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 553
Relay_Log_File: mysqld-relay-bin.000002
Relay_Log_Pos: 284
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 553
Relay_Log_Space: 459
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 12
Master_UUID: 14f5ab41-3c7b-11e7-a293-08002742c04c
Master_Info_File: /var/lib/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slav
e I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec)

ERROR:
No query specified

Maintenant que tout est prêt en place, passons à la phase de test pour conclure que
toute la configuration a été effectuée correctement.

Phase de test
Avant de commencer le test, faisons les hypothèses pour les attentes de résultat
final. Pour ce test, nous allons créer une table sur le serveur DB1 MySQL puis sur
DB2 nous vérifierons si la table existe automatiquement ou non. Si oui, nous y
ajouterons une nouvelle ligne de données et vérifierons à nouveau sur le serveur
DB1 si de nouvelles données sont disponibles sur les deux serveurs.

Vous aimerez peut-être aussi