๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
BackEnd๐ŸŒฑ/DB & SQL

[Docker MySQL] Orchestrator๋ฅผ ์ด์šฉํ•œ High Availability(HA) ๊ตฌ์ถ•ํ•˜๊ธฐ

by dkswnkk 2023. 11. 6.

๊ฐœ์š”

์ด์ „ ๊ฒŒ์‹œ๊ธ€ [Docker MySQL] Master-Slave Replication(๋ณต์ œ) ๊ตฌ์ถ•ํ•˜๊ธฐ์—์„œ MySQL์˜ Master-Slave ๋ณต์ œ ๊ตฌ์„ฑ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์‚ดํŽด๋ณด์•˜์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ๋งˆ์Šคํ„ฐ ์„œ๋ฒ„์˜ ๋ชจ๋“  ๋ฐ์ดํ„ฐ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์ด ์ž๋™์œผ๋กœ ์Šฌ๋ ˆ์ด๋ธŒ ์„œ๋ฒ„์— ๋™๊ธฐํ™”๋˜๊ฒŒ ๋˜๋ฉฐ, ์ด๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ์˜ ์ผ๊ด€์„ฑ์„ ์œ ์ง€ํ•˜๊ณ  ๋งˆ์Šคํ„ฐ ์„œ๋ฒ„์˜ ๋ถ€ํ•˜๋ฅผ ํšจ์œจ์ ์œผ๋กœ ๋ถ„์‚ฐ์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ, ๋งˆ์Šคํ„ฐ ์„œ๋ฒ„์— ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜์—ฌ ์ค‘๋‹จ๋˜๋ฉด, ์Šฌ๋ ˆ์ด๋ธŒ ์„œ๋ฒ„๊ฐ€ ์žˆ์Œ์—๋„ ๋ถˆ๊ตฌํ•˜๊ณ  ์šด์˜์ž๊ฐ€ ์ง์ ‘ ์กฐ์น˜๋ฅผ ์ทจํ•˜๊ธฐ ์ „๊นŒ์ง€๋Š” ์Šฌ๋ ˆ์ด๋ธŒ ์„œ๋ฒ„๋ฅผ ๋งˆ์Šคํ„ฐ ์„œ๋ฒ„๋กœ ๋Œ€์ฒดํ•˜์—ฌ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ๋ฌธ์ œ๊ฐ€ ๋˜ํ•œ ์กด์žฌํ–ˆ์—ˆ์Šต๋‹ˆ๋‹ค.

์ด๋ฒˆ ๊ฒŒ์‹œ๊ธ€์—์„œ๋Š” ์ด๋Ÿฌํ•œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ๋งˆ์Šคํ„ฐ ์„œ๋ฒ„์— ์žฅ์• ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ ์Šฌ๋ ˆ์ด๋ธŒ ์„œ๋ฒ„๋ฅผ ๋งˆ์Šคํ„ฐ ์„œ๋ฒ„๋กœ ์Šน๊ฒฉ์‹œํ‚ค๋Š” ๊ณผ์ •์„ ์ž๋™ํ™”ํ•˜๋Š” Orchestrator๋ฅผ ํ™œ์šฉํ•œ ๊ณ ๊ฐ€์šฉ์„ฑ(High Availability, HA) ๊ตฌ์„ฑ์— ๋Œ€ํ•ด ์„ค๋ช…ํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๊ณผ์ •์€ ํฌ๊ฒŒ ์•„๋ž˜ ๋‘ ๊ฐ€์ง€์ž…๋‹ˆ๋‹ค.

  1. HA ์ˆ˜๋™ ์„ค์ •
  2. HA ์ž๋™ํ™”(Auto Failover)

 

 

1. HA ์ˆ˜๋™ ์„ค์ •ํ•˜๊ธฐ

1.1 Orchestator ์ปจํ…Œ์ด๋„ˆ ์ƒ์„ฑ

๋จผ์ €, Orchestator ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. Orchestrator๋Š” MySQL ๋ณต์ œ ํ† ํด๋กœ์ง€ ๊ด€๋ฆฌ๋ฅผ ์œ„ํ•œ ์˜คํ”ˆ์†Œ์Šค์ž…๋‹ˆ๋‹ค. ๋„๊ตฌ์ž…๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด MySQL ๋ณต์ œ ๊ตฌ์„ฑ์˜ ์ƒํƒœ๋ฅผ ๋ชจ๋‹ˆํ„ฐ๋งํ•˜๊ณ , ์ž๋™ ๋ณต๊ตฌ, ๋ณต์ œ ํ† ํด๋กœ์ง€ ๋ณ€๊ฒฝ ๋“ฑ์˜ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

docker run -i -t --name orchestrator -h orchestrator \
  --net mybridge --net-alias=orchestrator \
  -p 3000:3000 \
  -d openarkcode/orchestrator:latest

 

1.2 dbcontainer์˜ ip๋Œ€์—ญ ํ™•์ธ

๋‹ค์Œ์œผ๋กœ, db001 ์ปจํ…Œ์ด๋„ˆ์˜ IP ๋Œ€์—ญ์„ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” Orchestator๋ฅผ ์œ„ํ•œ MySQL ์‚ฌ์šฉ์ž๋ฅผ ์ƒ์„ฑํ•  ๋•Œ ํ•„์š”ํ•œ๋ฐ, docker์˜ inspect ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์•„๋ž˜์™€ ๊ฐ™์ด ์ปจํ…Œ์ด๋„ˆ์˜ IP ์ฃผ์†Œ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

docker inspect --format '{{.NetworkSettings.Networks.mybridge.IPAddress}}' db001

db001 ์ปจํ…Œ์ด๋„ˆ์˜ IP ๋Œ€์—ญ ํ™•์ธ

 

1.3 Orchestrator๋ฅผ ์œ„ํ•œ MySQL ์‚ฌ์šฉ์ž ์ƒ์„ฑ

db001 ์ปจํ…Œ์ด๋„ˆ์—์„œ Orchestrator๋ฅผ ์œ„ํ•œ MySQL ์‚ฌ์šฉ์ž๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ์ด ์‚ฌ์šฉ์ž๋Š” Orchestrator๊ฐ€ MySQL ์„œ๋ฒ„์— ์ ‘์†ํ•˜์—ฌ ํ•„์š”ํ•œ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

docker exec -it -uroot db001 /bin/bash

mysql -uroot -p

CREATE USER orc_client_user@'172.%' IDENTIFIED BY 'orc_client_password';

# SUPER, PROCESS, REPLICATION SLAVE, RELOAD ๊ถŒํ•œ์€ Orchestator๊ฐ€ MySQL ์„œ๋ฒ„์— ์ ‘์†ํ•˜์—ฌ ๋ณต์ œ ๊ตฌ์„ฑ์˜ ์ƒํƒœ๋ฅผ ํ™•์ธํ•˜๊ฑฐ๋‚˜ ๋ณ€๊ฒฝํ•˜๋Š” ๋ฐ ํ•„์š”
GRANT SUPER, PROCESS, REPLICATION SLAVE, RELOAD ON *.* TO orc_client_user@'172.%';

# Orchestrator๊ฐ€ ๋ณต์ œ ์ƒํƒœ๋ฅผ ํ™•์ธํ•˜๋Š” ๋ฐ ํ•„์š”
GRANT SELECT ON mysql.slave_master_info TO orc_client_user@'172.%';

 

1.4 Orchestrator ์ ‘์†ํ™•์ธ

์ด์ œ Orchestrator์— ์ ‘์†ํ•˜์—ฌ ์„ค์ •์ด ์ •์ƒ์ ์œผ๋กœ ์™„๋ฃŒ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. Orchestrator๋Š” ์›น ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ œ๊ณตํ•˜๋ฏ€๋กœ ์›น ๋ธŒ๋ผ์šฐ์ €๋ฅผ ํ†ตํ•ด ์ ‘์†ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

http://{docker_host:ip}:3000/web/clusters

์—ฌ๊ธฐ์„œ {docker_host:ip} ๋ถ€๋ถ„์—๋Š” Docker ํ˜ธ์ŠคํŠธ์˜ IP ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ AWS EC2 ์ธ์Šคํ„ด์Šค๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด, ์ด ๋ถ€๋ถ„์— EC2 ์ธ์Šคํ„ด์Šค์˜ ํผ๋ธ”๋ฆญ IP ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•ด์•ผ ํ•˜๋ฉฐ EC2 ๋ณด์•ˆ ๊ทธ๋ฃน ์„ค์ •์—์„œ 3000๋ฒˆ ํฌํŠธ๋กœ ๋“ค์–ด์˜ค๋Š” ํŠธ๋ž˜ํ”ฝ์„ ํ—ˆ์šฉํ•˜๋„๋ก ์ธ๋ฐ”์šด๋“œ ์„ค์ •์„ ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

Orchestrator ์ธํ„ฐํŽ˜์ด์Šค ์ ‘์† ํ™”๋ฉด

์›น ์‚ฌ์ดํŠธ์— ์ ‘์†ํ•œ ํ›„, ์ƒ๋‹จ ๋ฉ”๋‰ด์—์„œ 'Cluster' > 'Discover'๋ฅผ ์„ ํƒํ•˜์—ฌ ์ƒˆ๋กœ์šด DB๋ฅผ ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค. 'Host:'๋ž€์— ํ˜ธ์ŠคํŠธ๋ช…์ด๋‚˜ IP ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•˜๊ณ  'Submit' ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด Orchestrator๊ฐ€ ํ•ด๋‹น DB๋ฅผ ์ž๋™์œผ๋กœ ์ฐพ์•„์„œ ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค.

'Cluster' > 'Discover' > 'Submit'
DIscovered db001:3306 ๋“ฑ๋ก ํ™•์ธ
์ด Instances ํ™•์ธ
'Cluster' > 'Dashboard' ํ™•์ธ

'Cluster' > 'Dashboard'๋กœ ์ด๋™ํ•ด์„œ ๋ณด๋ฉด db001์„ ํฌํ•จํ•˜์—ฌ ์ด 3๋Œ€์˜ ์„œ๋ฒ„๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ํ•˜๊ณ  ์žˆ์Œ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ์•ž์„œ ์„ค์ •ํ•œ ๋‚ด์šฉ์ด ์ œ๋Œ€๋กœ ์ ์šฉ๋˜์—ˆ์œผ๋ฉฐ, Orchestrator๊ฐ€ ๊ฐ ์„œ๋ฒ„์— ์ •์ƒ์ ์œผ๋กœ ์ ‘์†ํ•˜์—ฌ ์ƒํƒœ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ค๊ณ  ์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

1.5 HA ํ…Œ์ŠคํŠธ

์•ž์„œ ์„ค์ •ํ•œ High Availability(HA) ์„ค์ •์ด ์ •์ƒ์ ์œผ๋กœ ์ž‘๋™ํ•˜๋Š”์ง€ ํ…Œ์ŠคํŠธํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ์œ„ํ•ด db001 ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๊ณ ์˜๋กœ ์ •์ง€์‹œ์ผœ ๋ด…๋‹ˆ๋‹ค.

docker stop db001

db001 ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์ •์ง€๋จ์— ๋”ฐ๋ผ Orchestrator์˜ 'Dashboard'์—์„œ db001์˜ ์ƒํƒœ๊ฐ€ 'Recovery needed'๋กœ ํ‘œ์‹œ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, db001์— ์—ฐ๊ฒฐ๋˜์–ด ์žˆ๋˜ db002์™€ db003์˜ ์ƒํƒœ๊ฐ€ 'Disconnected'๋กœ ๋ณ€๊ฒฝ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

'Revocery' > db002๋ฅผ ์ƒˆ๋กœ์šด Master๋กœ ์Šน๊ฒฉ

์ด ์ƒํƒœ์—์„œ 'Recovery' ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜์—ฌ db002๋ฅผ ์ƒˆ๋กœ์šด Master๋กœ ์Šน๊ฒฉ์‹œ์ผœ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. 

db001์ด ๋ถ„๋ฆฌ๋จ
db002๊ฐ€ ์ƒˆ๋กœ์šด Master๊ฐ€ ๋˜์—ˆ์Œ

์ด ์ž‘์—… ์ดํ›„, db001๊ณผ db002๊ณผ ๋ถ„๋ฆฌ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ db002๊ฐ€ ์ƒˆ๋กœ์šด Master๊ฐ€ ๋˜์—ˆ๊ณ , db003์€ db002์˜ Slave๋กœ ๋ณ€๊ฒฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ db001์€ ์—ฌ์ „ํžˆ 'Recovery needed' ์ƒํƒœ๋กœ ๋‚จ์•„์žˆ์Šต๋‹ˆ๋‹ค.

 

1.6 Container db002์™€ db003 db ์ƒํƒœ ํ™•์ธ

db002์™€ db003์— ์ ‘์†ํ•˜์—ฌ DB์˜ ์ƒํƒœ๋ฅผ ํ™•์ธํ•ด ๋ด…์‹œ๋‹ค. 

# Docker ์ปจํ…Œ์ด๋„ˆ ์ ‘์†
docker exec -it -uroot db002 /bin/bash

# MySQL ์ ‘์†
mysql -uroot -p

# Slave ์ •๋ณด ํ™•์ธ
show slave status\G

db002์˜ Slave ์ •๋ณด ํ™•์ธ

์œ„ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๋ฉด db002์˜ Slave ์ •๋ณด๊ฐ€ ์ „๋ถ€ ์‚ฌ๋ผ์ง„ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ, read_only๊ฐ€ 0์œผ๋กœ ์„ค์ •๋˜์–ด ์žˆ์–ด ์“ฐ๊ธฐ๊ฐ€ ๊ฐ€๋Šฅํ•œ ์ƒํƒœ๋กœ ๋ณ€๊ฒฝ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Š” db002๊ฐ€ ์ƒˆ๋กœ์šด Master๋กœ ์ •์ƒ์ ์œผ๋กœ ์Šน๊ฒฉ๋˜์—ˆ์Œ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์ด์–ด์„œ db003์˜ Slave ์ •๋ณด๋ฅผ ํ™•์ธํ•˜์—ฌ Master๊ฐ€ db002๋กœ ๋ณ€๊ฒฝ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

# Docker ์ปจํ…Œ์ด๋„ˆ ์ ‘์†
docker exec -it -uroot db003 /bin/bash

# MySQL ์ ‘์†
mysql -uroot -p

# Slave ์ •๋ณด ํ™•์ธ
show slave status\G

db003์˜ Slave ์ •๋ณด ํ™•์ธ

db003์˜ Slave ์ •๋ณด์—์„œ Master๊ฐ€ db002๋กœ ๋ณ€๊ฒฝ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Š” HA ์„ค์ •์— ๋”ฐ๋ผ db002๊ฐ€ ์ƒˆ Master๋กœ ์Šน๊ฒฉ๋˜์—ˆ๊ณ , db003๊ฐ€ db002์˜ Slave๋กœ ์ •์ƒ์ ์œผ๋กœ ๋ณ€๊ฒฝ๋˜์—ˆ์Œ์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

 

1.7 db001 ๋ณต๊ตฌ ๋ฐ db002์˜ slave๋กœ ์„ค์ •

์ด์ œ db001 ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋‹ค์‹œ ์‹œ์ž‘ํ•˜๊ณ  db002์˜ Slave๋กœ ์„ค์ •ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๋จผ์ €, db001์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

docker start db001

๊ทธ๋‹ค์Œ, db001์— ์ ‘์†ํ•ฉ๋‹ˆ๋‹ค.

docker exec -it -uroot db001 /bin/bash

mysql -uroot -p

# ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์ฝ๊ธฐ ์ „์šฉ ๋ชจ๋“œ๋กœ ์„ค์ •
SET GLOBAL read_only = 1;

# MySQL ๋ณต์ œ๋ฅผ ์œ„ํ•ด ์ƒˆ ๋งˆ์Šคํ„ฐ ์„œ๋ฒ„์˜ ์ƒ์„ธ ์ •๋ณด๋ฅผ ์„ค์ •
CHANGE MASTER TO MASTER_HOST='db002', MASTER_USER='repl', MASTER_PASSWORD='repl', MASTER_AUTO_POSITION=1;

# ๋ณต์ œ ์‹œ์ž‘
START SLAVE;

# ๋ณต์ œ ์„ค์ • ํ™•์ธ
show slave status\G

์œ„ ๋ช…๋ น์„ ์ˆœ์„œ๋Œ€๋กœ ์‹คํ–‰ํ•˜๋ฉด db001์ด db002์˜ Slave๋กœ ์„ค์ •๋˜๋ฉฐ, db002์—์„œ ๋ฐœ์ƒํ•˜๋Š” ๋ชจ๋“  ๋ฐ์ดํ„ฐ ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด db001์—๋„ ๋™์ผํ•˜๊ฒŒ ์ ์šฉ๋ฉ๋‹ˆ๋‹ค.

db002์˜ Slave ์ •๋ณด ํ™•์ธ
db002 cluster ํ™•์ธ

๋งˆ์ง€๋ง‰์œผ๋กœ, Orchestrator์—์„œ db002 cluster๋ฅผ ํ™•์ธํ•˜๋ฉด db001์ด Slave๋กœ ์ถ”๊ฐ€๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 

 

 

2. HA ์ž๋™ํ™”(Auto Failover)

์œ„์—์„œ๋Š” Master DB์˜ ์žฅ์•  ํ›„์— ์ˆ˜๋™์œผ๋กœ Failover๋ฅผ ์‹œํ‚จ ๊ฒฝ์šฐ๋ฅผ ์‚ดํŽด๋ณด์•˜์Šต๋‹ˆ๋‹ค. ์ด๋ฒˆ์—๋Š” ์‚ฌ๋žŒ์˜ ๊ฐœ์ž… ์—†์ด ์ž๋™์œผ๋กœ Failover๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•, ์ฆ‰ Auto Failover์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

2.1 Auto Failover๋ฅผ ์œ„ํ•œ Orchestrator์˜ ์„ค์ • ๋ณ€๊ฒฝ

๋จผ์ €, Auto Failover๋ฅผ ์œ„ํ•ด Orchestrator์˜ ์„ค์ •์„ ๋ณ€๊ฒฝํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜์˜ ๋ช…๋ น์–ด๋“ค์„ ์‹คํ–‰ํ•˜์—ฌ ์„ค์ •์„ ๋ณ€๊ฒฝํ•˜๊ณ  Orchestrator๋ฅผ ์žฌ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

# Orchestrator๊ฐ€ ์‹คํ–‰๋˜๊ณ  ์žˆ๋Š” Docker ์ปจํ…Œ์ด๋„ˆ์— ์ ‘์†
docker exec -it orchestrator /bin/bash

# /etc/ ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์ด๋™ํ•˜์—ฌ orchestrator.conf.json ํŒŒ์ผ์„ ์—ฐ๋‹ค.
cd /etc/
vi orchestrator.conf.json

# ์•„๋ž˜์˜ ์„ค์ •๋“ค์„ ์ถ”๊ฐ€
"RecoverMasterClusterFilters":[
"*"
],

"PromotionIgnoreHostnameFilters": ["db003"],

# Orchestrator๋ฅผ ์žฌ์‹œ์ž‘
docker restart orchestrator

