Skip to content

Instantly share code, notes, and snippets.

@thuyhiend
Last active May 19, 2020 12:03
Show Gist options
  • Save thuyhiend/6c4e68fc2d2fb10b8d55c476e6ae49bf to your computer and use it in GitHub Desktop.
Save thuyhiend/6c4e68fc2d2fb10b8d55c476e6ae49bf to your computer and use it in GitHub Desktop.
Cấu hình Replication 3 master
```
## Master-1
create database replica_db;
create user 'slave'@'10.10.22.104' identified by 'abc@123';
create user 'slave'@'10.10.22.105' identified by 'abc@123';
grant replication slave on *.* to 'slave'@'10.10.22.104' identified by 'abc@123';
grant replication slave on *.* to 'slave'@'10.10.22.105' identified by 'abc@123';
vi /etc/my.cnf.d/mariadb-server.cnf
[mariadb]
server-id=1
log_bin=master
binlog_format=row
binlog_do_db=replica_db
systemctl restart mariadb
mysqldump --all-databases --user=root --password --master-data > masterdatabase.sql
scp masterdatabase.sql [email protected]:/root/masterdatabase.sql
scp masterdatabase.sql [email protected]:/root/masterdatabase.sql
show master status;
## Master-2
create database test;
create user 'slave'@'10.10.22.103' identified by 'abc@123';
create user 'slave'@'10.10.22.105' identified by 'abc@123';
grant replication slave on *.* to 'slave'@'10.10.22.103' identified by 'abc@123';
grant replication slave on *.* to 'slave'@'10.10.22.105' identified by 'abc@123';
vi /etc/my.cnf.d/mariadb-server.cnf
[mariadb]
server-id=2
log_bin=master
binlog_format=row
binlog_do_db=test
systemctl restart mariadb
mysqldump --all-databases --user=root --password --master-data > masterdatabase.sql2
scp masterdatabase.sql2 [email protected]:/root/masterdatabase.sql2
scp masterdatabase.sql2 [email protected]:/root/masterdatabase.sql2
show master status;
## Master-3
create database demo;
create user 'slave'@'10.10.22.103' identified by 'abc@123';
create user 'slave'@'10.10.22.104' identified by 'abc@123';
grant replication slave on *.* to 'slave'@'10.10.22.103' identified by 'abc@123';
grant replication slave on *.* to 'slave'@'10.10.22.104' identified by 'abc@123';
vi /etc/my.cnf.d/mariadb-server.cnf
[mariadb]
server-id=3
log_bin=master
binlog_format=row
binlog_do_db=demo
systemctl restart mariadb
mysqldump --all-databases --user=root --password --master-data > masterdatabase.sql3
scp masterdatabase.sql3 [email protected]:/root/masterdatabase.sql3
scp masterdatabase.sql3 [email protected]:/root/masterdatabase.sql3
show master status;
## Master-1
change master 'master-2' to master_host='10.10.22.104', master_user='slave', master_password='abc@123', master_log_file='master.000001', master_log_pos=325;
change master 'master-3' to master_host='10.10.22.105', master_user='slave', master_password='abc@123', master_log_file='master.000001', master_log_pos=325;
## Master-2
change master 'master-1' to master_host='10.10.22.103', master_user='slave', master_password='abc@123', master_log_file='master.000001', master_log_pos=325;
change master 'master-3' to master_host='10.10.22.105', master_user='slave', master_password='abc@123', master_log_file='master.000001', master_log_pos=325;
## Master-3
change master 'master-1' to master_host='10.10.22.103', master_user='slave', master_password='abc@123', master_log_file='master.000001', master_log_pos=325;
change master 'master-2' to master_host='10.10.22.104', master_user='slave', master_password='abc@123', master_log_file='master.000001', master_log_pos=325;
## Master-1
mysql -u root -p < /root/masterdatabase.sql2
mysql -u root -p < /root/masterdatabase.sql3
start slave 'master-2';
start slave 'master-3';
## Master-2
mysql -u root -p < /root/masterdatabase.sql
mysql -u root -p < /root/masterdatabase.sql3
start slave 'master-1';
start slave 'master-3';
## Master-3
mysql -u root -p < /root/masterdatabase.sql
mysql -u root -p < /root/masterdatabase.sql2
start slave 'master-1';
start slave 'master-2';
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment