[Infra] Maria DB(MySQL) ์ด์ค‘ํ™”(Replication) ๋‹จ๋ฐฉํ–ฅ ๊ตฌ์„ฑ

2022. 11. 29. 04:07ใ†System ์ž‘์—…์‹ค/DBMS

728x90
๋ฐ˜์‘ํ˜•


 

 

 

 

๊ณ ์„ฑ๋Šฅ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ œ์ž‘์„ ์œ„ํ•œ MariaDB ์„ฑ๋Šฅ ๋ถ„์„๊ณผ ์ตœ์ ํ™”

COUPANG

www.coupang.com

"์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค."

 

 

 

 

 

๐Ÿ—‚ ๋ชฉ์ฐจ

โ— [Infra] Maria DB(MySQL) ์ด์ค‘ํ™”(Replication) ๋‹จ๋ฐฉํ–ฅ ๊ตฌ์„ฑ
โ— [Spring Boot][MariaDB] ์ด์ค‘ํ™”๋œ Data Base ์ดˆ๊ธฐ ๊ตฌ์„ฑ


 

 

 

๐Ÿš€ Maria DB(MySQL) ์ด์ค‘ํ™”

    ๐Ÿ”ฝ  ๊ฐœ์š”

        ๐Ÿ“ฆ ์†Œ๊ฐœ

์ฃผ๋‹ˆํ•˜๋ž‘์ด ํ˜„์žฌ ์ง„ํ–‰ํ•˜๊ณ  ์žˆ๋Š” ๋ชจ์ž„์—์„œ Data Base๋ฅผ ์–ด๋–ค ๊ฒƒ์„ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์—์„œ ์‚ฌ์šฉํ• ์ง€ ๊ณ ๋ฏผํ•˜๊ณ , Maria DB๋ฅผ ์„ ํƒํ•˜๊ธฐ๋กœ ํ•˜์˜€์–ด์š”.

๊ทธ๋Ÿฐ๋ฐ, ํ˜„์—…์—์„œ๋Š” Data Base ๋ถ€ํ•˜๋ฅผ ๋ง‰๊ธฐ ์œ„ํ•ด ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์ž‘์—…์„ ํ•˜๊ฒŒ ๋˜๋Š”๋ฐ, ๋ชจ์ž„์€ ์ผ๋‹จ Data Base ์ด์ค‘ํ™”๋ฅผ ํ†ตํ•ด ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์—์„œ์˜ ๋ถ€ํ•˜๋ฅผ ๋ง‰์•„๋ณด๋Š” ๊ฒƒ์œผ๋กœ ๊ฒฐ์ •์„ ํ•˜์˜€์–ด์š”.

์ฐจํ›„ ์šด์˜ ํ™˜๊ฒฝ Data Base๋Š” ์–ด๋–ป๊ฒŒ ๊ตฌ์„ฑํ• ์ง€ ์•„์ง ์ •ํ•ด์ง€์ง€ ์•Š์•˜์ง€๋งŒ, Data Base ์ด์ค‘ํ™”๋ฅผ ํ†ตํ•ด Back End์—์„œ ์–ด๋–ป๊ฒŒ ์ด์ค‘ํ™”๋œ Data Base๋ฅผ ์ด์šฉํ•  ์ˆ˜ ์žˆ์„์ง€์— ๋Œ€ํ•ด ๊ณ ๋ฏผํ•˜๊ณ , ๊ณต๋ถ€ํ•˜๊ณ  ์ ์šฉํ•ด ๋ณด๋Š” ์‹œ๊ฐ„์„ ๊ฐ–์œผ๋ ค๊ณ  ํ•ด์š”.

 

MariaDB (MySQL) Replication(๋ณต์ œ)๋ž€?

Replication์€ ๋ณต์ œ๋ฅผ ๋œปํ•˜๋ฉฐ, 2๊ฐœ ์ด์ƒ์˜ DBMS๋ฅผ ๋‚˜๋ˆ  ๊ฐ๊ฐ์˜ Data๋ฅผ ๋‚˜๋ˆ  ์ €์žฅํ•˜๋Š” ๋ฐฉ์‹์ด์—์š”.
์ด ๋•Œ, ๊ฐ๊ฐ์˜ DBMS๋Š” Master - Master ํ˜น์€ Master - Slave ํ˜•ํƒœ๋กœ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด์—์š”.
๋˜ํ•œ, ์ด๊ฒƒ์€ ๋น„๋™๊ธฐ ๋ณต์ œ ๋ฐฉ์‹์„ ์ด์šฉํ•˜๊ฒŒ ๋˜๊ณ , Master์™€ Slave์— ๊ฐ๊ฐ ๊ณ ์œ  ๋ฒˆํ˜ธ๋ฅผ ์ง€์ •ํ•˜์—ฌ ์ด ๊ณ ์œ  ๋ฒˆํ˜ธ๋ฅผ ํ†ตํ•ด ์„œ๋กœ๋ฅผ ์ธ์‹ํ•˜์—ฌ ์ž‘๋™ํ•˜๊ฒŒ ํ•ด์•ผ ํ•ด์š”.

๐Ÿ’ก ์ฐธ๊ณ  ์‚ฌํ•ญ
Master DBMS ์—ญํ•  :
WAS(Web Application Server)์—์„œ ์‚ฝ์ž… / ์ˆ˜์ • / ์‚ญ์ œ ์š”์ฒญ์‹œ Binary Log๋ฅผ ๋งŒ๋“ค์–ด Slave Server๋กœ ๋ณด๋‚ด๋Š” ์—ญํ• .
Master๋Š” WAS๋กœ๋ถ€ํ„ฐ ์š”์ฒญ๋œ Data ์‚ฝ์ž… / ์ˆ˜์ • / ์‚ญ์ œ ๊ธฐ๋Šฅ์„ ํ•˜๋Š” ํ™˜๊ฒฝ์œผ๋กœ ๊ตฌ์„ฑํ•˜๋Š” ๊ฒƒ์ด ์ผ๋ฐ˜์ 

Slave DBMS ์—ญํ•  :
Master DBMS๋กœ ๋ถ€ํ„ฐ ์ „๋‹ฌ ๋ฐ›์€ Binary Log๋ฅผ ํ†ตํ•ด ์‹ค์ œ DB๋‚ด์— Data๋ฅผ ๊ตฌ์„ฑ
Slave๋Š” WAS๋กœ๋ถ€ํ„ฐ ์š”์ฒญ์„ ํ†ตํ•ด Data๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š” (Select) ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•ด ๊ตฌ์„ฑํ•˜๋Š” ๊ฒƒ์ด ์ผ๋ฐ˜์ 

 

์ตœ์ดˆ Master DBMS์˜ Insert / Update ๋“ฑ์— Event๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ์ฆ‰์‹œ Slave Server์— ๋ณ€๊ฒฝ๋œ Data ๋‚ด์šฉ์ด ๋‹ด๊ธด Binary Log๋ฅผ ์ „๋‹ฌํ•˜๊ฒŒ ๋˜์š”. ์ด๋Ÿฌํ•œ ๊ณผ์ •์œผ๋กœ ์–‘ ์ชฝ DBMS๋ฅผ ๋™์ผํ•œ Data๊ฐ€ ์กด์žฌํ•˜๋„๋ก Syncํ•  ์ˆ˜ ์žˆ๊ณ , Master๊ฐ€ ์žฅ์• ๊ฐ€ ๋‚˜๊ฒŒ ๋˜๋ฉด Slave ์„œ๋ฒ„๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์ฒ˜๋ฆฌํ•  ์ˆ˜๋„ ์žˆ์–ด์š”.

ํ•˜์ง€๋งŒ, ์ฃผ๋‹ˆํ•˜๋ž‘์ด ์ด์ค‘ํ™”๋ฅผ ํ•˜๋ ค๋Š” ์ด์œ ๋Š” ์œ„์™€ ๊ฐ™์€ ์ด์œ ๋„ ์žˆ์ง€๋งŒ, ํ•œ DBMS์— ๋ถ€ํ•˜๊ฐ€ ์ง‘์ค‘๋˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•˜๊ณ  ์‹ถ๊ธฐ ๋•Œ๋ฌธ์ด์—์š”.




Binary Log๋ž€?

binarylog๋Š” binlog๋ผ๊ณ ๋„ ๋ถ€๋ฅด๊ณ  ์žˆ์–ด์š”.
MariaDB(MySQL)์—์„œ ๋ฐœ์ƒํ•˜๋Š” ๋ชจ๋“  ๋‚ด์—ญ์„ ๊ธฐ๋กํ•˜๋Š” Log File์ด๊ณ , ์ด๊ฒƒ์€ ๊ธฐ๋ณธ์ ์œผ๋กœ ๋น„ํ™œ์„ฑํ™” ๋˜์–ด ์žˆ๋Š”๋ฐ, ์ด๋ฅผ ํ™œ์„ฑํ™” ์‹œ์ผœ์ฃผ์–ด์•ผ ํ•ด์š”.

 

 

๋ณต์ œ ๋ฐฉ์‹

STATEMENT : SQL๋ฌธ ๋ณต์‚ฌ
ROW - ๋ณ€๊ฒฝ๋œ row๋งŒ ๋ณต์‚ฌ
MIXED - ๋‘๊ฐ€์ง€ ๋ฐฉ์‹ ํ˜ผ์šฉ

 

์ถœ์ฒ˜ : https://server-talk.tistory.com


User๋ฅผ WAS๋ผ๊ณ  ์ƒ๊ฐํ•˜๊ณ , ์ตœ์ดˆ ์ด์šฉ์ž๊ฐ€ Web์„ ํ†ตํ•ด ์–ด๋–ค ์š”์ฒญ์„ ํ•˜๊ฒŒ ๋˜๋ฉด ํ•ด๋‹น ์š”์ฒญ์€ WAS๋กœ ์ „๋‹ฌ๋˜๊ฒŒ ๋˜๊ณ , WAS๋Š” Query๋ฅผ ๋งŒ๋“ค์–ด Master DBMS์— ์ „๋‹ฌํ•˜๊ฒŒ ๋  ๊ฑฐ์—์š”. ๊ทธ๋ฆฌ๊ณ  ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ Binary Log๋กœ ๋งŒ๋“ค์–ด Slaver Server์— ์ „๋‹ฌํ•˜๊ฒŒ ๋˜๊ณ , ์ด๋ฅผ ํ†ตํ•ด Data Sync๊ฐ€ ๋˜๋„๋ก ํ•˜๋Š” ๊ฒƒ์ด์—์š”. 

 

 

 

 

Maria DB(MySQL) ๋‹จ๋ฐฉํ–ฅ ์ด์ค‘ํ™”

์ถœ์ฒ˜ : https://server-talk.tistory.com


์ด์šฉ์ž๊ฐ€ ๋งŽ๊ฒŒ ๋˜๋ฉด ์—„์ฒญ๋‚˜๊ฒŒ ๋งŽ์€ ์š”์ฒญ์ด ๋“ค์–ด์˜ค๊ฒŒ ๋  ๊ฒƒ์ด๊ณ ,
์ด๊ฒƒ์€ ๋ชจ๋“  Server์— ๋ถ€ํ•˜๊ฐ€ ๊ฑธ๋ฆฌ๊ฒŒ ๋˜๋Š” ๊ฒฐ๊ณผ๋ฅผ ๋งŒ๋“ค๊ฒŒ ๋˜์š”.

์ด ๋•Œ, DBMS์— ๊ณผ๋ถ€ํ•˜๊ฐ€ ๊ฑธ๋ฆฌ๋Š” ๊ฒƒ์„ ๋ง‰๊ธฐ ์œ„ํ•ด MariaDB (MySQL)
Replication์„ ์ด์šฉํ•˜์—ฌ ๊ฐ™์€ DB๋ฅผ ์—ฌ๋Ÿฌ ๋Œ€๋กœ ๋ถ„์‚ฐํ•˜์—ฌ ๋ถ€ํ•˜ ๋ถ„์‚ฐ์„ ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด์—์š”.



์ถœ์ฒ˜ : https://danidani-de.tistory.com/


โˆ™ Data Base ์‚ฌ์šฉ์ž ํ˜น์€ WAS๋Š” Insert, Update, Delete ๋“ฑ์œผ๋กœ Data ๋ณ€๊ฒฝ ์š”์ฒญ์„ ์œ„ํ•œ Query๋ฅผ ์ „๋‹ฌ.
โˆ™ Master DBMS๋Š” Binary Log์— Data ๋ณ€๊ฒฝ ์‚ฌํ•ญ ๊ธฐ๋ก.
โˆ™ Connection Thread๋Š” DB Storage ์—”์ง„์— Commit ์ˆ˜ํ–‰.
โˆ™ Slave๊ฐ€ I/O Thread๋ฅผ ํ†ตํ•ด Master์—๊ฒŒ Event ์š”์ฒญ ์‹œ Master์˜ Binary Log Dump Thread(Master Thread)๋ฅผ
    ํ†ตํ•ด Binary Log๋ฅผ ์ „์†ก.
โˆ™ Slave๋Š” ์ „์†ก ๋ฐ›์€ File์„ Relay Log์— ๊ธฐ๋ก.
โˆ™ Slave๋Š” SQL Thread๋ฅผ ํ†ตํ•ด Storage ์—”์ง„์— ๋ณ€๊ฒฝ ์‚ฌํ•ญ ๊ธฐ๋ก.






Maria DB(MySQL) ์–‘๋ฐฉํ–ฅ ์ด์ค‘ํ™”

์ถœ์ฒ˜ : https://server-talk.tistory.com


Maria DB๋ฅผ ์ด์ค‘ํ™” ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์€ ์ด ์™ธ์—๋„ ์—ฌ๋Ÿฌ๊ฐ€์ง€๊ฐ€ ์žˆ์ง€๋งŒ, ๋Œ€ํ‘œ์ ์œผ๋กœ๋Š” ํฌ๊ฒŒ ๋‘๊ฐ€์ง€ ๊ฒฝ์šฐ๋ฅผ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ์–ด์š”.
์—ฌ๊ธฐ์„œ ์ฃผ๋‹ˆํ•˜๋ž‘์€ ๋ชจ์ž„์˜ ํ™˜๊ฒฝ์— ๋งž๋Š” ์ด์ค‘ํ™”๋ฅผ ๊ณ ๋ฏผํ•ด ๋ณด์•˜๊ณ , ๊ตณ์ด ๋‘ ๊ฐœ์˜ Data Base์— ์ฝ๊ธฐ / ์“ฐ๊ธฐ ๋ชจ๋“  ์ž‘์—…์„ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•˜์—ฌ ์ฒ˜๋ฆฌ๋ฅผ ํ•  ํ•„์š”๊ฐ€ ์—†๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ๋‹จ๋ฐฉํ–ฅ ์ด์ค‘ํ™”๋ฅผ ๊ตฌํ˜„ํ•˜๊ธฐ๋กœ ๊ฒฐ์‹ฌํ•˜์˜€์–ด์š”.





 

 

โ€ป ์ฃผ์˜์‚ฌํ•ญ

ํ˜ธํ™˜์„ฑ์„ ์œ„ํ•ด Replication์„ ์ด์šฉํ•˜๋Š” ๋ชจ๋“  DBMS๋Š” ๋™์ผํ•œ ํ™˜๊ฒฝ์œผ๋กœ ๊ตฌ์„ฑํ•˜๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•ฉ๋‹ˆ๋‹ค.
Replication์„ ์ด์šฉํ•˜๋Š” DBMS Version์ด ๊ฐ๊ธฐ ๋‹ค๋ฅธ ๊ฒฝ์šฐ Slave Server๊ฐ€ Master Server๋ณด๋‹ค ์ƒ์œ„ Version์ด์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค.
Replication ๊ธฐ๋™ ์‹œ Master Server๋ถ€ํ„ฐ ์˜ฌ๋ฆฌ๊ณ , Slave๋ฅผ ์˜ฌ๋ ค์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๋˜ํ•œ, Replication์„ ์ด์šฉํ•˜๊ฒŒ ๋˜๋ฉด ๊ณ„์†์ ์œผ๋กœ Binary Log๊ฐ€ ์Œ“์ด๊ฒŒ ๋˜๊ณ , ์ด๋Š” ๊ฒฐ๊ตญ Storage ์šฉ๋Ÿ‰์„ ์žก์•„๋จน๋Š” ์›์ธ์ด ๋˜์š”. ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— Cron์„ ์ด์šฉํ•ด์„œ ์ •๋ฆฌ๋ฅผ ์ฃผ๊ธฐ์ ์œผ๋กœ ํ•˜๊ฑฐ๋‚˜, my.cnf์— expire_logs_days์— Log์— ๋Œ€ํ•œ ์œ ํšจ๊ธฐ๊ฐ„์„ ์ง€์ •ํ•ด ์ฃผ์–ด์•ผ ํ•ด์š”.

Replication ๊ณผ์ •์—์„œ Error๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด Slave๋Š” Error Log๋ฅผ ์ž‘์„ฑํ•˜๊ฒŒ ๋˜์š”.
๋‚˜์ค‘์— Server ๊ด€๋ฆฌ์ž ๋“ฑ์ด Error๋ฅผ ์ถ”์ ํ•˜์—ฌ Binary Log๋ฅผ ๋ถ„์„ํ•˜์—ฌ ์œ ์‹ค๋œ ์ž๋ฃŒ๋ฅผ ๋ณต๊ตฌํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•  ์ˆ˜ ์žˆ๋‹ต๋‹ˆ๋‹ค.





 

 

    ๐Ÿ”ฝ  Master Server

        ๐Ÿ“ฆ Version ํ™•์ธ

์ตœ์ดˆ Master DBMS์— ์„ค์ • ์ž‘์—…์„ ํ•ด์ค„๊ฒŒ์š”.

๋จผ์ € ํ•ด๋‹น DBMS Version์„ ํ™•์ธํ•ด ๋ณด์•˜์–ด์š”.

select version();

 

select version();


ํ•ด๋‹น DBMS๋Š” Synology NAS์—์„œ Docker Service๋ฅผ ์ด์šฉํ•ด ๊ตฌ์ถ•ํ•œ Maria DB์—์š”.


 

 

        ๐Ÿ“ฆ ์„ค์ •

Data Base ์ƒ์„ฑ๊ณผ ๊ณ„์ • ์ƒ์„ฑ

 

# Data Base ์ƒ์„ฑ
create database test_replication character set utf8;

# Replication์„ ์œ„ํ•œ ๊ณ„์ • ์ƒ์„ฑ
grant replication slave on *.* to 'repl_adm'@'%' identified by '{๊ณ„์ • ๋น„๋ฐ€ ๋ฒˆํ˜ธ}';


์ด๋ ‡๊ฒŒ DB๋ฅผ ๋งŒ๋“ค๊ณ , ๊ณ„์ •์„ ๋จผ์ € ๋งŒ๋“ค์–ด ์ฃผ์–ด์•ผ ํ•ด์š”.

๋‹ค์Œ์€ ํ•ด๋‹น DBMS์˜ OS์—์„œ ์ž‘์—…์„ ํ•ด๋ณด๋ ค ํ•ด์š”.

vim /etc/mysql/my.cnf

[mysqld]
log-bin = mysql-bin
server-id = 1
binlog_format = row
expire_logs_days = 90




์œ„์™€ ๊ฐ™์ด 32 ~ 36๋ฒˆ์งธ ์ค„์„ ๋„ฃ์–ด์ฃผ์—ˆ์–ด์š”.

๐Ÿ’ก ์ฐธ๊ณ  ์‚ฌํ•ญ
mysql-bin : Binary log File Name
server-id : master์™€ Slave์˜ ๊ฐ’๋งŒ ๋‹ค๋ฅด๋ฉด ์–ด๋–ค ๊ฐ’์ด๋˜ ์‚ฌ์šฉ ๊ฐ€๋Šฅ
binlog_format : ์ด์ค‘ํ™” ์œ ํ˜• ์„ ํƒ (STATEMENT, ROW, MIXED ์ค‘ ์„ ํƒ)
expire_logs_days : Binary Log ๋ณด๊ด€ ๊ธฐ๊ฐ„ ์„ค์ •

 

service mariadb restart


๊ทธ๋Ÿฐ ๋’ค MariaDB Deamon์„ ์žฌ ๊ธฐ๋™ํ•˜์—ฌ ์ฃผ์—ˆ์–ด์š”.

์ฃผ๋‹ˆํ•˜๋ž‘์€ ํ˜„์žฌ Master DBMS๋ฅผ Synology NAS Docker์— ๋„์šด ๊ฒƒ์ด์—์š”.
๊ทธ๋Ÿฐ๋ฐ ์œ„์™€ ๊ฐ™์ด ์žฌ๊ธฐ๋™์— ๋ฌธ์ œ๊ฐ€ ์žˆ์–ด Synology NAS์—์„œ ์ง์ ‘ ์žฌ๊ธฐ๋™์„ ํ•ด์ฃผ์—ˆ์–ด์š”.


show master status;

 

Binary Log ์ •๋ณด


์œ„์™€ ๊ฐ™์ด Binary Log๊ฐ€ ์ž…๋ ฅ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.
File๋ช…๊ณผ Position์€ ์ž˜ ๊ธฐ๋กํ•ด๋‘์–ด์•ผ ํ•ด์š”.

๋˜ํ•œ, Data Base ์žฌ ๊ธฐ๋™ ์‹œ File๋ช…๊ณผ Position ๋ฒˆํ˜ธ๊ฐ€ ๋ณ€๊ฒฝ๋  ์ˆ˜ ์žˆ๋‹ค๋Š” ์ ์„ ์žŠ์œผ๋ฉด ์•ˆ๋˜์š”.

 

 

"์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค."

 

 

    ๐Ÿ”ฝ  Slave Server

        ๐Ÿ“ฆ Version ํ™•์ธ

์ด๋ฒˆ์—๋Š” Slave Server๋ฅผ ๊ฐ€์ง€๊ณ  ๋†€์•„๋ณด๋ ค๊ณ  ํ•ด์š”.

์ตœ์ดˆ Version ๋ถ€ํ„ฐ ํ™•์ธํ•ด ๋ณผ๊ฒŒ์š”.

select version();


Master DBMS์™€ ๋™์ผํ•œ Version์œผ๋กœ ๋งž์ถ”๊ณ  ์ž‘์—…์„ ํ•˜๋Š” ์ค‘์ด์—์š”.


ํ•ด๋‹น DBMS๋Š” Laptop์— CentOS 7 Version์„ ์˜ฌ๋ฆฌ๊ณ , ๊ตฌ์ถ•ํ•œ Maria DB์—์š”.
์ด ์„œ๋ฒ„์—์„œ๋Š” Docker๋ฅผ ์ด์šฉํ•˜์ง€ ์•Š์•˜์–ด์š”.


vim /etc/my.cnf

[mysqld]
log-bin = mysql-bin
server-id = 2
binlog_format = row
expire_logs_days = 90


ํ•ด๋‹น Server๋Š” Master์™€ ๋‹ค๋ฅด๊ฒŒ my.cnf ์œ„์น˜๊ฐ€ etc Directory ๋ฐ”๋กœ ์•ˆ์— ์žˆ์—ˆ์–ด์š”.
์•„๋ฌด๋ž˜๋„ Docker๋ฅผ ๋งŒ๋“  ์‚ฌ๋žŒ์ด ์กฐ์ ˆ์„ ํ•ด์„œ ๊ทธ๋Ÿฐ๊ฐ€๋ด์š”.

Slave๋„ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ 12 ~ 16๋ฒˆ์งธ๊นŒ์ง€ ์ถ”๊ฐ€ํ•ด ์ฃผ์—ˆ์–ด์š”.

๋‹ค๋งŒ, Master์™€ ๋‹ค๋ฅธ ๋ถ€๋ถ„์€ server-id ๋ถ€๋ถ„์ธ๋ฐ, ๋ฐ˜๋“œ์‹œ Master์™€ ๋‹ค๋ฅธ ๋ฒˆํ˜ธ๋ฅผ ๊ธฐ์ž…ํ•ด ์ฃผ์–ด์•ผํ•ด์š”.


systemctl restart mariadb


MariaDB Deamon์„ ๋‹ค์‹œ ์žฌ ๊ธฐ๋™ํ•˜์—ฌ ์ฃผ์—ˆ์–ด์š”.


mysql -u root -p


