Mysql replication chain 제거 및 Master 변경

위 그림과 같은 설정이 Mysql replication chain 이다.
slave DB3은 Master DB 의 Slave 이자, Slave DB4 의 Master 인 상태.
구성은 다소 어렵지 않다.
Chain 제거 및 Master 변경 작업
- Slave DB3 my.cnf 에 log-slave-updates 옵션 제거 후 Mysql restart (해당 옵션은 Chain 전용 옵션 하단 참조)
--log-slave-updates
일반적으로, 슬레이브는 마스터 서버에서 전달 받은 업데이트에 대해서는 자신의 바이너리 로그에 기록하지 않는다. 이 옵션은 SQL 쓰레드가 실행한 업데이트를 자신의 바이너리 로그에 기록하도록 만든다. 슬레이브가 바이너리 로깅을 활성화 시키기 위한 --log-bin 옵션과 함께 시작되어야 이 옵션이 적용된다. --log-slave-updates는 여러분이 리플리케이션 서버를 서로 연결 (chain) 할 때 사용하는 것이다. 예를 들면, 아래와 같은 배열을 사용해서 리플리케이션 서버를 설정한다고 가정하자:
A -> B -> C
여기에서, A는 슬레이브B에 대한 마스터 역할을 하고, B는 슬레이브 C에 대해 마스터 역할을 한다. 이렇게 동작하기 위해서는, B가 반드시 마스터인 동시에 슬레이브가 되어야 한다. 바이너리 로깅을 활성화 시키기 위해 A와 B 모두에서 --log-bin옵션을 실행해야 하고, A에서 받은 업데이트를 B가 자신의 바이너리 로그에 기록할 수 있도록 B는 --log-slave-updates 옵션을 실행해야 한다.
- Slave DB4 서버에서
mysql> stop slave;
mysql> reset slave;
후 Mysql restart 후 Master bin 포지션 확인 후 (FM은 모든 테이블을 플러시 (flush)하고 쓰기 연산 명령문을 잠근 후 Master 변경 해야함)
CHANGE MASTER TO master_host='192.168.0.170', master_port=3306, master_user='REPLICATION_ID',
master_password='REPLICATION_PASSWORD', master_log_file='MASTER.BIN.LOG.FILE', master_log_pos=MASTER POSITION;
연결,
mysql> start slave;
mysql> show slave status \G;
확인
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.0.170
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000032
Read_Master_Log_Pos: 292782232
Relay_Log_File: mysqld_relay_bin.000002
Relay_Log_Pos: 6486407
Relay_Master_Log_File: mysql-bin.000032
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 292782232
Relay_Log_Space: 6486615
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 9d6bf51a-9284-11e6-8c79-00259086b960
Master_Info_File: /DATA/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
* Slave_IO_Running와 Slave_SQL_Running이 모두 Yes,
* Read_Master_Log_Pos와 Exec_Master_Log_Pos 값이 일치,
* Last_Errno는 0, Last_Error는 공란, Seconds_Behind_Master이 0이면 정상 복제중