티스토리 뷰

Master server

$ mysql -uroot -p

mysql> GRANT REPLICATION SLAVE ON *.* to 'repl'@'172.%' IDENTIFIED BY 'repl-password-here';

mysql> flush tables with read lock;

mysql> reset master;

# Make note of the file name and file position

mysql> show master status;

$ /etc/init.d/mysql stop

$ xfs_freeze -f /mnt/mysql

# Take AWS EC2 EBS snapshot and when it begins do next step

$ xfs_freeze -u /mnt/mysql

$ /etc/init.d/mysql start

$ mysql -uroot -p

mysql> unlock tables;

Wait for WAS to finish writing the EBS snapshot before proceeding.


Slave server

  1. EBS snapshot is complete
  2. create a new volume from snapshot
  3. umount old volume
  4. umount /data
  5. Detach "/data" volume
  6. Attach new "/data" volume
  7. mount /data
  8. lsblk
  9. sudo dd if=/dev/xvdX of=/dev/null bs=1M
  10. syncing to the master

$ /etc/init.d/mysql start

$ mysql -uroot -p

mysql> CHANGE MASTER TO

 MASTER_HOST='172.x.x.x',

 MASTER_USER='repl',

 MASTER_PASSWORD='repl-password-here',

 MASTER_LOG_FILE = 'mysql-bin.000001',

 MASTER_LOG_POS = 107;

mysql> start slave;

mysql> show slave status \G


Reference

  • https://jrklein.com/2017/03/22/mysql-master-slave-replication-on-aws-ec2-ebs/
  • https://www.tecmint.com/mariadb-master-slave-replication-on-centos-rhel-debian/


댓글