1. 브리지 생성
[1] 도커 네트워크 확인 & 브리지 생성
[root@dev opc]# docker network ls
NETWORK ID NAME DRIVER SCOPE
697ad12cd5fa bridge bridge local
d955f1181bf5 host host local
30e9346c2d17 none null local
[root@dev opc]# docker network create --driver bridge mybridge
[2] data,log 삭제하고 도커 컨테이너 재생성
docker run -it --name db001 -p 3306:3306 -h db001 \
--net mybridge --net-alias=db001 \
-v /home/opc/db/db001/data:/var/lib/mysql \
-v /home/opc/db/db001/log:/var/log/mysql \
-v /home/opc/db/db001/conf:/etc/percona-server.conf.d \
-e MYSQL_ROOT_PASSWORD="root" -d percona:5.7.30
docker run -it --name db002 -p 3307:3306 -h db002 \
--net mybridge --net-alias=db002 \
-v /home/opc/db/db002/data:/var/lib/mysql \
-v /home/opc/db/db002/log:/var/log/mysql \
-v /home/opc/db/db002/conf:/etc/percona-server.conf.d \
-e MYSQL_ROOT_PASSWORD="root" -d percona:5.7.30
docker run -it --name db003 -p 3308:3306 -h db003 \
--net mybridge --net-alias=db003 \
-v /home/opc/db/db003/data:/var/lib/mysql \
-v /home/opc/db/db003/log:/var/log/mysql \
-v /home/opc/db/db003/conf:/etc/percona-server.conf.d \
-e MYSQL_ROOT_PASSWORD="root" -d percona:5.7.30
[3] master에서 user 생성
mysql> CREATE USER 'repl'@'%' IDENTIFIED BY 'repl';
Query OK, 0 rows affected (0.01 sec)
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
Query OK, 0 rows affected (0.01 sec)
[4] ping 날려보기
[root@db001 /]# ping db001
PING db001 (172.18.0.2) 56(84) bytes of data.
64 bytes from db001 (172.18.0.2): icmp_seq=1 ttl=64 time=0.047 ms
64 bytes from db001 (172.18.0.2): icmp_seq=2 ttl=64 time=0.043 ms
64 bytes from db001 (172.18.0.2): icmp_seq=3 ttl=64 time=0.044 ms
64 bytes from db001 (172.18.0.2): icmp_seq=4 ttl=64 time=0.044 ms
64 bytes from db001 (172.18.0.2): icmp_seq=5 ttl=64 time=0.043 ms
^C
--- db001 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 3999ms
rtt min/avg/max/mdev = 0.043/0.044/0.047/0.004 ms
[root@db001 /]#
[root@db001 /]# ping db002
PING db002 (172.18.0.3) 56(84) bytes of data.
64 bytes from db002.mybridge (172.18.0.3): icmp_seq=1 ttl=64 time=0.170 ms
64 bytes from db002.mybridge (172.18.0.3): icmp_seq=2 ttl=64 time=0.073 ms
64 bytes from db002.mybridge (172.18.0.3): icmp_seq=3 ttl=64 time=0.078 ms
^C
--- db002 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.073/0.107/0.170/0.044 ms
[root@db001 /]#
[root@db001 /]# ping db003
PING db003 (172.18.0.4) 56(84) bytes of data.
64 bytes from db003.mybridge (172.18.0.4): icmp_seq=1 ttl=64 time=0.102 ms
64 bytes from db003.mybridge (172.18.0.4): icmp_seq=2 ttl=64 time=0.076 ms
64 bytes from db003.mybridge (172.18.0.4): icmp_seq=3 ttl=64 time=0.080 ms
^C
[5] slave 에 master 세팅
mysql> reset master;
Query OK, 0 rows affected (0.02 sec)
mysql> CHANGE MASTER TO MASTER_HOST='db001', \
MASTER_USER='repl', MASTER_PASSWORD='repl', \
MASTER_AUTO_POSITION=1;
Query OK, 0 rows affected, 2 warnings (0.02 sec)
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status\G;
>> 결과
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: db001
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 635
Relay_Log_File: db002-relay-bin.000003
Relay_Log_Pos: 848
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: 635
Relay_Log_Space: 2927711
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: 100
Master_UUID: edab089d-a7d1-11ee-85d6-0242ac120002
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 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: edab089d-a7d1-11ee-85d6-0242ac120002:1-7
Executed_Gtid_Set: edab089d-a7d1-11ee-85d6-0242ac120002:1-7
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.01 sec)
출처
인프런 - 따라하며 배우는 MySQL on Docker 를 보고 정리해보았습니다.
'Infra > Docker' 카테고리의 다른 글
[Docker] Proxy Layer 구성하기 (2) | 2024.01.08 |
---|---|
[Docker] Orchestra를 통해 High Availability(HA) 구축하기 (1) | 2024.01.08 |
[Docker] Master-Slave Replication 구성 (0) | 2023.12.31 |
[Docker] 호스트OS에 log, config 연결 (+my.cnf) (1) | 2023.12.29 |
[Docker] Docker란? Docker로 Mysql 설치해보기 (1) | 2023.12.28 |