๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’ปTech/๐ŸฌMySQL

[MariaDB] Replication ๊ธฐ๋Šฅ ์ ์šฉ ๋ฐฉ๋ฒ•

by _viper_ 2021. 4. 20.
๋ฐ˜์‘ํ˜•

MariaDB Replication ๊ธฐ๋Šฅ์€ DB ๋ฐ์ดํ„ฐ ๋ฐฑ์—… ์šฉ๋„๋กœ ์‚ฌ์šฉ (์ด์ค‘ํ™”๊ฐ€ ์•„๋‹˜)

 

1. Master ์„œ๋ฒ„

1) mariaDB stop & DB ๋ฐฑ์—…

$ systemctl stop mariadb
$ mysqldump -uroot -p hue > hue.sql

 

2) server.cnf ์„ค์ • ์ถ”๊ฐ€

vi /etc/my.conf.d/server.cnf
-----------------------------
[mysqld]
log_bin=mysql-bin
server-id=1
-----------------------------

 

3) systemctl start mariadb

 

4) mysql ์ ‘์† ํ›„ ์•„๋ž˜ ๋ช…๋ น์–ด ์‹คํ–‰

> GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO repl@'%' identified by 'Password'

 

5) slave ์„œ๋ฒ„์— ์ž…๋ ฅํ•  file, position ํ™•์ธ

  • ํ•ด๋‹น ์ •๋ณด slave ์„ค์ •์—์„œ ์‚ฌ์šฉ
> show master status;

 

2. Slave ์„œ๋ฒ„

1) mariaDB stop & ๋ฐฑ์—… DB ์—…๋กœ๋“œ

$ systemctl stop mariadb
$ mysql -uroot -p hue < hue.sql

 

2) server.cnf ์„ค์ • ์ถ”๊ฐ€

$ vi /etc/my.conf.d/server.cnf
-------------------------------
[mysqld]
log_bin=mysql-bin
server-id=2
relay_log=mysql-relay-bin
log_slave_updates=1
read_only=1
-------------------------------

 

3) systemctl start mariadb

 

4) mysql ์ ‘์† ํ›„ ์•„๋ž˜ ๋ช…๋ น์–ด ์‹คํ–‰

> CHANGE MASTER TO MASTER_HOST='127.x.x.x', MASTER_USER='repl', MASTER_PASSWORD='Password',
   MASTER_PORT=3306, MASTER_LOG_FILE='mysql-bin.000001',
   MASTER_LOG_POS=328,  MASTER_CONNECT_RETRY=10;
> start slave;
> show slave status;

 

3. ์„ค์ • ํ›„ ๋ฐ์ดํ„ฐ ๋™๊ธฐํ™” ํ™•์ธ