๊ฐ ์„ค์ •์— ๋Œ€ํ•œ ์„ค๋ช…์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • "RecoverMasterClusterFilters": ["*"]: ์ด ์„ค์ •์€ ๋ชจ๋“  ํด๋Ÿฌ์Šคํ„ฐ์—์„œ Master ์„œ๋ฒ„ ์žฅ์•  ๋ณต๊ตฌ๋ฅผ ์‹œ๋„ํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.
  • "PromotionIgnoreHostnameFilters":["db003"]: ์ด ์„ค์ •์€ db003 ์„œ๋ฒ„๋ฅผ Master๋กœ ์Šน๊ฒฉํ•˜๋Š” ๊ฒƒ์„ ๋ฌด์‹œํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. ์ฆ‰, db003๋Š” ํ•ญ์ƒ Slave์˜ ์—ญํ• ๋งŒ ์ˆ˜ํ–‰ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

์ด๋ ‡๊ฒŒ ์„ค์ •์„ ๋ณ€๊ฒฝํ•˜๋ฉด, ์ดํ›„๋ถ€ํ„ฐ๋Š” Master ์„œ๋ฒ„์— ์žฅ์• ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด Orchestrator๊ฐ€ ์ž๋™์œผ๋กœ ๋‹ค๋ฅธ ์„œ๋ฒ„๋ฅผ Master๋กœ ์Šน๊ฒฉ์‹œํ‚ค๊ณ  ์žฅ์• ๊ฐ€ ๋ฐœ์ƒํ•œ ์„œ๋ฒ„๋ฅผ ๋ณต๊ตฌํ•˜๋Š” ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. 

'Cluster' > 'Dashboard' ํ™•์ธ

Orchestrator์˜ ์„ค์ •์„ ๋ณ€๊ฒฝํ•˜๊ณ  ์žฌ์‹œ์ž‘ํ•œ ํ›„์—, Orchestrator ์›น ์ธํ„ฐํŽ˜์ด์Šค์˜ ์ขŒ์ธก ์ƒ๋‹จ์— ์œ„์น˜ํ•œ ํ•˜ํŠธ ํ‘œ์‹œ๋ฅผ ๋ณด๋ฉด ๋ถˆ์ด ๋“ค์–ด์˜ค๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ด๋Š” Orchestror๊ฐ€ ์ž๋™์œผ๋กœ Master Recovery๋ฅผ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ์ƒํƒœ์ž„์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ, ์ดํ›„์—๋Š” Master ์„œ๋ฒ„์— ์žฅ์• ๊ฐ€ ๋ฐœ์ƒํ•˜๋”๋ผ๋„ Orchestrator๊ฐ€ ์ž๋™์œผ๋กœ Failover๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ณ , ์žฅ์• ๊ฐ€ ๋ฐœ์ƒํ•œ Master ์„œ๋ฒ„๋ฅผ ๋ณต๊ตฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 

 

2.3 ์žฅ์•  ์ƒํ™ฉ ์ƒ์„ฑ

๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์žฅ์•  ์ƒํ™ฉ์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด Master DB์ธ db002 ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ •์ง€์‹œ์ผœ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

docker stop db002

์œ„ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๋ฉด db002 ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์ •์ง€๋˜์–ด ์žฅ์•  ์ƒํ™ฉ์ด ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. ์ด๋•Œ, Orchestrator๋Š” ์„ค์ •์— ๋”ฐ๋ผ ์ž๋™์œผ๋กœ Failover๋ฅผ ์ˆ˜ํ–‰ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

Failover๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์ˆ˜ํ–‰๋˜๋ฉด, Cluster๋Š” db002์™€ db001๋กœ ๋ถ„๋ฆฌ๋˜๋ฉฐ, db003์ด db001์˜ Slave๋กœ ์„ค์ • ๋ณ€๊ฒฝ๋˜๋Š” ๋ชจ์Šต์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Š” Orchestrator๊ฐ€ ์žฅ์•  ์ƒํ™ฉ์„ ์ •์ƒ์ ์œผ๋กœ ๊ฐ์ง€ํ•˜๊ณ , ์ƒˆ๋กœ์šด Master๋กœ db001์„ ์Šน๊ฒฉ์‹œํ‚จ ํ›„, db003์„ db001์˜ Slave๋กœ ์žฌ๋ฐฐ์น˜ํ•œ ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

 

 

