메뉴 건너뛰기

조회 수 6782 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
CentOS 6.2, MySQL 5.5.16에서 테스트했습니다.
먼저 Master-Slave 구조 설정 후에 Master-Master 구조 설정을 추가하였습니다.
 
 
#######################################################################
[ Master - Slave 설정 ]
#######################################################################
: Master에서만 트랜잭션이 가능하고 Master의 변경사항이 Slave로 단방향 동기화 구조
 
##################################
[ Master 설정 ]
##################################
 
1. vi /etc/my.cnf 설정
---------------------------
[mysqld]
# Seting for Replication(Master)
server-id        = 1                          <- 서버 고유아이디, Slave와 다르게 설정
log-bin          = mysql-bin               <- MySQL(오라클의 redo로그와 유사) 로그생성 설정
expire_logs_days = 7                      <- 로그 보관주기 설정(일)
replicate-do-db  = test_db              <- Replication 대상 DB 지정, 이 옵션을 제거시 모든 DB 복제
---------------------------
 
* 참고(binlog_do_db/replicate-do-db 차이)
binlog_do_db : Master 기준 어떤 DB를 Replication 허용할 것인지 설정(제외조건 binlog_ignore_db)
- replicate-do-db : Slave 기준 어떤 DB를 Replication 할 것인지 설정(제외조건 replicate-ignore-db)
 
 
2. mysql restart
service mysql restart
 
3. Master 접속 계정생성 및 Replication 접근 권한설정
---------------------------
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' IDENTIFIED BY 'repl';   <- repl/repl 계정변경가능
mysql> FLUSH PRIVILEGES;
---------------------------
 
4. 데이터 동기화(백업)
---------------------------
mysql> FLUSH TABLES WITH READ LOCK;
mysql> mysqldump -u root -p test_db > backup.sql
mysql> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 |      107 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
 
mysql> UNLOCK TABLES;
---------------------------
 
 
 
##################################
[ Slave 설정 ]
##################################
 
1. 데이터 동기화(복사)
---------------------------
mysql> mysql -u root -p test_db < backup.sql
---------------------------
 
2. vi /etc/my.cnf 설정
---------------------------
[mysqld]
# Seting for Replication(Slave)
server-id        = 2
log-bin          = mysql-bin
expire_logs_days = 7
replicate-do-db  = test_db
---------------------------
 
3. mysql restart
service mysql restart
 
4. Master 접속설정
---------------------------
mysql> CHANGE MASTER TO 
MASTER_HOST='192.168.1.5',                     <- Master IP나 호스트명을 입력
MASTER_USER='repl',                               <- Replication 아이디
MASTER_PASSWORD='repl',                      <- Replication 패스워드
MASTER_PORT=3306,
MASTER_LOG_FILE='mysql-bin.000001',      <- Master의 SHOW MASTER STATUS; 결과화면의 로그파일명 입력
MASTER_LOG_POS=107;                           <- Master의 SHOW MASTER STATUS; 결과화면의 Position 입력
---------------------------
 
5. Slave 시작
---------------------------
#변경의 경우
#stop slave;
#reset slave;
#flush privileges;
 
start slave;
 
 
 
 
 
#######################################################################
[ Master - Master 설정추가 ]
#######################################################################
: 양쪽 노드가 다 Master이면서 Slave인 구조로 양방향 동기화 구조
 
##################################
[ Slave 설정 ]
##################################
: 위 Master-Slave 설정에서 서로 바꾸어 설정을 하면 됨
 
1. 접속 계정생성 및 Replication 접근 권한설정
---------------------------
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' IDENTIFIED BY 'repl';
mysql> FLUSH PRIVILEGES;
---------------------------
 
2. 로그파일과 Position확인
 mysql> SHOW MASTER STATUS;
 
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
mysql-bin.000002 |      322 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
 
 
 
##################################
[ Master 설정 ]
##################################
 
3. Master 접속설정
---------------------------
mysql> CHANGE MASTER TO 
MASTER_HOST='192.168.1.19',                     <- Master IP나 호스트명을 입력
MASTER_USER='repl',                                <- Replication 아이디
MASTER_PASSWORD='repl',                       <- Replication 패스워드
MASTER_PORT=3306,
MASTER_LOG_FILE='mysql-bin.000002',       <- Slave의 SHOW MASTER STATUS; 결과화면의 로그파일명 입력
MASTER_LOG_POS=322;                            <- Slave의 SHOW MASTER STATUS; 결과화면의 Position 입력
 
flush privileges;
 
start slave;
---------------------------
 
4. 동작확인
mysql> SHOW SLAVE STATUS\G
 
양쪽에서 위 명령으로 상태 확인시 아래와 같은 결과시 성공.
 
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.5
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000002
          Read_Master_Log_Pos: 107
               Relay_Log_File: JCSM-2-relay-bin.000006
                Relay_Log_Pos: 253
        Relay_Master_Log_File: mysql-bin.000002
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: test_db
          ...중략
1 row in set (0.00 sec)
 
한쪽 mysql 중지시 아래와 같은 결과
 
*************************** 1. row ***************************
               Slave_IO_State: Reconnecting after a failed master event read
                  Master_Host: 192.168.1.5
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 24447
               Relay_Log_File: JCSM-2-relay-bin.000004
                Relay_Log_Pos: 22473
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Connecting
            Slave_SQL_Running: Yes
              Replicate_Do_DB: test_db
          ....중략
                Last_IO_Errno: 2003
                Last_IO_Error: error reconnecting to master 'repl@192.168.1.5:3306' - retry-time: 60  retries: 86400
 
1 row in set (0.00 sec)

 
* 한쪽 DB를 중지 시키고 다른 쪽 DB에서 데이터 변경후 중지시킨 DB를 start 해보니 자동으로 데이터 동기화가 잘 됨을 확인.

List of Articles
번호 제목 날짜 조회 수
66 MySQL 중복 데이터 찾아서 삭제하기 2019.01.11 1949
65 MySQL 최적화 방법 설명 2014.02.27 8022
64 MySQL 쿼리 결과 값 세로로 보기 2017.04.12 6053
63 MySQL 클라이언트/서버 프로토콜 2018.07.18 2750
62 MYSQL 통계 함수 SUM AVG MAX MIN 예제 문제 5 file 2021.03.27 137
61 MYSQL 트리거 중첩트리거 file 2021.03.27 261
60 MySQL 파티션 개요 file 2017.12.22 4150
59 mysql 포트 바꾸기, 외부에서 접속하기 2021.03.26 5079
58 MYSQL 프로시져 PROCEDURE file 2021.03.27 197
57 mysql(exists, not exists) file 2017.11.16 4090
56 mysql(union,join) file 2017.11.16 3837
55 mysql-bin 로그를 SQL 문으로 변환한는 방법 2018.07.18 1672
54 mysql-bin(binary log)파일 정리 및 삭제 2023.01.12 117
53 MySQL/MariaDB 백업 & 복원 - mysqldump 2015.08.07 7384
52 mysqlbinlog (mysql 백업, 로그남기기) 2021.03.26 201
51 MySQL〃오라클의 nextval을 MySQL에서 사용하기 2018.07.24 3864
50 MySQL에서 사용자 권한 주기 (grant 명령어) 2017.04.12 5885
49 MySQL에서 원격 IP 접속 허용하기 2017.04.12 5621
48 MySQL의 alter table 명령어 모음 2017.04.12 5105
47 no exists, not in 을 이용한 조건에 만족하지 않는 것들 구하기, 둘의 차이점 2021.03.26 125
Board Pagination Prev 1 2 3 4 5 6 7 Next
/ 7

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved