메뉴 건너뛰기

조회 수 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
번호 제목 날짜 조회 수
126 mysql table 값 변경 mariadb 테이블 값 변경 2023.01.12 83
125 FORMAT 문법 사용 하기(숫자 자리수 나타내기) file 2023.01.10 98
124 MYSQL IN&BETWEEN&NULL&예제&FROM절 문제3 file 2021.03.27 104
123 MYSQL any&all&in&예제& WHERE 절 문제4 file 2021.03.27 111
122 CASE 문법 사용 하기 file 2023.01.10 111
121 데이터베이스별 / 테이블별 용량 확인 하기 2023.01.10 115
120 mysql-bin(binary log)파일 정리 및 삭제 2023.01.12 117
119 MYSQL Groupby & having 예제 문제 6 file 2021.03.27 118
118 no exists, not in 을 이용한 조건에 만족하지 않는 것들 구하기, 둘의 차이점 2021.03.26 125
117 fulltext 관련 글 2021.03.26 125
116 MYSQL order by 예제&문제 7 file 2021.03.27 126
115 binlog 조회 / 삭제 / 보관 기간 설정 file 2023.01.10 127
114 column의 정보 중에서 column 설명(column_comment) 2021.03.26 129
113 MYSQL FULLTEXT INDEX & PARTION 검색기능향상&파티션 file 2021.03.27 131
112 MYSQL 부속질의어 예제&문제 9 file 2021.03.27 134
111 MYSQL 기초문법&예제&문제 2 file 2021.03.27 136
110 MYSQL 통계 함수 SUM AVG MAX MIN 예제 문제 5 file 2021.03.27 137
109 MariaDB can't create test file lower-test 2023.02.16 137
108 MYSQL select 명령문의 조합 &union 예제&문제 8 file 2021.03.27 138
107 엑셀로 되어있는 부분 db로 import하는 방법 2020.07.28 144
Board Pagination Prev 1 2 3 4 5 6 7 Next
/ 7

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved