yoursyun

mariaDB 복제 (replication) 본문

database/mariaDB

mariaDB 복제 (replication)

yoursyun 2020. 12. 4. 10:06

centos7 / mariadb 10.4 기준

 

# 복제 사용자 생성

MariaDB [(none)]> grant replication slave, replication client on *.* to '아이디'@'%' identified by '비밀번호';

MariaDB [(none)]> grant all privileges on visnag.* TO '아이디'@'%';

MariaDB [(none)]> flush privileges;

 

# 서버 아이디 점검

MariaDB [(none)]> show variables like 'server_id';

+---------------+-------+

| Variable_name | Value |

+---------------+-------+

| server_id     | 1     |

+---------------+-------+

1 row in set (0.002 sec)

 

# MASTER 정보를 조회

MariaDB [(none)]> SHOW MASTER STATUS;

+--------------------+----------+--------------+------------------+

| File               | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+--------------------+----------+--------------+------------------+

| mariadb-bin.000001 |      852 |              |                  |

+--------------------+----------+--------------+------------------+

여기서 File Position Slave 설정 시 필요하다.

 

# 운영중인 서버라면 슬레이브 기동전 global lock을 걸어준다.

MariaDB [(none)]> FLUSH TABLES WITH READ LOCK;

* 참고 : global lock 해제 unlock tables;

 

#

# 마스터 설정 끝 슬래이브 설정 시작

#

 

[root@localhost kimsy]# vi /etc/my.cnf.d/server.cnf

[mysqld]

server-id=2

log_bin=/var/log/binlog/mariadb-bin

log_bin_index=/var/log/binlog/mariadb-bin.index

expire_logs_days=3

max_binlog_size=100M

relay_log=/var/log/binlog/relay-bin

relay_log_index=/var/log/binlog/relay-bin.index

relay_log_info_file=/var/log/binlog/relay-bin.info

log_slave_updates

replicate-ignore-db=복제예외 데이터베이스

replicate-ignore-db=performance_schema

replicate-ignore-db=test

replicate-ignore-db=information_schema

replicate-ignore-db=mysql

replicate-do-table=visang.article #복제하고자하는테이블

 

#마리아 재시작

[root@pororicom log]# systemctl start mariadb

 

CHANGE MASTER TO MASTER_HOST='복제하고자하는DB서버아이피', MASTER_USER='아이디', MASTER_PASSWORD='비밀번호',

MASTER_PORT=3306, MASTER_LOG_FILE='mariadb-bin.000001', MASTER_LOG_POS=1053, MASTER_CONNECT_RETRY=3;

flush PRIVILEGES;

start SLAVE;

 

SHOW SLAVE STATUS;

 

Slave_IO_Running : Yes

Slave_SQL_Running : Yes

 

이면 정상 실행되어진 상황이다. 오류가 발생하면 "SHOW SLAVE STATUS;" 의 Last_SQL_Error 컬럼을 참조하도록하자.

반응형