Replication 설정
0) Slave, Master 서버 설정 변경
Master의 /etc/mysql/my.cnf에서
아래와 같이 binary logging과 server-id를 체크한다.
Slave의 /etc/mysql/my.cnf에서
아래와 같이server-id가 겹치지 않도록 수정한다.
1) master와 slave에 동일한 버전의 mysql 설치( 본인의 경우에는 5.0 설치 )
2) replication용 user 추가( 여기서는 repl로 설정 )
3) replication slave용 user를 master에서 권한 설정.
4) Slave의 설정을 위해서 Master의 binary log 정보를 보자.
5) Slave에서 Master 세팅 설정.
/etc/mysql/my.cnf를 수정해도 되며, 아래와 같이 명령을 날려도 된다.
아래 각 항목의 값들 중, log_file과 log_pos는 위의 master status의 값을 적는다.
6) Slave 시작.
7) Slave 상태 확인.
Slave_IO_State가 위와 같이 나오지 않고,
'Connecting to master' 등 다른 상태이면 network상태를 의심해봐야 한다.
ping으로 network 연결 상태를 보고,
이도 정상적인 경우에는 skip-networking 옵션이 켜 있는 경우일 것이다.
이 부분의 주소를 수정하고 재시작하도록 한다.
MySQL 재 시작
이제 master의 변화가 slave에 반영되는 것을 확인할 수 있다.
0) Slave, Master 서버 설정 변경
Master의 /etc/mysql/my.cnf에서
아래와 같이 binary logging과 server-id를 체크한다.
[mysql]
log-bin=mysql-bin
server-id=1
log-bin=mysql-bin
server-id=1
Slave의 /etc/mysql/my.cnf에서
아래와 같이server-id가 겹치지 않도록 수정한다.
[mysql]
server-id=2
server-id=2
1) master와 slave에 동일한 버전의 mysql 설치( 본인의 경우에는 5.0 설치 )
2) replication용 user 추가( 여기서는 repl로 설정 )
mysql> CREATE USER userid IDENTIFIED BY 'password';
3) replication slave용 user를 master에서 권한 설정.
mysql> grant replication slave on *.* to 'repl'@'%.dsphome.net' identified by '****';
4) Slave의 설정을 위해서 Master의 binary log 정보를 보자.
mysql> FLUSH TABLES WITH READ LOCK;
mysql> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000027 | 9080 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
mysql> UNLOCK TABLES;
mysql> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000027 | 9080 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
mysql> UNLOCK TABLES;
5) Slave에서 Master 세팅 설정.
/etc/mysql/my.cnf를 수정해도 되며, 아래와 같이 명령을 날려도 된다.
아래 각 항목의 값들 중, log_file과 log_pos는 위의 master status의 값을 적는다.
mysql> CHANGE MASTER TO
-> MASTER_HOST='hostname/ip',
-> MASTER_USER='repl',
-> MASTER_PASSWORD='****',
-> MASTER_LOG_FILE='mysql-bin.000027',
-> MASTER_LOG_POS=9080;
-> MASTER_HOST='hostname/ip',
-> MASTER_USER='repl',
-> MASTER_PASSWORD='****',
-> MASTER_LOG_FILE='mysql-bin.000027',
-> MASTER_LOG_POS=9080;
6) Slave 시작.
mysql> START SLAVE;
7) Slave 상태 확인.
mysql> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: blog1.naver.com (예입니다)
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000027
Read_Master_Log_Pos: 9080
Relay_Log_File: mysqld-relay-bin.000022
Relay_Log_Pos: 235
Relay_Master_Log_File: mysql-bin.000027
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: 169
Relay_Log_Space: 235
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)
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: blog1.naver.com (예입니다)
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000027
Read_Master_Log_Pos: 9080
Relay_Log_File: mysqld-relay-bin.000022
Relay_Log_Pos: 235
Relay_Master_Log_File: mysql-bin.000027
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: 169
Relay_Log_Space: 235
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)
Slave_IO_State가 위와 같이 나오지 않고,
'Connecting to master' 등 다른 상태이면 network상태를 의심해봐야 한다.
ping으로 network 연결 상태를 보고,
이도 정상적인 경우에는 skip-networking 옵션이 켜 있는 경우일 것이다.
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 127.0.0.1
# localhost which is more compatible and is not less secure.
bind-address = 127.0.0.1
이 부분의 주소를 수정하고 재시작하도록 한다.
MySQL 재 시작
$ sudo /etc/init.d/mysql restart
이제 master의 변화가 slave에 반영되는 것을 확인할 수 있다.