- Master, Slave 모두 구성되어 있다는 전제하에 진행하였습니다.
1. 유저 생성 및 권한 부여
<<Master>>
#Slave에서만 접근 가능하도록 함
sql> create user 'repl'@'[Slave IP]' identified by 'repl' ;
sql> grant replication slave on *.* to 'repl'@'[Slave IP]' ;
#모든 데이터베이스의 모든 테이블에 다음과 같은 권한을 부여해라.
2. MySQL dump
<<Master>>
#백업받을 디렉토리 생성
[root@/] mkdir backup
#디렉토리 소유자 변경
[root@/] chown mysql:mysql backup
<<Master>>
#전체 데이터베이스 백업
# mysql이 권한을 가진 디렉토리 안으로 떨어트려야 permission denied 안난다.
#--master-data=2 이 옵션이 백업 시점에서의 log position과 log file을 기록해 달라는 뜻이다.
[mysql] mysqldump -uroot -p[root의 비밀번호] --all-databases --routines --triggers --events --single-transaction --master-data=2 > /backup/full_dump.sql
#슬레이브 DB로 백업파일 전송
[mysql@/backup] scp backup.sql root@[Slave IP]:/
#방화벽 내리기!!!!!!!
[root] systemctl status firewalld
[root] systemctl stop firewalld
<<Slave>>
#mysql -u[연결할 계정 이름] -p[계정 비밀번호] --host=[연결할 IP] --port=[포트번호]
[mysql] mysql -urepl -prepl --host=[Master IP]--port=[Master Port]
3. 로그 파일 및 포지션 확인
<<Master>>
#확인
[mysql@backup] vi full_dump.sql
-- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000010', MASTER_LOG_POS=1025;
4. 슬레이브 설정
<<Slave>>
#마스터에서 dump받은 백업파일 슬레이브에 insert하기
[mysql] mysql -uroot -p -S /tmp/mysql.sock < backup.sql
sql> status #UNIX socket확인 #server ID 헷갈릴 때 확인 용으로 사용
#replication을 위한 마스터 연결 정보 입력
sql> CHANGE MASTER TO
MASTER_HOST='[Master IP]',
MASTER_PORT=[Master Port],
MASTER_USER='repl',
MASTER_PASSWORD='repl',
MASTER_LOG_FILE='mysql-bin.000010',
MASTER_LOG_POS=1025,
MASTER_CONNECT_RETRY=10;
#슬레이브 수행
sql> start slave ;
#확인
sql> show slave status \G ;
<<Master>>
sql> show processlist \G;