준비 : 서버 2대와 각각의 서버에 mysql 설치되어있는 상태
Master 서버 부분
1. mysql 환경 설정
[vi /etc/my.cnf]
|
[mysqld]
log-bin=mysql-bin
server-id=1
binlog_do_db=EdgeDB
|
|
2. mysql 계정 생성(slave에서 master로 접속할 계정)
|
mysql> grant all privileges on *.* to 'repl'@'%' identified by '';
|
|
3. systemctl restart mysqld
mysql 재시작
4. master 서버 정보 확인
|
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000002 | 1956 | EdgeDB | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
|
|
여기서 file 이름과 position 위치를 알고 있어야 한다.
Slave 서버 부분
1. slave서버에 master에 있는 db명과 같은 디비 생성(만약 dump 파일로 db를 옮긴 상태라면 이 과정은 필요없다.)
|
mysql> create database EdgeDB default character set utf8;
|
|
2. slave 서버 mysql 환경 설정
[vi /etc/my.cnf]
|
[mysqld]
server-id=2
binlog_do_db=EdgeDB
slave-skip-errors=all
read_only=1
|
|
3. systemctl restart mysqld
mysql 재시작
4. slave 서버의 mysql 내부 설정
|
mysql> change master to
master_host='마스터ip주소',
master_user='repl',
master_password='repl의 비번',
master_log_file='mysql-bin.000002',
master_log_pos=1956;
|
|
5. 연결 확인(master)
|
mysql> show processlist\G
*************************** 1. row ***************************
Id: 106
User: repl
Host: slave서버ip:50896
db: NULL
Command: Binlog Dump
Time: 3537
State: Master has sent all binlog to slave; waiting for more updates
Info: NULL
|
|
6 slave 서버에서...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: master ip주소
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 1956
Relay_Log_File: mysqld-relay-bin.000002
Relay_Log_Pos: 1740
Relay_Master_Log_File: mysql-bin.000002
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: 1956
Relay_Log_Space: 1914
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: b9ea7ac5-207f-11e9-b5f6-1866da603378
Master_Info_File: /var/lib/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
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
1 row in set (0.00 sec)
|
|
Last_IO_Errno: 0
Last_IO_Error:
위와 같이 에러 내용이 없어야 한다.
실제로 마스터 mysql에서 데이터를 입출력 하면 slave에 데이터가 입출력 되는것을 확인 가능하다.