MariaDB์— root ๊ณ„์ •์œผ๋กœ ์ ‘์†์„ ํ•ด ์ฃผ์—ˆ์–ด์š”.
์ฃผ๋‹ˆํ•˜๋ž‘์€ root ๊ณ„์ •์ด ์™ธ๋ถ€์—์„œ ์ ‘์†ํ•˜์ง€ ๋ชปํ•˜๋„๋ก ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์—
SQL Tool์„ ์ด์šฉํ•ด์„œ ๋ถ™์„ ์ˆ˜ ์—†์–ด CLI๋กœ ์ง์ ‘ ์ž‘์—…์„ ํ•˜๋ คํ•ด์š”.


๋ฐ˜์‘ํ˜•
change master to
    -> master_host="192.168.100.1",
    -> master_user="{๊ณ„์ • ์ด๋ฆ„}",
    -> master_password="{๊ณ„์ • ๋น„๋ฐ€๋ฒˆํ˜ธ}",
    -> master_port={MariaDB Port ๋ฒˆํ˜ธ},
    -> master_log_file="{Master DBMS Binary Log File Name}",
    -> master_log_pos={Master DBMS Binary Log Position ๋ฒˆํ˜ธ};


์œ„์™€ ๊ฐ™์ด Master์™€ ์—ฐ๊ฒฐ์„ ์œ„ํ•œ Query๋ฅผ ์ž‘์„ฑํ•ด ์ฃผ์—ˆ์–ด์š”.


start slave;


์œ„์˜ Query๋กœ Slave ๋™์ž‘์„ ์‹คํ–‰ํ•ด ์ฃผ์—ˆ์–ด์š”.


728x90

show slave status\G;


์œ„์™€ ๊ฐ™์ด ์—ฐ๊ฒฐ ์ •๋ณด๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.

 

 

show slave status\G;


๋งŒ์•ฝ ์œ„์™€ ๊ฐ™์ด Last_IO_Error์— Error๋ฌธ์ด ๋‚˜์˜จ๋‹ค๋ฉด Master Server์™€์˜ ์—ฐ๊ฒฐ์— ๋ฌธ์ œ๊ฐ€ ์žˆ๋Š” ๊ฒƒ์ด์—์š”.
์ฃผ๋‹ˆํ•˜๋ž‘์€ Port ๋ฒˆํ˜ธ๋ฅผ ๋ฐ”๊ฟจ๋Š”๋ฐ, ๊ธฐ์กด Port๋ฒˆํ˜ธ๋ฅผ ์ด์šฉํ•˜๊ณ , IP๋ฅผ ์ž˜๋ชป ์ž…๋ ฅํ•ด์„œ ๋‚˜์˜ค๋Š” ๋ฌธ์ œ์˜€์–ด์š”.






create database {DB ์ด๋ฆ„} character set utf8;


์ฃผ๋‹ˆํ•˜๋ž‘์€ ์œ„์™€ ๊ฐ™์ด Project์—์„œ ์‚ฌ์šฉํ•  DB๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์–ด์š”.


show databases;


DB๋Š” ์ •์ƒ์ ์œผ๋กœ ์ž˜ ๋งŒ๋“ค์–ด์กŒ์–ด์š”.






show databases;


Slave DBMS์—์„œ๋„ ์œ„์™€ ๊ฐ™์ด ๋งŒ๋“ค์–ด ์ง„๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.


 


๋‹ค์‹œ Master์—์„œ DB์•ˆ์— Table์„ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์–ด์š”.



๊ทธ๋ฆฌ๊ณ  ์œ„์™€ ๊ฐ™์ด ๊ฐ’์„ ๋„ฃ์–ด์ค˜๋ดค์–ด์š”.

๊ณผ์—ฐ Slave์—๋„ ์ƒ๊ฒผ์„๊นŒ์š”?



์œ„์™€ ๊ฐ™์ด Slave์—๋„ ๋™์ผํ•œ ๊ฐ’์ด ๋‚˜์˜ค๋Š” ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.

์ž‘์—… ์„ฑ๊ณต์ด์—์š”!

์ด๋ ‡๊ฒŒ ํ•˜๋ฉด DB ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ, ์‚ฌ์šฉ์ž ๊ณ„์ •๋„ ๋ชจ๋‘ Master์—์„œ๋งŒ ๋งŒ๋“ค๋ฉด ๋ฐ”๋กœ Slave๋กœ Syncํ•  ์ˆ˜ ์žˆ์–ด์š”.


์ด์ œ Data Base ์ด์ค‘ํ™”๋ฅผ ํ•ด ๋ณด์•˜์œผ๋‹ˆ ๋‹ค์Œ์—๋Š” BackEnd ๊ฐœ๋ฐœ์ž ๋‹ต๊ฒŒ

Spring Boot์—์„œ ์ด์ค‘ํ™”ํ•œ Data Base๋ฅผ ์„ค์ •ํ•˜๊ณ , ๊ฐ€์ง€๊ณ  ๋†€์•„๋ณผ๊ฒŒ์š”.





๐Ÿง ์ฐธ๊ณ  ์ž๋ฃŒ

 

MySQL(MariaDB) Replication - DB ์‹ค์‹œ๊ฐ„ ์ด์ค‘ํ™” :: DANIDANI

MySQL(Maria DB) Replication ์ด๋ž€? DB ๋ณต์ œ๋ฅผ ์˜๋ฏธํ•œ๋‹ค. 2๋Œ€ ์ด์ƒ์˜ DBMS๋ฅผ ๋‚˜๋ˆ ์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค. (master - slave, master - master, ๋‹ค์ค‘ slave ๋ฐฉ์‹ ๋“ฑ) ๋น„๋™๊ธฐ ๋ณต์ œ ๋ฐฉ์‹์ด๋‹ค. master์™€ slave์— ๊ฐ๊ฐ ์„œ

danidani-de.tistory.com



 

mariadb(mysql) ์ด์ค‘ํ™” ๊ตฌ์„ฑ

์ด์ „์— ํด๋Ÿฌ์Šคํ„ฐ ๊ตฌ์ถ•์— ๋Œ€ํ•œ ๋‚ด์šฉ์„ ์ •๋ฆฌํ–ˆ๋Š”๋ฐ, ์˜ค๋Š˜์€ ์ด์ค‘ํ™” ๊ตฌ์„ฑ์„ ์ •๋ฆฌํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ํด๋Ÿฌ์Šคํ„ฐ๋กœ ๊ตฌ์„ฑํ•˜๋Š”๊ฒŒ ์ด์ค‘ํ™” ๊ตฌ์„ฑ ๋ณด๋‹ค๋Š” ๋งŽ์€ ์žฅ์ ์ด ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•˜์ง€๋งŒ ์“ฐ์ž„์ƒˆ์— ๋”ฐ๋ผ ํ•„์š”ํ•œ

ongamedev.tistory.com

 

 

 

MySQL Replication(๋ณต์ œ) - ๋‹จ๋ฐฉํ–ฅ ์ด์ค‘ํ™”

MySQL Replication์„ ์ด์šฉํ•˜์—ฌ DBMS ๋‹จ๋ฐฉํ–ฅ ์ด์ค‘ํ™”ํ•˜๊ธฐ ์›น์„œ๋ฒ„ ๋ถ€ํ•˜๋กœ ์ธํ•ด L4๋ฅผ ์ด์šฉํ•˜์—ฌ ๋กœ๋“œ๋ฐธ๋Ÿฐ์‹ฑ์œผ๋กœ ์›น์„œ๋ฒ„์˜ ๋ถ€ํ•˜๋ฅผ ํ•ด๊ฒฐํ•˜์˜€์ง€๋งŒ, DB ์„œ๋ฒ„์˜ ๋ถ€ํ•˜๋กœ ์ธํ•˜์—ฌ ์‚ฌ์ดํŠธ๊ฐ€ ๋Š๋ฆฌ๊ฒŒ ์—ด๋ฆฌ๋Š” ํ˜„์ƒ์ด ๋ฐœ

server-talk.tistory.com

 

 

 

๊ณ ์„ฑ๋Šฅ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ œ์ž‘์„ ์œ„ํ•œ MariaDB ์„ฑ๋Šฅ ๋ถ„์„๊ณผ ์ตœ์ ํ™”

COUPANG

www.coupang.com

"์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค."

 

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•