์ •๋ฆฌ

์ด๋ฒˆ ๋‚ด์šฉ์—์„œ๋Š” ๋งˆ์Šคํ„ฐ ์„œ๋ฒ„์— ์žฅ์• ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ ์Šฌ๋ ˆ์ด๋ธŒ ์„œ๋ฒ„๋ฅผ ๋งˆ์Šคํ„ฐ ์„œ๋ฒ„๋กœ ์Šน๊ฒฉ์‹œํ‚ค๋Š” ๊ณผ์ •์„ ์ž๋™ํ™”ํ•˜๋Š” Orchestrator๋ฅผ ํ™œ์šฉํ•œ ๊ณ ๊ฐ€์šฉ์„ฑ(High Availability, HA) ๊ตฌ์„ฑ์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์•˜์Šต๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ, ์ด๋ ‡๊ฒŒ HA ๊ตฌ์„ฑ์„ ํ†ตํ•ด DB ์„œ๋ฒ„์˜ ์žฅ์• ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋”๋ผ๋„ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ DB ์ ‘์† ์ •๋ณด๊ฐ€ ์—…๋ฐ์ดํŠธ๋˜์ง€ ์•Š์œผ๋ฉด ์—ฌ์ „ํžˆ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์„ค์ • ์ •๋ณด์—๋Š” ์žฅ์• ๊ฐ€ ๋ฐœ์ƒํ•œ db001์ด master DB๋กœ ์„ค์ •๋˜์–ด ์žˆ๋‹ค๋ฉด, db001์— ๋ฌธ์ œ๊ฐ€ ์ƒ๊ฒจ db002๊ฐ€ ์ƒˆ๋กœ์šด master๊ฐ€ ๋˜์—ˆ์„ ๋•Œ์—๋„ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ๊ณ„์† db001์„ ๋ฐ”๋ผ๋ณด๋„๋ก ์„ค์ •๋˜์–ด ์žˆ๊ณ , db001์— ์ ‘์†ํ•˜๋ ค๊ณ  ๊ณ„์† ์‹œ๋„ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

์ฆ‰, ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ ˆ๋ฒจ์—์„œ๋Š” db001์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜์—ฌ Failover๊ฐ€ ์ด๋ฃจ์–ด์ ธ ์„œ๋น„์Šค๋ฅผ ์ง€์†ํ•  ์ค€๋น„๊ฐ€ ๋˜์—ˆ์ง€๋งŒ, ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ๋Š” ์•„์ง๋„ ๊ณ„์† ์žฅ์•  ์ƒํ™ฉ์ธ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ, ์ด๋Ÿฐ ์ƒํ™ฉ์—์„œ๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ DB ์ ‘์† ์ •๋ณด๋ฅผ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ db001์—์„œ ์ƒˆ๋กœ์šด master์ธ db002๋กœ ๋ณ€๊ฒฝํ•˜๋Š” ์ž‘์—…์ด ํ•„์š”ํ•˜๊ณ , ์ด๋Ÿฐ ๊ฒฝ์šฐ์—๋Š” ๋Œ€๋ถ€๋ถ„ ์ „์ฒด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์žฌ์‹œ์ž‘ํ•ด์•ผ ํ•˜๋Š” ์ƒํ™ฉ์ด ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

์ด๋Ÿฐ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค์Œ ๋‚ด์šฉ์—์„œ๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜๊ณผ DB ์„œ๋ฒ„ ์‚ฌ์ด์— proxy ์—ญํ• ์„ ํ•ด์ฃผ๋Š” ๋ ˆ์ด์–ด๋ฅผ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด์„œ, ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์„ค์ • ๋ณ€๊ฒฝ์ด๋‚˜ ์žฌ์‹œ์ž‘ ์—†์ด ์ž๋™์œผ๋กœ ๋ณ€๊ฒฝ๋œ master DB๋กœ ์—ฐ๊ฒฐํ•˜๋„๋ก ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

๋Œ“๊ธ€