1. 개 요
- 현재 디비를 단독으로 사용중이기 때문에 디비 이중화로 분산처리로 사용하기 위함.
- Master-slave 용도로 사용하기 위함.

 

2. 접속정보
- 서버명 / IP(마스터 디비)
root / 패스워드
mysql root / 패스워드

- (신규서버)corent-0514 / 112.175.47.112(슬레이브 DB)

세팅 내역 : 
  OS: Centos 6.5 x86_64
  레이드구성 : SAS 300G * 3EA (RAID 1, backup 300G)
  파티션 : /(30G), swap(4G), /home 나머지

root / 패스워드
mysql root / 패스워드

 

3. 작업 절차 (기존 디비 백업 후 작업 진행)

(1) Master DB

- 기존 디비데이터 전체 백업(Innodb와 Misam 혼합사용 dump로 백업 진행)

- /etc/my.cnf 파일 백업 후 아래 내용 [mysqld] 섹션에 추가
server-id       = 1
log-bin=mysql-bin
binlog_format=mixed
expire_logs_days = 7
max_binlog_size = 1G
 

- mysql 서비스 리스타트 진행

- 리스타스 진행 후 binlog 생성 여부 확인
- mysql 접속하여 슬레이브 계정 생성
mysql > grant replication slave on *.* to 'repliuser'@'112.175.47.112' identified by 'DGreward1004';

- mysql dump 진행
mysqldump -u root -p --all-databases --master-data > juncmobile.sql

- 덤프한 파일 slave 서버로 데이터 복사
rsync -av juncmobile.sql root@112.175.47.112:/home

 

 

 

(2) (신규서버) slave DB

- 마스터 서버와 동일한 버전으로 설치 및 셋팅 완료 상태

- 마스터 서버에서 덤프한 파일 복원
/home/mysql/bin/mysql -u root -p < juncmobile.sql

- /etc/my.cnf 파일 백업 후 아래 내용 [mysqld] 섹션에 추가

server-id       = 2
relay_log=mysql-relay-bin
log-bin=mysql-bin
binlog_format=mixed
expire_logs_days = 7
max_binlog_size = 1G
#slave-skip-errors=all
slave-skip-errors=1062
read_only

master-host=112.175.47.104 
master-port=3306 
master-user= repliuser 
master-password= DGreward1004
 

- mysql 서비스 리스타트 진행

- mysql 접속하여 마스터 세팅

CHANGE MASTER TO MASTER_HOST='112.175.47.104', MASTER_PORT=3306, MASTER_USER='repliuser', MASTER_PASSWORD='DGreward1004', master_connect_retry=60;

- 슬레이브 스타트
start slave;

- slave 상태 재확인 

mysql> show slave status\G; 
*************************** 1. row *************************** 
            Slave_IO_State: Waiting for master to send event 
                Master_Host: 112.175.47.104 
                Master_User: repliuser 
                Master_Port: 3306 
              Connect_Retry: 60 
            Master_Log_File: mysql-bin.000003 
        Read_Master_Log_Pos: 98 
            Relay_Log_File: mysql-relay-bin.000005 
              Relay_Log_Pos: 240 
      Relay_Master_Log_File: mysql-bin.000003 
          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: 98 
            Relay_Log_Space: 240 
            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 
1 row in set (0.00 sec) 

- data 일치확인(master,slave 서버 둘다 확인)

mysql> use usedmarket;
mysql> select count(*) from 테이블명; 

+ Recent posts