Skip to content

gjlee0802/ElasticStack-Kafka-Docker-Study

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

81 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๋ชฉ์ฐจ ์ •๋ฆฌ

ElasticStack ์šฐ๋ถ„ํˆฌ ํ™˜๊ฒฝ์—์„œ ์„ค์น˜
ELK๊ตฌ์„ฑ์š”์†Œ

์—˜๋ผ์Šคํ‹ฑ์„œ์น˜

Elasticsearch ์šฉ์–ด์ •๋ฆฌ
Elasticsearch ํŠน์ง•
Elasticsearch ๋ฐ์ดํ„ฐ ์ƒ‰์ธ
Elasticsearch ์‹คํ–‰ํ™˜๊ฒฝ ์„ค์ •
...

ํ‚ค๋ฐ”๋‚˜

ํ‚ค๋ฐ”๋‚˜ ๊ธฐ๋ณธ
ํ‚ค๋ฐ”๋‚˜ ์ฝ”๋กœ๋‚˜ ๋Œ€์‹œ๋ณด๋“œ ๋งŒ๋“ค๊ธฐ
...

์ปจํ…Œ์ด๋„ˆ

OCI์™€ CRI
์ €์ˆ˜์ค€ ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„๊ณผ ๊ณ ์ˆ˜์ค€ ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„
์ปจํ…Œ์ด๋„ˆ์™€ VMs์˜ ์ฐจ์ด
๋„์ปค ์‹ค์Šต-๊ธฐ๋ณธ ๋ช…๋ น์–ด
๋„์ปค ์‹ค์Šต-์ด๋ฏธ์ง€ ์ƒ์„ฑ
๋„์ปคํ—ˆ๋ธŒ ์ด์šฉ
...

Kafka

Producer & Consumer
Topic
Broker
Replication
ISR
Lag
Burrow
Zookeeper
...

ElasticStack ์šฐ๋ถ„ํˆฌ ํ™˜๊ฒฝ์—์„œ ์„ค์น˜

yoonje๋‹˜์˜ ์•„๋ž˜ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์—์„œ 'tuto'ํŒŒ์ผ์„ https://github.com/gjlee0802/ElasticStackStudy/blob/main/tuto ๋กœ ๋Œ€์ฒดํ•˜์—ฌ ์ˆ˜ํ–‰.
yoonje๋‹˜์˜ ์„ค์น˜ ํŠœํ† ๋ฆฌ์–ผ: https://github.com/yoonje/elastic-stack-tutorial
tuto์—์„œ ํŒจํ‚ค์ง€ ๋‹ค์šด๋กœ๋“œ ์ฃผ์†Œ ์ˆ˜์ •, ์šฐ๋ถ„ํˆฌ ํ™˜๊ฒฝ์— ๋งž๊ฒŒ ์ˆ˜์ •
์ฃผ์˜์‚ฌํ•ญ: ์‚ฌ์šฉ์ž๋ช… "user"์„ ๊ธฐ์ค€์œผ๋กœ ํ•จ.

ElasticStackStudy1

ELK๊ตฌ์„ฑ์š”์†Œ(Elasticsearch,Logstash,Kibana)

Elasticsearch (๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค)

Logstash๋กœ๋ถ€ํ„ฐ ๋ฐ›์€ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฒ€์ƒ‰ ๋ฐ ์ง‘๊ณ„๋ฅผ ํ•˜์—ฌ ํ•„์š”ํ•œ ๊ด€์‹ฌ ์žˆ๋Š” ์ •๋ณด๋ฅผ ํš๋“.
Lucene ๊ฒ€์ƒ‰์—”์ง„ ๊ธฐ๋ฐ˜์˜ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋กœ ๊ณ ์„ฑ๋Šฅ์˜ ๊ฒ€์ƒ‰ ๊ธฐ๋Šฅ, ๋Œ€๊ทœ๋ชจ ๋ถ„์‚ฐ ์‹œ์Šคํ…œ ๊ธฐ๋Šฅ ๋“ฑ์„ ์ œ๊ณตํ•œ๋‹ค.
ํ‘œ์ค€ RESTful API์™€ JSON์„ ์ด์šฉํ•ด ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

Logstash (Input > filter > output ์˜ pipeline ๊ตฌ์กฐ๋กœ ์ˆ˜์ง‘ํ•˜๊ณ  ํ•„ํ„ฐ๋งํ•˜์—ฌ ์ „๋‹ฌ)

๋‹ค์–‘ํ•œ ์†Œ์Šค( DB, csvํŒŒ์ผ ๋“ฑ )์˜ ๋กœ๊ทธ ๋˜๋Š” ํŠธ๋žœ์žญ์…˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ˆ˜์ง‘, ์ง‘๊ณ„, ํŒŒ์‹ฑํ•˜์—ฌ Elasticsearch๋กœ ์ „๋‹ฌ
๋ฐ์ดํ„ฐ ์ˆ˜์ง‘ ํŒŒ์ดํ”„๋ผ์ธ ๋„๊ตฌ์ž…๋‹ˆ๋‹ค.
๊ฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ๋ฐ์ดํ„ฐ, ๋กœ์šฐ ๋ฐ์ดํ„ฐ, ์œˆ๋„์šฐ ์ด๋ฒคํŠธ ๋“ฑ์œผ๋กœ๋ถ€ํ„ฐ ๋ฐ์ดํ„ฐ๋ฅผ ์ˆ˜์ง‘ํ•ฉ๋‹ˆ๋‹ค.
๋‹ค์–‘ํ•œ ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์ด์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ์ง‘๊ณ„ ๋ฐ ๋ณด๊ด€, ์„œ๋ฒ„ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ, ํŒŒ์ดํ”„๋ผ์ธ์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ˆ˜์ง‘ํ•˜์—ฌ ํ•„ํ„ฐ๋ฅผ ํ†ตํ•ด ๋ณ€ํ™˜ ํ›„ ElasticSearch๋กœ ์ „์†กํ•ฉ๋‹ˆ๋‹ค.

Kibana (์‹œ๊ฐํ™” ๋‹ด๋‹น)

Elasticsearch์˜ ๋น ๋ฅธ ๊ฒ€์ƒ‰์„ ํ†ตํ•ด ๋ฐ์ดํ„ฐ๋ฅผ ์‹œ๊ฐํ™” ๋ฐ ๋ชจ๋‹ˆํ„ฐ๋ง
Elastic Search์— ์ €์žฅ๋œ ์ •๋ณด๋“ค์„ ๊ฒ€์ƒ‰ ๋ฐ ๋ถ„์„ํ•˜๊ณ  ์‹œ๊ฐํ™”ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ๊ฐ–๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

Beats (๋ฐ์ดํ„ฐ ์ „์†ก ๋‹ด๋‹น)

๊ฒฝ๋Ÿ‰ ์—์ด์ „ํŠธ๋กœ ์„ค์น˜๋˜์–ด ๋ฐ์ดํ„ฐ๋ฅผ Logstash ๋˜๋Š” ElasticSearch๋กœ ์ „์†กํ•ฉ๋‹ˆ๋‹ค.

  1. FileBeat
  • ์„œ๋ฒ„์—์„œ ๋กœ๊ทธํŒŒ์ผ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
  1. PacketBeat
  • ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ ์„œ๋ฒ„๊ฐ„์— ๊ตํ™˜๋˜๋Š” ํŠธ๋žœ์žญ์…˜์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•˜๋Š” ๋„คํŠธ์›Œํฌ ํŒจํ‚ท ๋ถ„์„๊ธฐ ์ž…๋‹ˆ๋‹ค.
  1. MetricBeat
  • ์šด์˜ ์ฒด์ œ ๋ฐ ์„œ๋น„์Šค์—์„œ Metrics๋ฅผ ์ฃผ๊ธฐ์ ์œผ๋กœ ์ˆ˜์ง‘ํ•˜๋Š” ์„œ๋ฒ„ ๋ชจ๋‹ˆํ„ฐ๋ง ์—์ด์ „ํŠธ์ž…๋‹ˆ๋‹ค.
  1. WinlogBeat
  • Windows ์ด๋ฒคํŠธ ๋กœ๊ทธ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

RDBMS์™€ Elasticsearch๋น„๊ต

RDBMS_Elastic RDBMS_Elastic_

Elasticsearch ์šฉ์–ด ์ •๋ฆฌ

1) ํด๋Ÿฌ์Šคํ„ฐ( Cluster )

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

2) ๋…ธ๋“œ( Node )

Elasticsearch๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ํ•˜๋‚˜์˜ ๋‹จ์œ„ ํ”„๋กœ์„ธ์Šค๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.
๊ทธ ์—ญํ• ์— ๋”ฐ๋ผ Master-eligible, Data, Ingest, Tribe ๋…ธ๋“œ๋กœ ๊ตฌ๋ถ„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ํด๋Ÿฌ์Šคํ„ฐ์˜ ์ผ๋ถ€์ด๋ฉฐ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๊ณ  ํด๋Ÿฌ์Šคํ„ฐ์˜ ์ธ๋ฑ์‹ฑ ๋ฐ ๊ฒ€์ƒ‰ ๊ธฐ๋Šฅ์— ์ฐธ์—ฌํ•˜๋Š” ๋‹จ์ผ ์„œ๋ฒ„์ž…๋‹ˆ๋‹ค.
  • ๋…ธ๋“œ์— ํ• ๋‹น๋˜๋Š” ์ž„์˜ UUID์ธ ์ด๋ฆ„์œผ๋กœ ์‹๋ณ„ํ•ฉ๋‹ˆ๋‹ค.
  • ํŠน์ • ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ํด๋Ÿฌ์Šคํ„ฐ ์ด๋ฆ„์œผ๋กœ ๊ฒฐํ•ฉํ•˜๋„๋ก ๋…ธ๋“œ๋ฅผ ๊ตฌ์„ฑ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

3) ์ธ๋ฑ์Šค( Index ) / ์ƒค๋“œ( Shard ) / ๋ณต์ œ( Replica )

index๋Š” RDBMS์—์„œ database์™€ ๋Œ€์‘ํ•˜๋Š” ๊ฐœ๋…์ž…๋‹ˆ๋‹ค.
๋˜ํ•œ shard์™€ replica๋Š” Elasticsearch์—๋งŒ ์กด์žฌํ•˜๋Š” ๊ฐœ๋…์ด ์•„๋‹ˆ๋ผ, ๋ถ„์‚ฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์‹œ์Šคํ…œ์—๋„ ์กด์žฌํ•˜๋Š” ๊ฐœ๋…์ž…๋‹ˆ๋‹ค.

์ธ๋ฑ์Šค

  • ์ƒ‰์ธ ๊ณผ์ •์„ ๊ฑฐ์นœ ๊ฒฐ๊ณผ๋ฌผ, ๋˜๋Š” ์ƒ‰์ธ๋œ ๋ฐ์ดํ„ฐ๊ฐ€ ์ €์žฅ๋˜๋Š” ์ €์žฅ์†Œ์ž…๋‹ˆ๋‹ค.
  • ๋‹ค์†Œ ์œ ์‚ฌํ•œ ํŠน์„ฑ์„ ๊ฐ–๋Š” ๋ฌธ์„œ๋“ค์˜ ์ง‘ํ•ฉ์ž…๋‹ˆ๋‹ค.

์ƒค๋“œ

  • Index๋Š” ์ž ์žฌ์ ์œผ๋กœ ๋‹จ์ผ ๋…ธ๋“œ์˜ ํ•˜๋“œ์›จ์–ด ์ œํ•œ์„ ์ดˆ๊ณผ ํ•  ์ˆ˜ ์žˆ๋Š” ๋งŽ์€ ์–‘์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ๋‹จ์ผ ๋…ธ๋“œ์˜ ๋””์Šคํฌ๊ฐ€ ๋งž์ง€ ์•Š๊ฑฐ๋‚˜ ๋‹จ์ผ ๋…ธ๋“œ์˜ ๊ฒ€์ƒ‰ ์š”์ฒญ๋งŒ ์ฒ˜๋ฆฌํ•˜๊ธฐ์—๋Š” ๋„ˆ๋ฌด ๋Š๋ฆด ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— shards๋ฅผ ์ด์šฉํ•˜์—ฌ Index๋ฅผ ์—ฌ๋Ÿฌ ์กฐ๊ฐ์œผ๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์ˆ˜ํ‰์ ์œผ๋กœ ์ฝ˜ํ…์ธ  ๋ณผ๋ฅจ์„ split/scale ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
  • ์—ฌ๋Ÿฌ ๋…ธ๋“œ์—์„œ ์ž ์žฌ์ ์œผ๋กœ ๋ถ„์‚ฐ์„ ํ†ตํ•ด ์ž‘์—…์„ ๋ถ„์‚ฐ ๋ฐ ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ๋ฅผ ํ•  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์„ฑ๋Šฅ/์ฒ˜๋ฆฌ๋Ÿ‰์ด ํ–ฅ์ƒ๋ฉ๋‹ˆ๋‹ค.

-> ์ƒค๋”ฉ๊ณผ ํŒŒํ‹ฐ์…”๋‹ ์ฐจ์ด

  • ์ƒค๋”ฉ : ์—ฌ๋Ÿฌ์‹œ์Šคํ…œ์— ๋‚˜๋ˆ„์–ด ์ €์žฅ
  • ํŒŒํ‹ฐ์…”๋‹ : ํ•œ ์‹œ์Šคํ…œ์—์„œ ์—ฌ๋Ÿฌ ํ…Œ์ด๋ธ”๋กœ ์ €์žฅ

Shard์™€ Replica ๊ฐœ๋… ์ฐธ๊ณ 1 : https://jiseok-woo.tistory.com/8
Shard์™€ Replica ๊ฐœ๋… ์ฐธ๊ณ 2 : http://guruble.com/elasticsearch-2-shard-replica/

๋ณต์ œ

  • ์žฅ์• ๊ฐ€ ๋ฐœ์ƒํ•  ๊ฒฝ์šฐ ๊ณ ๊ฐ€์šฉ์„ฑ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ๋ณต์ œ๋ณธ ์ƒค๋“œ๋Š” ๋ณต์‚ฌ๋œ ์›๋ณธ/๊ธฐ๋ณธ ์ƒค๋“œ์™€ ๋™์ผํ•œ ๋…ธ๋“œ์— ํ• ๋‹น๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
  • ๋ชจ๋“  ๋ณต์ œ๋ณธ์—์„œ ๊ฒ€์ƒ‰์„ ๋ณ‘๋ ฌ๋กœ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ฒ€์ƒ‰ ๋ณผ๋ฅจ/์ฒ˜๋ฆฌ๋Ÿ‰์„ ์ˆ˜ํ‰ ํ™•์žฅ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ๊ธฐ๋ณธ์ ์œผ๋กœ ๊ฐ ์ธ๋ฑ์Šค๋Š” 4๊ฐœ์˜ ๊ธฐ๋ณธ ์ƒค๋“œ์™€ 1๊ฐœ์˜ ๋ณต์ œ๋ณธ์ด ํ• ๋‹น๋ฉ๋‹ˆ๋‹ค.
  • ๋˜ ๋‹ค๋ฅธ ํ˜•ํƒœ์˜ shard๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋…ธ๋“œ๋ฅผ ์†์‹คํ–ˆ์„ ๊ฒฝ์šฐ ๋ฐ์ดํ„ฐ์˜ ์‹ ๋ขฐ์„ฑ์„ ์œ„ํ•ด ์ƒค๋“œ๋“ค์„ ๋ณต์ œํ•˜๋Š” ๊ฒƒ์ด์ฃ . ๋”ฐ๋ผ์„œ replica๋Š” ์„œ๋กœ ๋‹ค๋ฅธ ๋…ธ๋“œ์— ์กด์žฌํ•  ๊ฒƒ์„ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค.

->Replica๊ฐ€ ํ•„์š”ํ•œ ์ด์œ  2๊ฐ€์ง€

    1. โ€˜๊ฒ€์ƒ‰์„ฑ๋Šฅ(search performance)โ€˜
    1. โ€˜์žฅ์• ๋ณต๊ตฌ(fail-over)โ€˜

ElasticsearchArch

4) ๋ฌธ์„œ( Document )

JSON ํ˜•ํƒœ์˜ ์‹ค์ œ ์˜๋ฏธ์žˆ๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ง„ Elasticsearch ๊ธฐ๋ณธ ์ €์žฅ๋‹จ์œ„
RDB์˜ row, ๋ ˆ์ฝ”๋“œ์™€ ๋น„์Šท.
๋ฌธ์„œ๋Š” ๊ฐ๊ฐ ๊ณ ์œ ํ•œ ID ๊ฐ’์„ ๊ฐ–๋Š”๋‹ค
๊ณ ์œ ํ•œ ID:

  • ์‚ฌ์šฉ์ž ์ง€์ •๊ฐ’ or ๋žœ๋ค๊ฐ’
  • ๋ฐ์ดํ„ฐ๋ฅผ ์ฐพ์•„๊ฐ€๋Š” Meta key ์—ญํ• 

Elasticsearch ํŠน์ง•

Scale out

  • ์ƒค๋“œ๋ฅผ ํ†ตํ•ด ๊ทœ๋ชจ๊ฐ€ ์ˆ˜ํ‰์ ์œผ๋กœ ๋Š˜์–ด๋‚  ์ˆ˜ ์žˆ์Œ

๊ณ ๊ฐ€์šฉ์„ฑ

  • Replica๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ์˜ ์•ˆ์ •์„ฑ์„ ๋ณด์žฅ Replica

Schema Free

  • Json ๋ฌธ์„œ๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ๊ฒ€์ƒ‰์„ ์ˆ˜ํ–‰ํ•˜๋ฏ€๋กœ ์Šคํ‚ค๋งˆ ๊ฐœ๋…์ด ์—†์Œ

Restful

  • ๋ฐ์ดํ„ฐ CURD ์ž‘์—…์€ HTTP Restful API๋ฅผ ํ†ตํ•ด ์ˆ˜ํ–‰ํ•œ๋‹ค. restful

๋ฉ€ํ‹ฐํ…Œ๋„Œ์‹œ (multitenancy)

๋ฐ์ดํ„ฐ๋“ค์€ ์ธ๋ฑ์Šค(Index) ๋ผ๋Š” ๋…ผ๋ฆฌ์ ์ธ ์ง‘ํ•ฉ ๋‹จ์œ„๋กœ ๊ตฌ์„ฑ๋˜๋ฉฐ ์„œ๋กœ ๋‹ค๋ฅธ ์ €์žฅ์†Œ์— ๋ถ„์‚ฐ๋˜์–ด ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.
์„œ๋กœ ๋‹ค๋ฅธ ์ธ๋ฑ์Šค๋“ค์„ ๋ณ„๋„์˜ ์ปค๋„ฅ์…˜ ์—†์ด ํ•˜๋‚˜์˜ ์งˆ์˜๋กœ ๋ฌถ์–ด์„œ ๊ฒ€์ƒ‰ํ•˜๊ณ , ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋“ค์„ ํ•˜๋‚˜์˜ ์ถœ๋ ฅ์œผ๋กœ ๋„์ถœํ•  ์ˆ˜ ํŠน์ง•.

์—ญ์ƒ‰์ธ(inverted index) -> ElasticSearch๊ฐ€ ๋น ๋ฅธ ์ด์œ 

RDB์˜ ๊ฒฝ์šฐ
RDBsearch like ๊ฒ€์ƒ‰: fox๊ฐ€ ํฌํ•จ๋œ ํ–‰๋“ค์„ ๊ฐ€์ ธ์˜จ๋‹ค๊ณ  ํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด Text ์—ด์„ ํ•œ ์ค„์”ฉ ์ฐพ์•„ ๋‚ด๋ ค๊ฐ€๋ฉด์„œ fox๊ฐ€ ์žˆ์œผ๋ฉด ๊ฐ€์ ธ์˜ค๊ณ  ์—†์œผ๋ฉด ๋„˜์–ด๊ฐ€๋Š” ์‹์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค
ElasticSearch์˜ ๊ฒฝ์šฐ
inverted_index
Inverted Index: ์ฑ…์˜ ๋งจ ๋’ค์— ์žˆ๋Š” ์ฃผ์š” ํ‚ค์›Œ๋“œ์— ๋Œ€ํ•œ ๋‚ด์šฉ์ด ๋ช‡ ํŽ˜์ด์ง€์— ์žˆ๋Š”์ง€ ๋ณผ ์ˆ˜ ์žˆ๋Š” ์ฐพ์•„๋ณด๊ธฐ ํŽ˜์ด์ง€์— ๋น„์œ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
Elasticsearch์—์„œ๋Š” ์ถ”์ถœ๋œ ๊ฐ ํ‚ค์›Œ๋“œ๋ฅผ ํ…€(term) ์ด๋ผ๊ณ  ๋ถ€๋ฆ…๋‹ˆ๋‹ค.
์ด๋ ‡๊ฒŒ ์—ญ ์ธ๋ฑ์Šค๊ฐ€ ์žˆ์œผ๋ฉด fox๋ฅผ ํฌํ•จํ•˜๊ณ  ์žˆ๋Š” ๋„ํ๋จผํŠธ๋“ค์˜ id๋ฅผ ๋ฐ”๋กœ ์–ป์–ด์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ…์ŠคํŠธ ๋ถ„์„(Text Analysis)

Elasticsearch์˜ ์• ๋„๋ผ์ด์ €๋Š” 0-3๊ฐœ์˜ ์บ๋ฆญํ„ฐ ํ•„ํ„ฐ(Character Filter)์™€ 1๊ฐœ์˜ ํ† ํฌ๋‚˜์ด์ €(Tokenizer), ๊ทธ๋ฆฌ๊ณ  0-n๊ฐœ์˜ ํ† ํฐ ํ•„ํ„ฐ(Token Filter)๋กœ ์ด๋ฃจ์–ด์ง‘๋‹ˆ๋‹ค. Analyzer
์บ๋ฆญํ„ฐ ํ•„ํ„ฐ: ์ „์ฒด ๋ฌธ์žฅ์—์„œ ํŠน์ • ๋ฌธ์ž๋ฅผ ๋Œ€์น˜ํ•˜๊ฑฐ๋‚˜ ์ œ๊ฑฐํ•˜๋Š”๋ฐ ์ด ๊ณผ์ •์„ ๋‹ด๋‹นํ•˜๋Š” ๊ธฐ๋Šฅ.
ํ† ํฌ๋‚˜์ด์ €: ๋ฌธ์žฅ์— ์†ํ•œ ๋‹จ์–ด๋“ค์„ ํ…€ ๋‹จ์œ„๋กœ ํ•˜๋‚˜์”ฉ ๋ถ„๋ฆฌ ํ•ด ๋‚ด๋Š” ์ฒ˜๋ฆฌ ๊ณผ์ •์„ ๊ฑฐ์น˜๋Š”๋ฐ ์ด ๊ณผ์ •์„ ๋‹ด๋‹นํ•˜๋Š” ๊ธฐ๋Šฅ.(๋ฐ˜๋“œ์‹œ 1๊ฐœ๋งŒ ์ ์šฉ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.)
lowercase ํ† ํฐํ•„ํ„ฐ: ๋Œ€๋ฌธ์ž๋ฅผ ๋ชจ๋‘ ์†Œ๋ฌธ์ž๋กœ ๋ฐ”๊ฟ”์ค๋‹ˆ๋‹ค.
stop ํ† ํฐํ•„ํ„ฐ: ๋ถˆ์šฉ์–ด(stopword, ๊ฒ€์ƒ‰์–ด๋กœ์„œ์˜ ๊ฐ€์น˜๊ฐ€ ์—†๋Š” ๋‹จ์–ด)๋ฅผ ์ œ๊ฑฐ.
snowball ํ† ํฐํ•„ํ„ฐ: ํ˜•ํƒœ์†Œ ๋ถ„์„ ๊ณผ์ •์„ ๊ฑฐ์ณ์„œ ๋ฌธ๋ฒ•์ƒ ๋ณ€ํ˜•๋œ ๋‹จ์–ด๋ฅผ ์ผ๋ฐ˜์ ์œผ๋กœ ๊ฒ€์ƒ‰์— ์“ฐ์ด๋Š” ๊ธฐ๋ณธ ํ˜•ํƒœ๋กœ ๋ณ€ํ™˜.(jumps์™€ jumping์€ ๋ชจ๋‘ jump๋กœ ๋ณ€๊ฒฝ)

์ถœ์ฒ˜ :
https://victorydntmd.tistory.com/308
https://iassad.tistory.com/7
https://heowc.tistory.com/49
https://esbook.kimjmin.net/06-text-analysis/6.1-indexing-data

ElasticStackStudy2

ElasticSearch Data ์ƒ‰์ธ

  • [๋™์‚ฌ] ์ƒ‰์ธ (indexing) : ๋ฐ์ดํ„ฐ๊ฐ€ ๊ฒ€์ƒ‰๋  ์ˆ˜ ์žˆ๋Š” ๊ตฌ์กฐ๋กœ ๋ณ€๊ฒฝํ•˜๊ธฐ ์œ„ํ•ด ์›๋ณธ ๋ฌธ์„œ๋ฅผ ๊ฒ€์ƒ‰์–ด ํ† ํฐ๋“ค์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ์ €์žฅํ•˜๋Š” ์ผ๋ จ์˜ ๊ณผ์ •์ž…๋‹ˆ๋‹ค.
  • [๋ช…์‚ฌ] ์ธ๋ฑ์Šค (index, indices) : ์ƒ‰์ธ ๊ณผ์ •์„ ๊ฑฐ์นœ ๊ฒฐ๊ณผ๋ฌผ, ๋˜๋Š” ์ƒ‰์ธ๋œ ๋ฐ์ดํ„ฐ๊ฐ€ ์ €์žฅ๋˜๋Š” ์ €์žฅ์†Œ์ž…๋‹ˆ๋‹ค. ๋˜ํ•œ Elasticsearch์—์„œ ๋„ํ๋จผํŠธ๋“ค์˜ ๋…ผ๋ฆฌ์ ์ธ ์ง‘ํ•ฉ์„ ํ‘œํ˜„ํ•˜๋Š” ๋‹จ์œ„์ด๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค.
  • ๊ฒ€์ƒ‰ (search) : ์ธ๋ฑ์Šค์— ๋“ค์–ด์žˆ๋Š” ๊ฒ€์ƒ‰์–ด ํ† ํฐ๋“ค์„ ํฌํ•จํ•˜๊ณ  ์žˆ๋Š” ๋ฌธ์„œ๋ฅผ ์ฐพ์•„๊ฐ€๋Š” ๊ณผ์ •์ž…๋‹ˆ๋‹ค.
  • ์งˆ์˜ (query) : ์‚ฌ์šฉ์ž๊ฐ€ ์›ํ•˜๋Š” ๋ฌธ์„œ๋ฅผ ์ฐพ๊ฑฐ๋‚˜ ์ง‘๊ณ„ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•˜๊ธฐ ์œ„ํ•ด ๊ฒ€์ƒ‰ ์‹œ ์ž…๋ ฅํ•˜๋Š” ๊ฒ€์ƒ‰์–ด ๋˜๋Š” ๊ฒ€์ƒ‰ ์กฐ๊ฑด์ž…๋‹ˆ๋‹ค.
    Indexing

ElasticSearch ์‹คํ–‰ ์˜ต์…˜

  • -d : Elasticsearch๋ฅผ ๋ฐฑ๊ทธ๋ผ์šด ๋ฐ๋ชฌ์œผ๋กœ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
  • -p <ํŒŒ์ผ๋ช…> : Elasticsearch ํ”„๋กœ์„ธ์Šค ID๋ฅผ ์ง€์ •ํ•œ ํŒŒ์ผ์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. ์‹คํ–‰์ด ์ข…๋ฃŒ๋˜๋ฉด ์ €์žฅ๋œ ํŒŒ์ผ์€ ์ž๋™์œผ๋กœ ์‚ญ์ œ๋ฉ๋‹ˆ๋‹ค.

ElasticSearch ์‹คํ–‰ ํ™˜๊ฒฝ ์„ค์ •๋ฐฉ๋ฒ• 2๊ฐ€์ง€

  • ํ™ˆ ๋””๋ ‰ํ† ๋ฆฌ์˜ config ๊ฒฝ๋กœ ์•„๋ž˜ ์žˆ๋Š” ํŒŒ์ผ๋“ค์„ ๋ณ€๊ฒฝ
    • jvm.options - Java ํž™๋ฉ”๋ชจ๋ฆฌ ๋ฐ ํ™˜๊ฒฝ๋ณ€์ˆ˜ (Elasticsearch๋Š” Java์˜ ๊ฐ€์ƒ๋จธ์‹  ์œ„์—์„œ ์‹คํ–‰์ด ๋˜๋Š”๋ฐ 7.0 ๊ธฐ์ค€์œผ๋กœ 1gb์˜ ํž™๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ๊ธฐ๋ณธ์œผ๋กœ ์„ค์ •๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.)
    • elasticsearch.yml - Elasticsearch ์˜ต์…˜ (elasticsearch ์‹คํ–‰ ํ™˜๊ฒฝ์— ๋Œ€ํ•œ ์‹ค์ œ ์„ค์ •๋“ค์€ ๋Œ€๋ถ€๋ถ„ elasticsearch.yml ํŒŒ์ผ์—์„œ ์„ค์ •)
    • log4j2.properties - ๋กœ๊ทธ ๊ด€๋ จ ์˜ต์…˜
  • ์‹œ์ž‘ ๋ช…๋ น์œผ๋กœ ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•
    • Elasticsearch ๋ฅผ ์ฒ˜์Œ ์‹คํ–‰ํ•  ๋•Œ -E ์ปค๋งจ๋“œ ๋ผ์ธ ๋ช…๋ น์„ ํ†ตํ•ด์„œ๋„ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

    elasticsearch.yml ์„ค์ •

    • cluster.name: "<ํด๋Ÿฌ์Šคํ„ฐ๋ช…>"
    • node.name: "<๋…ธ๋“œ๋ช…>"
    • node.attr.: ""
    • path.data: [ "<๊ฒฝ๋กœ>" ]
    • path.logs: "<๊ฒฝ๋กœ>"
    • bootstrap.memory_lock: true
    • network.host: <ip ์ฃผ์†Œ>
    • http.port: <ํฌํŠธ ๋ฒˆํ˜ธ>
    • transport.port: <ํฌํŠธ ๋ฒˆํ˜ธ>
    • discovery.seed_hosts: [ "<ํ˜ธ์ŠคํŠธ-1>", "<ํ˜ธ์ŠคํŠธ-2>", ... ]
    • cluster.initial_master_nodes: [ "<๋…ธ๋“œ-1>", "<๋…ธ๋“œ-2>" ]

    ์‹œ์ž‘ ๋ช…๋ น์œผ๋กœ ์„ค์ •

    ํด๋Ÿฌ์Šคํ„ฐ๋ช…์€ my-cluster ๋…ธ๋“œ๋ช…์€ node-1๋กœ ๋…ธ๋“œ๋ฅผ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‹คํ–‰.
    • $ bin/elasticsearch -E cluster.name=my-cluster -E node.name="node-1"

ํด๋Ÿฌ์Šคํ„ฐ ๊ตฌ์„ฑ

Elasticsearch์˜ ๋…ธ๋“œ๋“ค์€ ํด๋ผ์ด์–ธํŠธ์™€์˜ ํ†ต์‹ ์„ ์œ„ํ•œ http ํฌํŠธ(9200-9299), ๋…ธ๋“œ ๊ฐ„์˜ ๋ฐ์ดํ„ฐ ๊ตํ™˜์„ ์œ„ํ•œ tcp ํฌํŠธ (9300-9399) ์ด 2๊ฐœ์˜ ๋„คํŠธ์›Œํฌ ํ†ต์‹ ์„ ์—ด์–ด๋‘๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
์ผ๋ฐ˜์ ์œผ๋กœ 1๊ฐœ์˜ ๋ฌผ๋ฆฌ ์„œ๋ฒ„๋งˆ๋‹ค ํ•˜๋‚˜์˜ ๋…ธ๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ์„ ๊ถŒ์žฅํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

์—ฌ๋Ÿฌ ์„œ๋ฒ„์— ํ•˜๋‚˜์˜ ํด๋Ÿฌ์Šคํ„ฐ๋กœ ์‹คํ–‰

  • 3๊ฐœ์˜ ๋‹ค๋ฅธ ๋ฌผ๋ฆฌ ์„œ๋ฒ„์—์„œ ๊ฐ๊ฐ 1๊ฐœ ์”ฉ์˜ ๋…ธ๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด
    cluster_1
  • ์„œ๋ฒ„1 ์—์„œ ๋‘๊ฐœ์˜ ๋…ธ๋“œ๋ฅผ ์‹คํ–‰ํ•˜๊ณ , ๋˜ ๋‹ค๋ฅธ ์„œ๋ฒ„์—์„œ ํ•œ๊ฐœ์˜ ๋…ธ๋“œ๋ฅผ ์‹คํ–‰
    cluster_2

ํ•˜๋‚˜์˜ ์„œ๋ฒ„์—์„œ ์—ฌ๋Ÿฌ ํด๋Ÿฌ์Šคํ„ฐ ์‹คํ–‰

  • ํ•˜๋‚˜์˜ ๋ฌผ๋ฆฌ ์„œ๋ฒ„์—์„œ ์„œ๋กœ ๋‹ค๋ฅธ ๋‘ ๊ฐœ์˜ ํด๋Ÿฌ์Šคํ„ฐ ์‹คํ–‰
    cluster_3

์ถœ์ฒ˜: https://esbook.kimjmin.net/03-cluster/3.1-cluster-settings

๋””์Šค์ปค๋ฒ„๋ฆฌ (Discovery)

๋…ธ๋“œ๊ฐ€ ์ฒ˜์Œ ์‹คํ–‰ ๋  ๋•Œ ๊ฐ™์€ ์„œ๋ฒ„, ๋˜๋Š” discovery.seed_hosts: [ ] ์— ์„ค์ •๋œ ๋„คํŠธ์›Œํฌ ์ƒ์˜ ๋‹ค๋ฅธ ๋…ธ๋“œ๋“ค์„ ์ฐพ์•„ ํ•˜๋‚˜์˜ ํด๋Ÿฌ์Šคํ„ฐ๋กœ ๋ฐ”์ธ๋”ฉ ํ•˜๋Š” ๊ณผ์ •
์ˆœ์„œ

  1. discovery.seed_hosts ์„ค์ •์— ์žˆ๋Š” ์ฃผ์†Œ ์ˆœ์„œ๋Œ€๋กœ ๋…ธ๋“œ๊ฐ€ ์žˆ๋Š”์ง€ ์—ฌ๋ถ€๋ฅผ ํ™•์ธ
  • ๋…ธ๋“œ๊ฐ€ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ > cluster.name ํ™•์ธ
    • ์ผ์น˜ํ•˜๋Š” ๊ฒฝ์šฐ > ๊ฐ™์€ ํด๋Ÿฌ์Šคํ„ฐ๋กœ ๋ฐ”์ธ๋”ฉ > ์ข…๋ฃŒ
    • ์ผ์น˜ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ > 1๋กœ ๋Œ์•„๊ฐ€์„œ ๋‹ค์Œ ์ฃผ์†Œ ํ™•์ธ ๋ฐ˜๋ณต
  • ๋…ธ๋“œ๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ > 1๋กœ ๋Œ์•„๊ฐ€์„œ ๋‹ค์Œ ์ฃผ์†Œ ํ™•์ธ ๋ฐ˜๋ณต
  1. ์ฃผ์†Œ๊ฐ€ ๋๋‚  ๋•Œ ๊นŒ์ง€ ๋…ธ๋“œ๋ฅผ ์ฐพ์ง€ ๋ชปํ•œ ๊ฒฝ์šฐ
  • ์Šค์Šค๋กœ ์ƒˆ๋กœ์šด ํด๋Ÿฌ์Šคํ„ฐ ์‹œ์ž‘
    discovery

์ธ๋ฑ์Šค์™€ ์ƒค๋“œ - Index & Shards

  • ์ธ๋ฑ์Šค๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ์ƒค๋“œ(shard)๋ผ๋Š” ๋‹จ์œ„๋กœ ๋ถ„๋ฆฌ๋˜๊ณ  ๊ฐ ๋…ธ๋“œ์— ๋ถ„์‚ฐ๋˜์–ด ์ €์žฅ์ด ๋ฉ๋‹ˆ๋‹ค.
  • ๊ฐ™์€ ์ƒค๋“œ์™€ ๋ณต์ œ๋ณธ์€ ๋™์ผํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ด๊ณ  ์žˆ์œผ๋ฉฐ ๋ฐ˜๋“œ์‹œ ์„œ๋กœ ๋‹ค๋ฅธ ๋…ธ๋“œ์— ์ €์žฅ์ด ๋ฉ๋‹ˆ๋‹ค.
  • ์ƒค๋“œ์˜ ๊ฐœ์ˆ˜๋Š” ์ธ๋ฑ์Šค๋ฅผ ์ฒ˜์Œ ์ƒ์„ฑํ•  ๋•Œ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ํ”„๋ผ์ด๋จธ๋ฆฌ ์ƒค๋“œ ์ˆ˜๋Š” ์ธ๋ฑ์Šค๋ฅผ ์ฒ˜์Œ ์ƒ์„ฑํ•  ๋•Œ ์ง€์ •ํ•˜๋ฉฐ, ์ธ๋ฑ์Šค๋ฅผ ์žฌ์ƒ‰์ธ ํ•˜์ง€ ์•Š๋Š” ์ด์ƒ ๋ฐ”๊ฟ€ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.
  • ๋ณต์ œ๋ณธ์˜ ๊ฐœ์ˆ˜๋Š” ๋‚˜์ค‘์— ๋ณ€๊ฒฝ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

๋งˆ์Šคํ„ฐ ๋…ธ๋“œ์™€ ๋ฐ์ดํ„ฐ ๋…ธ๋“œ - Master & Data

๋งˆ์Šคํ„ฐ ๋…ธ๋“œ (Master Node)

ํ•˜๋‚˜์˜ ๋…ธ๋“œ๋Š” ์ธ๋ฑ์Šค์˜ ๋ฉ”ํƒ€ ๋ฐ์ดํ„ฐ, ์ƒค๋“œ์˜ ์œ„์น˜์™€ ๊ฐ™์€ ํด๋Ÿฌ์Šคํ„ฐ ์ƒํƒœ(Cluster Status) ์ •๋ณด๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๋งˆ์Šคํ„ฐ ๋…ธ๋“œ์˜ ์—ญํ• ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.
ํด๋Ÿฌ์Šคํ„ฐ๋งˆ๋‹ค ๋ฐ˜๋“œ์‹œ ํ•˜๋‚˜์˜ ๋งˆ์Šคํ„ฐ ๋…ธ๋“œ๊ฐ€ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.

(elasticsearch.yml)

  • ๋””ํดํŠธ ์„ค์ •์€ node.master: true๋กœ ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ( ๋ชจ๋“  ๋…ธ๋“œ๊ฐ€ ๋งˆ์Šคํ„ฐ ๋…ธ๋“œ๋กœ ์„ ์ถœ๋  ์ˆ˜ ์žˆ๋Š” ๋งˆ์Šคํ„ฐ ํ›„๋ณด ๋…ธ๋“œ )
  • ํด๋Ÿฌ์Šคํ„ฐ๊ฐ€ ์ปค์ ธ์„œ ๋…ธ๋“œ์™€ ์ƒค๋“œ๋“ค์˜ ๊ฐœ์ˆ˜๊ฐ€ ๋งŽ์•„์ง€๊ฒŒ ๋˜๋ฉด ๋ชจ๋“  ๋…ธ๋“œ๋“ค์ด ๋งˆ์Šคํ„ฐ ๋…ธ๋“œ์˜ ์ •๋ณด๋ฅผ ๊ณ„์† ๊ณต์œ ํ•˜๋Š” ๊ฒƒ์€ ๋ถ€๋‹ด์ด ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋งˆ์Šคํ„ฐ ๋…ธ๋“œ๋กœ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๋…ธ๋“œ๋“ค์€ ์„ค์ •๊ฐ’์„ node.master: false ๋กœ ํ•˜์—ฌ ๋งˆ์Šคํ„ฐ ๋…ธ๋“œ์˜ ์—ญํ• ์„ ํ•˜์ง€ ์•Š๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

๋ฐ์ดํ„ฐ ๋…ธ๋“œ (Data Node)

์‹ค์ œ๋กœ ์ƒ‰์ธ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๊ณ  ์žˆ๋Š” ๋…ธ๋“œ์ž…๋‹ˆ๋‹ค.

(elasticsearch.yml)

  • ๋งˆ์Šคํ„ฐ ํ›„๋ณด ๋…ธ๋“œ๋“ค์€ node.data: false ๋กœ ์„ค์ •ํ•˜์—ฌ ๋งˆ์Šคํ„ฐ ๋…ธ๋“œ ์—ญํ• ๋งŒ ํ•˜๊ณ  ๋ฐ์ดํ„ฐ๋Š” ์ €์žฅํ•˜์ง€ ์•Š๋„๋ก ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Split Brain ๋ฌธ์ œ

๋งˆ์Šคํ„ฐ ํ›„๋ณด ๋…ธ๋“œ๋“ค์€ 3๊ฐœ ์ด์ƒ์˜ ํ™€์ˆ˜ ๊ฐœ๋ฅผ ๋†“๋Š” ๊ฒƒ์„ ๊ถŒ์žฅํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๋งŒ์•ฝ์— ๋งˆ์Šคํ„ฐ ํ›„๋ณด ๋…ธ๋“œ๋ฅผ 2๊ฐœ ํ˜น์€ ์ง์ˆ˜๋กœ ์šด์˜ํ•˜๋Š” ๊ฒฝ์šฐ ๋„คํŠธ์›Œํฌ ์œ ์‹ค๋กœ ์ธํ•ด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ƒํ™ฉ์„ ๊ฒช์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. splitbrain
Split Brain์ด๋ž€
๋„คํŠธ์›Œํฌ ๋‹จ์ ˆ๋กœ ๋งˆ์Šคํ„ฐ ํ›„๋ณด ๋…ธ๋“œ๊ฐ€ ๋ถ„๋ฆฌ๋˜๋ฉด ๊ฐ์ž๊ฐ€ ์„œ๋กœ ๋‹ค๋ฅธ ํด๋Ÿฌ์Šคํ„ฐ๋กœ ๊ตฌ์„ฑ๋˜์–ด ๋™์ž‘ํ•˜๋‹ค๊ฐ€
๋„คํŠธ์›Œํฌ๊ฐ€ ๋ณต๊ตฌ ๋˜๊ณ  ํ•˜๋‚˜์˜ ํด๋Ÿฌ์Šคํ„ฐ๋กœ ๋‹ค์‹œ ํ•ฉ์ณ์กŒ์„ ๋•Œ ๋ฐ์ดํ„ฐ ์ •ํ•ฉ์„ฑ์— ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธฐ๊ณ  ๋ฐ์ดํ„ฐ ๋ฌด๊ฒฐ์„ฑ ์†์‹ค๋˜๋Š” ํ˜„์ƒ.

Split Brain ๋ฌธ์ œ๋ฅผ ํ”ผํ•˜๊ธฐ
๋งˆ์Šคํ„ฐ ํ›„๋ณด ๋…ธ๋“œ ๊ฐœ์ˆ˜๋Š” ํ•ญ์ƒ ํ™€์ˆ˜๋กœ ํ•˜๊ณ  ๊ฐ€๋™์„ ์œ„ํ•œ ์ตœ์†Œ ๋งˆ์Šคํ„ฐ ํ›„๋ณด ๋…ธ๋“œ ์„ค์ •์€ (์ „์ฒด ๋งˆ์Šคํ„ฐ ํ›„๋ณด ๋…ธ๋“œ)/2+1 ๋กœ ์„ค์ •

(elasticsearch.yml)
7.0๋ฒ„์ „๋ถ€ํ„ฐ๋Š” node.master: true ์ธ ๋…ธ๋“œ๊ฐ€ ์ถ”๊ฐ€๋˜๋ฉด ํด๋Ÿฌ์Šคํ„ฐ๊ฐ€ ์Šค์Šค๋กœ minimum_master_nodes ๋…ธ๋“œ ๊ฐ’์„ ๋ณ€๊ฒฝํ•˜๋„๋ก ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
์‚ฌ์šฉ์ž๋Š” ์ตœ์ดˆ ๋งˆ์Šคํ„ฐ ํ›„๋ณด๋กœ ์„ ์ถœํ•  cluster.initial_master_nodes: [ ] ๊ฐ’๋งŒ ์„ค์ •ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

์„œ๋ฒ„ ์ด์ค‘ํ™” ๊ตฌ์กฐ(Active-Standby, Active-Active) ๊ฐœ๋…

Active-Standby ๊ตฌ์กฐ

ํ•˜๋‚˜์˜ ์„œ๋ฒ„๊ฐ€ ํ™œ์„ฑ ์ƒํƒœ๋กœ ์„œ๋น„์Šค ์ค‘์ผ ๋•Œ ๋‹ค๋ฅธ ํ•˜๋‚˜๋Š” ๋Œ€๊ธฐ๋ฅผ ํ•œ๋‹ค.
ํ™œ์„ฑ ์„œ๋ฒ„์— ์žฅ์• ๊ฐ€ ๋ฐœ์ƒํ•ด ์„œ๋น„์Šค๋ฅผ ๋ชปํ•˜๊ฒŒ ๋˜๋ฉด, ๋Œ€๊ธฐ์„œ๋ฒ„๊ฐ€ ์žฅ์•  ๋ฐœ์ƒ์„ ๊ฐ์ง€ํ•˜๊ณ  ๋Œ€๊ธฐ ์„œ๋ฒ„์— ๋ชจ๋“  ์„œ๋น„์Šค๋ฅผ ์˜ฌ๋ ค์„œ ์„œ๋น„์Šค๋ฅผ ์šด์˜ํ•˜๋Š” ๊ตฌ์กฐ์ด๋‹ค.

Active-Active ๊ตฌ์กฐ

๋‹ค์ค‘ํ™” ์žฅ๋น„๊ฐ€ ๋‘๋Œ€ ๋ชจ๋‘ ํ™œ์„ฑํ™” ๋˜์–ด ๋™์ž‘ํ•˜๋Š” ๊ตฌ์„ฑ์ด๋‹ค. ๋‘๋Œ€๊ฐ€ ๋ชจ๋‘ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— Active-Standby์— ๋น„ํ•˜์—ฌ ์ฒ˜๋ฆฌ๋ฅ ์ด ๋†’์ง€๋งŒ, ๋ณดํ†ต ์„ค์ • ๋ฐ ๊ตฌ์„ฑ์ด ๋ณต์žกํ•ด์ง€๋ฉฐ ํ•œ๋Œ€๊ฐ€ ์ฃฝ์—ˆ์„ ๊ฒฝ์šฐ, ๋‘๋Œ€์˜ ์ฒ˜๋ฆฌ๋Ÿ‰์„ ํ•œ๋Œ€๋กœ ์ฒ˜๋ฆฌํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฆฌ์†Œ์Šค๊ฐ€ ๋†’์•„์ ธ ๋ฆฌ์†Œ์Šค์— ๋Œ€ํ•œ ๊ณ„ํš๋„ ํ•„์š”ํ•˜๋‹ค.

์ƒค๋“œ์™€ ์„ฑ๋Šฅ ๋ฌธ์ œ

Elasticsearch์—์„œ๋Š” ์ƒค๋“œ๋‹น ๋‹จ์ผ ์“ฐ๋ ˆ๋“œ๊ฐ€ ๊ฐ ์ฟผ๋ฆฌ๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. ์บ์‹ฑ์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์„ ๋•Œ, ์ตœ์†Œ ์ฟผ๋ฆฌ ์‘๋‹ต ์‹œ๊ฐ„์€ ๋ฐ์ดํ„ฐ, ์ฟผ๋ฆฌ ์œ ํ˜• ๋ฐ ์ƒค๋“œ ํฌ๊ธฐ์— ๋”ฐ๋ผ ๋‹ฌ๋ผ์ง‘๋‹ˆ๋‹ค.
๋งŽ์€ ๊ฐœ์ˆ˜์˜ ์ž‘์€ ์ƒค๋“œ๋ฅผ ์กฐํšŒํ•˜๋ฉด ๊ฐ ์ƒค๋“œ๋งˆ๋‹ค ์ฒ˜๋ฆฌ ์†๋„๋Š” ๋นจ๋ผ์ง€์ง€๋งŒ ๋” ๋งŽ์€ ์ž‘์—…์„ ํ์— ๋„ฃ๊ณ  ์ˆœ์„œ๋Œ€๋กœ ์ฒ˜๋ฆฌํ•ด์•ผํ•˜๋ฏ€๋กœ, ๋” ์ ์€ ๊ฐœ์ˆ˜์˜ ํฐ ์ƒค๋“œ๋ฅผ ๊ฒ€์ƒ‰ํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ๋ฐ˜๋“œ์‹œ ๋น ๋ฅด๋‹ค๊ณ  ๋ณด์žฅํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.
๋™์‹œ์— ์—ฌ๋Ÿฌ ์ฟผ๋ฆฌ๊ฐ€ ์‹คํ–‰๋  ๋•Œ, ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์ž‘์€ ์ƒค๋“œ๊ฐ€ ์˜คํžˆ๋ ค ์ฟผ๋ฆฌ ์ฒ˜๋ฆฌ๋Ÿ‰(throughput)์„ ์ค„์ผ ์ˆ˜๋„ ์žˆ๊ฒ ์ฃ .
์ƒค๋“œ์˜ ์ˆ˜๊ฐ€ ๋„ˆ๋ฌด ์ ์œผ๋ฉด ๋‹จ์ผ ์ฟผ๋ฆฌ์˜ ์‘๋‹ต ์†๋„๋Š” ๋Š๋ ค์งˆ ์ˆ˜ ์žˆ์œผ๋‚˜ ๋Œ€๋Ÿ‰์˜ ์ฟผ๋ฆฌ๊ฐ€ ์ง„์ž…๋  ๊ฒฝ์šฐ ๊ณ ๋ฅธ ์„ฑ๋Šฅ์„ ๋ณด์—ฌ์ค„ ์ˆ˜ ์žˆ๊ณ , ์ƒค๋“œ์˜ ์ˆ˜๊ฐ€ ๋„ˆ๋ฌด ๋งŽ์œผ๋ฉด ๋‹จ์ผ ์ฟผ๋ฆฌ์˜ ์‘๋‹ต ์†๋„๋Š” ๋น ๋ฅผ ์ˆ˜ ์žˆ์œผ๋‚˜ ๋Œ€๋Ÿ‰์˜ ์ฟผ๋ฆฌ๊ฐ€ ์ธ์ž…๋  ๊ฒฝ์šฐ ์ฟผ๋ฆฌ ๋ณ„ ์„ฑ๋Šฅ ์ฐจ์ด๊ฐ€ ์‹ฌํ•ด์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ถœ์ฒ˜: https://www.elastic.co/kr/blog/how-many-shards-should-i-have-in-my-elasticsearch-cluster
https://brunch.co.kr/@alden/39

ElasticStackStudy3

RESTFul API : ํ•ญ์ƒ ๋‹จ์ผ URL๋กœ ์ ‘๊ทผ์„ ํ•˜๊ณ  PUT, GET, DELETE ๊ฐ™์€ http ๋ฉ”์„œ๋“œ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค
http://<ํ˜ธ์ŠคํŠธ>:<ํฌํŠธ>/<์ธ๋ฑ์Šค>/_doc/<๋„ํ๋จผํŠธ id>

CRUD API

  • PUT (Update)
PUT my_index/_doc/1   
{   
  "name":"GyeongJoo Lee",   
  "message":"์•ˆ๋…•ํ•˜์„ธ์š” Elasticsearch"   
}  
  • GET (Read)
GET my_index/_doc/1   
  • DELETE (Delete)
DELETE my_index/_doc/1   
  • POST (Create) POST ๋ฉ”์„œ๋“œ๋Š” PUT ๋ฉ”์„œ๋“œ์™€ ์œ ์‚ฌํ•˜๊ฒŒ ๋ฐ์ดํ„ฐ ์ž…๋ ฅ์— ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
    ๋„ํ๋จผํŠธ๋ฅผ ์ž…๋ ฅํ•  ๋•Œ POST ๋ฉ”์„œ๋“œ๋กœ <์ธ๋ฑ์Šค>/_doc ๊นŒ์ง€๋งŒ ์ž…๋ ฅํ•˜๊ฒŒ ๋˜๋ฉด ์ž๋™์œผ๋กœ ์ž„์˜์˜ ๋„ํ๋จผํŠธid ๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค. ๋„ํ๋จผํŠธid์˜ ์ž๋™ ์ƒ์„ฑ์€ PUT ๋ฉ”์„œ๋“œ๋กœ๋Š” ๋™์ž‘ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
POST my_index/_doc   
{   
  "name":"GyeongJoo Lee",   
  "message":"์•ˆ๋…•ํ•˜์„ธ์š” Elasticsearch"   
}  

๋ฒŒํฌ API

  • ์—ฌ๋Ÿฌ ๋ช…๋ น์„ ๋ฐฐ์น˜๋กœ ์ˆ˜ํ–‰ํ•˜๊ธฐ ์œ„ํ•ด์„œ _bulk API์˜ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
    _bulk API๋กœ index, create, update, delete์˜ ๋™์ž‘์ด ๊ฐ€๋Šฅํ•˜๋ฉฐ delete๋ฅผ ์ œ์™ธํ•˜๊ณ ๋Š” ๋ช…๋ น๋ฌธ๊ณผ ๋ฐ์ดํ„ฐ๋ฌธ์„ ํ•œ ์ค„์”ฉ ์ˆœ์„œ๋Œ€๋กœ ์ž…ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  • ๋ฒŒํฌ ๋™์ž‘์€ ๋”ฐ๋กœ๋”ฐ๋กœ ์ˆ˜ํ–‰ํ•˜๋Š” ๊ฒƒ ๋ณด๋‹ค ์†๋„๊ฐ€ ํ›จ์”ฌ ๋น ๋ฆ…๋‹ˆ๋‹ค. ํŠนํžˆ ๋Œ€๋Ÿ‰์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ž…๋ ฅ ํ•  ๋•Œ๋Š” ๋ฐ˜๋“œ์‹œ _bulk API๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ๋ถˆํ•„์š”ํ•œ ์˜ค๋ฒ„ํ—ค๋“œ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ ๋ช…๋ น์œผ๋กœ bulk.json ํŒŒ์ผ์— ์žˆ๋Š” ๋‚ด์šฉ๋“ค์„ _bulk ๋ช…๋ น์œผ๋กœ ์‹คํ–‰ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ํŒŒ์ผ ์ด๋ฆ„ ์•ž์—๋Š” @๋ฌธ์ž๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

$ curl -XPOST "http://localhost:9200/_bulk" -H 'Content-Type: application/json' --data-binary @bulk.json

๊ฒ€์ƒ‰ API

Elasticsearch์˜ ์ง„๊ฐ€๋Š” ์ฟผ๋ฆฌ๋ฅผ ํ†ตํ•œ ๊ฒ€์ƒ‰ ๊ธฐ๋Šฅ์— ์žˆ์Šต๋‹ˆ๋‹ค.
๊ฒ€์ƒ‰์€ ์ธ๋ฑ์Šค ๋‹จ์œ„๋กœ ์ด๋ฃจ์–ด์ง‘๋‹ˆ๋‹ค.

URI ๊ฒ€์ƒ‰

GET <์ธ๋ฑ์Šค๋ช…>/_search ํ˜•์‹์œผ๋กœ ์‚ฌ์šฉํ•˜๋ฉฐ ์ฟผ๋ฆฌ๋ฅผ ์ž…๋ ฅํ•˜์ง€ ์•Š์œผ๋ฉด ์ „์ฒด ๋„ํ๋จผํŠธ๋ฅผ ์ฐพ๋Š” match_all ๊ฒ€์ƒ‰์„ ํ•ฉ๋‹ˆ๋‹ค.

  • URI ๊ฒ€์ƒ‰์œผ๋กœ ๊ฒ€์ƒ‰์–ด "value" ๊ฒ€์ƒ‰
GET test/_search?q=value   
  • URI ๊ฒ€์ƒ‰์œผ๋กœ ๊ฒ€์ƒ‰์–ด "value AND three" ๊ฒ€์ƒ‰ (AND, OR, NOT)
GET test/_search?q=value AND three   
  • URI ๊ฒ€์ƒ‰์œผ๋กœ "field" ํ•„๋“œ์—์„œ ๊ฒ€์ƒ‰์–ด "value" ๊ฒ€์ƒ‰ (๊ฒ€์ƒ‰์–ด value ์„ field ํ•„๋“œ์—์„œ ์ฐพ๊ณ  ์‹ถ์œผ๋ฉด)
GET test/_search?q=field:value   

๋ฐ์ดํ„ฐ ๋ณธ๋ฌธ (Data Body) ๊ฒ€์ƒ‰

๋ฐ์ดํ„ฐ ๋ณธ๋ฌธ(data body) ๊ฒ€์ƒ‰์€ ๊ฒ€์ƒ‰ ์ฟผ๋ฆฌ๋ฅผ ๋ฐ์ดํ„ฐ ๋ณธ๋ฌธ์œผ๋กœ ์ž…๋ ฅํ•˜๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค.
Elasticsearch์˜ QueryDSL์„ ์‚ฌ์šฉํ•˜๋ฉฐ ์ฟผ๋ฆฌ ๋˜ํ•œ Json ํ˜•์‹์œผ๋กœ ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

match ์ฟผ๋ฆฌ ์ฟผ๋ฆฌ ์ž…๋ ฅ์€ ํ•ญ์ƒ query ์ง€์ •์ž๋กœ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ ๋‹ค์Œ ๋ ˆ๋ฒจ์—์„œ ์ฟผ๋ฆฌ์˜ ์ข…๋ฅ˜๋ฅผ ์ง€์ •ํ•˜๋Š”๋ฐ ์œ„์—์„œ๋Š” match ์ฟผ๋ฆฌ๋ฅผ ์ง€์ •ํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ ๋‹ค์Œ์€ ์‚ฌ์šฉํ•  ์ฟผ๋ฆฌ ๋ณ„๋กœ ๋ฌธ๋ฒ•์ด ์ƒ์ดํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ match ์ฟผ๋ฆฌ๋Š” <ํ•„๋“œ๋ช…>:<๊ฒ€์ƒ‰์–ด> ๋ฐฉ์‹์œผ๋กœ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค. ๋ฐ์ดํ„ฐ ๋ณธ๋ฌธ ๊ฒ€์ƒ‰์œผ๋กœ "field" ํ•„๋“œ์—์„œ ๊ฒ€์ƒ‰์–ด "value" ๊ฒ€์ƒ‰

GET test/_search   
{   
  "query": {   
    "match": {   
      "field": "value"   
    }   
  }   
}   

๋ฉ€ํ‹ฐํ…Œ๋„Œ์‹œ (Multitenancy) ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์ธ๋ฑ์Šค๋ฅผ ํ•œ๊บผ๋ฒˆ์— ๋ฌถ์–ด์„œ ๊ฒ€์ƒ‰ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฉ€ํ‹ฐํ…Œ๋„Œ์‹œ๋ฅผ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

  • ์‰ผํ‘œ๋กœ ๋‚˜์—ดํ•ด์„œ ์—ฌ๋Ÿฌ ์ธ๋ฑ์Šค ๊ฒ€์ƒ‰
GET logs-2018-01,2018-02,2018-03/_search   
  • ์™€์ผ๋“œ์นด๋“œ * ๋ฅผ ์ด์šฉํ•ด์„œ ์—ฌ๋Ÿฌ ์ธ๋ฑ์Šค ๊ฒ€์ƒ‰
GET logs-2018-*/_search   

Query DSL (Domain Specific Language)

Elasticsearch ๋Š” ๊ฒ€์ƒ‰์„ ์œ„ํ•œ ์ฟผ๋ฆฌ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
์ด๋Ÿฐ ๋ฐ์ดํ„ฐ ์‹œ์Šคํ…œ์—์„œ ์ œ๊ณตํ•˜๋Š” ์ฟผ๋ฆฌ ๊ธฐ๋Šฅ์„ Query DSL (Domain Specific Language) ์ด๋ผ๊ณ  ์ด์•ผ๊ธฐ ํ•˜๋ฉฐ Elasticsearch ์˜ Query DSL ์€ ๋ชจ๋‘ json ํ˜•์‹์œผ๋กœ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

- match all(๋ณ„๋‹ค๋ฅธ ์กฐ๊ฑด ์—†์ด ํ•ด๋‹น ์ธ๋ฑ์Šค์˜ ๋ชจ๋“  ๋„ํ๋จผํŠธ๋ฅผ ๊ฒ€์ƒ‰ํ•˜๋Š” ์ฟผ๋ฆฌ)

GET my_index/_search   

์™€ ์•„๋ž˜๋Š” ๋™์ผ

GET my_index/_search   
{   
  "query":{   
    "match_all":{ }   
   }   
}   

- match(ํ’€ ํ…์ŠคํŠธ ๊ฒ€์ƒ‰์— ์‚ฌ์šฉ๋˜๋Š” ๊ฐ€์žฅ ์ผ๋ฐ˜์ ์ธ ์ฟผ๋ฆฌ)

#match ์ฟผ๋ฆฌ๋กœ message ํ•„๋“œ์—์„œ dog ๊ฒ€์ƒ‰

GET my_index/_search
{   
  "query": {   
    "match": {   
      "message": "dog"   
    }   
  }   
}   

dog๊ฐ€ ํฌํ•จ๋œ ๋„ํ๋จผํŠธ๋“ค์ด ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋กœ ๋‚˜ํƒ€๋‚ฉ๋‹ˆ๋‹ค.
#match ์ฟผ๋ฆฌ๋กœ message ํ•„๋“œ์—์„œ quick dog ๊ฒ€์ƒ‰
match ๊ฒ€์ƒ‰์— ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๊ฒ€์ƒ‰์–ด๋ฅผ ์ง‘์–ด๋„ฃ๊ฒŒ ๋˜๋ฉด ๋””ํดํŠธ๋กœ OR ์กฐ๊ฑด์œผ๋กœ ๊ฒ€์ƒ‰์ด ๋˜์–ด ์ž…๋ ฅ๋œ ๊ฒ€์ƒ‰์–ด ๋ณ„๋กœ ํ•˜๋‚˜๋ผ๋„ ํฌํ•จ๋œ ๋ชจ๋“  ๋ฌธ์„œ๋ฅผ ๋ชจ๋‘ ๊ฒ€์ƒ‰ํ•ฉ๋‹ˆ๋‹ค.

GET my_index/_search
{
  "query": {
    "match": {
      "message": "quick dog"
    }
  }
}

quick๊ณผ dog์ค‘ ์–ด๋–ค ๋‹จ์–ด๋ผ๋„ ํฌํ•จํ•œ ๋„ํ๋จผํŠธ๋“ค์ด ๊ฒ€์ƒ‰๋ฉ๋‹ˆ๋‹ค.

#๊ฒ€์ƒ‰์–ด๊ฐ€ ์—ฌ๋Ÿฟ์ผ ๋•Œ ๊ฒ€์ƒ‰ ์กฐ๊ฑด์„ OR ๊ฐ€ ์•„๋‹Œ AND ๋กœ ๋ฐ”๊พธ๋ ค๋ฉด operator ์˜ต์…˜์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
quick dog ๋ฅผ AND ์กฐ๊ฑด์œผ๋กœ ๊ฒ€์ƒ‰ํ•˜๋ ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

GET my_index/_search
{
  "query": {
    "match": {
      "message": {
        "query": "quick dog",
        "operator": "and"
      }
    }
  }
}

- match_phrase

"quick dog" ๋ผ๋Š” ๊ตฌ๋ฌธ์„ ๊ณต๋ฐฑ์„ ํฌํ•จํ•ด ์ •ํ™•ํžˆ ์ผ์น˜ํ•˜๋Š” ๋‚ด์šฉ์„ ๊ฒ€์ƒ‰ํ•˜๋ ค๋ฉด match_phrase ์ฟผ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
#match_phrase ์ฟผ๋ฆฌ๋กœ "lazy dog" ๊ตฌ๋ฌธ ๊ฒ€์ƒ‰

GET my_index/_search
{
  "query": {
    "match_phrase": {
      "message": "lazy dog"
    }
  }
}

#slop ์ด๋ผ๋Š” ์˜ต์…˜์„ ์ด์šฉํ•˜์—ฌ slop์— ์ง€์ •๋œ ๊ฐ’ ๋งŒํผ ๋‹จ์–ด ์‚ฌ์ด์— ๋‹ค๋ฅธ ๊ฒ€์ƒ‰์–ด๊ฐ€ ๋ผ์–ด๋“œ๋Š” ๊ฒƒ์„ ํ—ˆ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
match_phrase ์ฟผ๋ฆฌ์— slop:1 ๋กœ "lazy dog" ๊ตฌ๋ฌธ ๊ฒ€์ƒ‰

GET my_index/_search
{
  "query": {
    "match_phrase": {
      "message": {
        "query": "lazy dog",
        "slop": 1
      }
    }
  }
}

slop์˜ ํฌ๊ธฐ๋ฅผ 1๋กœ ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— lazy์™€dog ์‚ฌ์ด์— jumping์ด ์žˆ๋Š” "Lazy jumping dog" ๊ฐ’๋„ ๊ฒ€์ƒ‰์ด ๋ฉ๋‹ˆ๋‹ค.

- query_string

URL๊ฒ€์ƒ‰์— ์‚ฌ์šฉํ•˜๋Š” ๋ฃจ์”ฌ์˜ ๊ฒ€์ƒ‰ ๋ฌธ๋ฒ•์„ ๋ณธ๋ฌธ ๊ฒ€์ƒ‰์— ์ด์šฉํ•˜๊ณ  ์‹ถ์„ ๋•Œ query_string ์ฟผ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

#message ํ•„๋“œ์—์„œ lazy์™€ jumping์„ ๋ชจ๋‘ ํฌํ•จํ•˜๊ฑฐ๋‚˜ ๋˜๋Š” "quick dog" ๊ตฌ๋ฌธ์„ ํฌํ•จํ•˜๋Š” ๋„ํ๋จผํŠธ๋ฅผ ๊ฒ€์ƒ‰ํ•˜๋Š” ์ฟผ๋ฆฌ์ž…๋‹ˆ๋‹ค.
match_phrase ์ฒ˜๋Ÿผ ๊ตฌ๋ฌธ ๊ฒ€์ƒ‰์„ ํ•  ๋•Œ๋Š” ๊ฒ€์ƒ‰ํ•  ๊ตฌ๋ฌธ์„ ์Œ๋”ฐ์˜ดํ‘œ " ์•ˆ์— ๋„ฃ์Šต๋‹ˆ๋‹ค.

GET my_index/_search
{
  "query": {
    "query_string": {
      "default_field": "message",
      "query": "(jumping AND lazy) OR \"quick dog\""
    }
  }
}

"Lazy jumping dog" ๋„ํ๋จผํŠธ์™€ "quick dog" ๊ฐ’์„ ํฌํ•จํ•˜๋Š” ๋„ํ๋จผํŠธ ๋‘๊ฐœ๊ฐ€ ๊ฒฐ๊ณผ๋กœ ๋ฆฌํ„ด๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Bool ๋ณตํ•ฉ ์ฟผ๋ฆฌ

  • must : ์ฟผ๋ฆฌ๊ฐ€ ์ฐธ์ธ ๋„ํ๋จผํŠธ๋“ค์„ ๊ฒ€์ƒ‰ํ•ฉ๋‹ˆ๋‹ค.
  • must_not : ์ฟผ๋ฆฌ๊ฐ€ ๊ฑฐ์ง“์ธ ๋„ํ๋จผํŠธ๋“ค์„ ๊ฒ€์ƒ‰ํ•ฉ๋‹ˆ๋‹ค.
  • should : ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ ์ค‘ ์ด ์ฟผ๋ฆฌ์— ํ•ด๋‹นํ•˜๋Š” ๋„ํ๋จผํŠธ์˜ ์ ์ˆ˜๋ฅผ ๋†’์ž…๋‹ˆ๋‹ค.
  • filter : ์ฟผ๋ฆฌ๊ฐ€ ์ฐธ์ธ ๋„ํ๋จผํŠธ๋ฅผ ๊ฒ€์ƒ‰ํ•˜์ง€๋งŒ ์Šค์ฝ”์–ด๋ฅผ ๊ณ„์‚ฐํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. must ๋ณด๋‹ค ๊ฒ€์ƒ‰ ์†๋„๊ฐ€ ๋น ๋ฅด๊ณ  ์บ์‹ฑ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

์‚ฌ์šฉ๋ฌธ๋ฒ•

GET <์ธ๋ฑ์Šค๋ช…>/_search
{
  "query": {
    "bool": {
      "must": [
        { <์ฟผ๋ฆฌ> }, โ€ฆ
      ],
      "must_not": [
        { <์ฟผ๋ฆฌ> }, โ€ฆ
      ],
      "should": [
        { <์ฟผ๋ฆฌ> }, โ€ฆ
      ],
      "filter": [
        { <์ฟผ๋ฆฌ> }, โ€ฆ
      ]
    }
  }
}

์ •ํ™•๋„

Elasticsearch ์™€ ๊ฐ™์€ ํ’€ ํ…์ŠคํŠธ ๊ฒ€์ƒ‰์—”์ง„์€ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๊ฐ€ ์ž…๋ ฅ๋œ ๊ฒ€์ƒ‰ ์กฐ๊ฑด๊ณผ ์–ผ๋งˆ๋‚˜ ์ •ํ™•ํ•˜๊ฒŒ ์ผ์น˜ํ•˜๋Š” ์ง€๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๊ฐ€์ง€๊ณ  ์žˆ์–ด
์ด ์ •ํ™•๋„๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์‚ฌ์šฉ์ž๊ฐ€ ๊ฐ€์žฅ ์›ํ•˜๋Š” ๊ฒฐ๊ณผ๋ฅผ ๋จผ์ € ๋ณด์—ฌ์ค„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ์ •ํ™•ํ•œ ์ •๋„๋ฅผ relevancy ๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

Score

  • _score ํ•ญ๋ชฉ์— ์Šค์ฝ”์–ด ์ ์ˆ˜๊ฐ€ ํ‘œ์‹œ๋˜๊ณ  ์ด ์ ์ˆ˜๊ฐ€ ๋†’์€ ๊ฒฐ๊ณผ๋ถ€ํ„ฐ ๋‚˜ํƒ€๋‚ฉ๋‹ˆ๋‹ค.
  • max_score์—๋Š” ์ „์ฒด ๊ฒฐ๊ณผ ์ค‘์—์„œ ๊ฐ€์žฅ ๋†’์€ ์ ์ˆ˜๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.

TF (Term Frequency)

๋„ํ๋จผํŠธ ๋‚ด์— ๊ฒ€์ƒ‰๋œ ํ…€(term)์„ ๋งŽ์ด ํฌํ•จํ• ์ˆ˜๋ก ์ ์ˆ˜๊ฐ€ ๋†’์•„์ง€๋Š” ๊ฒƒ

IDF (Inverse Document Frequency)

์ „์ฒด ์ธ๋ฑ์Šค์— ๊ฒ€์ƒ‰ํ•œ ํ…€์„ ํฌํ•จํ•˜๊ณ  ์žˆ๋Š” ๋„ํ๋จผํŠธ ๊ฐœ์ˆ˜๊ฐ€ ๋งŽ์„์ˆ˜๋ก ๊ทธ ํ…€์˜ ์ž์‹ ์˜ ์ ์ˆ˜๊ฐ€ ๊ฐ์†Œํ•˜๋Š” ๊ฒƒ

Field Length

๋„ํ๋จผํŠธ์—์„œ ํ•„๋“œ ๊ธธ์ด๊ฐ€ ํฐ ํ•„๋“œ ๋ณด๋‹ค๋Š” ์งง์€ ํ•„๋“œ์— ์žˆ๋Š” ํ…€์˜ ๋น„์ค‘์ด ํด ๊ฒƒ์ž…๋‹ˆ๋‹ค.

Bool : Should

๊ฒ€์ƒ‰์–ด ์ค‘ ํŠน์ • ๊ฒ€์ƒ‰์–ด๊ฐ€ ํฌํ•จ๋œ ๊ฒฐ๊ณผ์— ๊ฐ€์ค‘์น˜๋ฅผ ์ค˜์„œ ์ƒ์œ„๋กœ ์˜ฌ๋ฆฌ๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ ์‚ฌ์šฉ

์ •ํ™•๊ฐ’ ์ฟผ๋ฆฌ (Exact Value Query)

๊ฒ€์ƒ‰ ์กฐ๊ฑด์˜ ์ฐธ / ๊ฑฐ์ง“ ์—ฌ๋ถ€๋งŒ ํŒ๋ณ„ํ•ด์„œ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

  • bool : filter filter๋Š” ๊ฒ€์ƒ‰์— ์กฐ๊ฑด์€ ์ถ”๊ฐ€ํ•˜์ง€๋งŒ ์Šค์ฝ”์–ด์—๋Š” ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š๋„๋ก ์ œ์–ดํ•  ๋•Œ ์‚ฌ์šฉ.
  • keyword ๋ฌธ์ž์—ด๊ณผ ๊ณต๋ฐฑ, ๋Œ€์†Œ๋ฌธ์ž๊นŒ์ง€ ์ •ํ™•ํžˆ ์ผ์น˜ํ•˜๋Š” ๋ฐ์ดํ„ฐ๋งŒ์„ ๊ฒฐ๊ณผ๋กœ ๋ฆฌํ„ดํ•ฉ๋‹ˆ๋‹ค.
    ์Šค์ฝ”์–ด๋ฅผ ๊ณ„์‚ฐํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— keyword ๊ฐ’์„ ๊ฒ€์ƒ‰ ํ•  ๋•Œ๋Š” filter ๊ตฌ๋ฌธ ์•ˆ์— ๋„ฃ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

๋ฒ”์œ„ ์ฟผ๋ฆฌ (Range Query)

์ˆซ์ž, ๋‚ ์งœ ํ˜•์‹์€ range ์ฟผ๋ฆฌ๋ฅผ ์ด์šฉํ•ด์„œ ๊ฒ€์ƒ‰์„ ํ•ฉ๋‹ˆ๋‹ค.
'range : { <ํ•„๋“œ๋ช…>: { <ํŒŒ๋ผ๋ฉ”ํ„ฐ>:<๊ฐ’> } }'
#price ๊ฐ’์ด 700 ์ด์ƒ 900 ๋ฏธ๋งŒ์ธ ๋ฐ์ดํ„ฐ ๊ฒ€์ƒ‰

GET phones/_search
{
 "query": {
   "range": {
     "price": {
       "gte": 700,
       "lt": 900
     }
   }
 }
}

#date ๊ฐ’์ด 2016-01-01 ~ 2018-01-01 ์‚ฌ์ด์˜ ๋ฐ์ดํ„ฐ ๊ฒ€์ƒ‰

GET phones/_search
{
  "query": {
    "range": {
      "date": {
        "gt": "31/12/2015",
        "lt": "2018",
        "format": "dd/MM/yyyy||yyyy"
      }
    }
  }
}

๋ฐ์ดํ„ฐ ์ƒ‰์ธ๊ณผ ํ…์ŠคํŠธ ๋ถ„์„

_analyze API

๋ถ„์„๋œ ๋ฌธ์žฅ์„ _analyze API๋ฅผ ์ด์šฉํ•ด์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
ํ† ํฌ๋‚˜์ด์ €๋Š” tokenizer, ํ† ํฐ ํ•„ํ„ฐ๋Š” filter ํ•ญ๋ชฉ์˜ ๊ฐ’์œผ๋กœ ์ž…๋ ฅํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.
ํ† ํฌ๋‚˜์ด์ €๋Š” ํ•˜๋‚˜๋งŒ ์ ์šฉ๋˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฐ”๋กœ ์ž…๋ ฅํ•˜๊ณ , ํ† ํฐํ•„ํ„ฐ๋Š” ์—ฌ๋Ÿฌ๊ฐœ๋ฅผ ์ ์šฉํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— [ ] ์•ˆ์— ๋ฐฐ์—ด ํ˜•์‹์œผ๋กœ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

GET _analyze
{
  "text": "The quick brown fox jumps over the lazy dog",
  "tokenizer": "whitespace",
  "filter": [
    "lowercase",
    "stop",
    "snowball"
  ]
}
  • ์—ฌ๋Ÿฌ ํ† ํฐ ํ•„ํ„ฐ๋ฅผ ์ž…๋ ฅ ํ•  ๋•Œ๋Š” ์ˆœ์„œ๊ฐ€ ์ค‘์š”ํ•˜๋ฉฐ ๋งŒ์•ฝ์— stop ํ† ํฐ ํ•„ํ„ฐ๋ฅผ lowercase ๋ณด๋‹ค ๋จผ์ € ๋†“๊ฒŒ ๋˜๋ฉด stop ํ† ํฐํ•„ํ„ฐ ์ฒ˜๋ฆฌ์‹œ ๋Œ€๋ฌธ์ž๋กœ ์‹œ์ž‘ํ•˜๋Š” "The"๋Š” ๋ถˆ์šฉ์–ด๋กœ ๊ฐ„์ฃผ๋˜์ง€ ์•Š์•„ ๊ทธ๋ƒฅ ๋‚จ์•„์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๊ทธ ํ›„์— lowercase๊ฐ€ ์ ์šฉ๋˜์–ด ์†Œ๋ฌธ์ž "the"๊ฐ€ ์ตœ์ข… ๊ฒ€์ƒ‰ ํ…€์œผ๋กœ ์—ญ ์ƒ‰์ธ์— ๋‚จ์•„์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

  • whitespace ํ† ํฌ๋‚˜์ด์ € ๊ทธ๋ฆฌ๊ณ  lowercase, stop, snowball ํ† ํฐํ•„ํ„ฐ๋“ค์„ ์กฐํ•ฉํ•œ ๊ฒƒ์ด snowball ์• ๋„๋ผ์ด์ € ์ž…๋‹ˆ๋‹ค.
    snowball ์• ๋„๋ผ์ด์ €๋ฅผ ์‚ฌ์šฉํ•œ ๊ฒฐ๊ณผ๋Š” ์•ž์˜ whitespace ํ† ํฌ๋‚˜์ด์ € ๊ทธ๋ฆฌ๊ณ  lowercase, stop, snowball ํ† ํฐํ•„ํ„ฐ๋ฅผ ์‚ฌ์šฉํ•œ ๊ฒฐ๊ณผ์™€ ๋™์ผํ•˜๊ฒŒ ๋‚˜ํƒ€๋‚ฉ๋‹ˆ๋‹ค.

  • jumps, jumping์„ ๊ฒ€์ƒ‰ํ•˜๋ฉด ์‹ค์ œ๋กœ๋Š” jump๋กœ ๋ฐ”๊พธ์–ด ๊ฒ€์ƒ‰์ด ๋ฉ๋‹ˆ๋‹ค.

ํ‚ค๋ฐ”๋‚˜ ๊ธฐ๋ณธ ์‹ค์Šต

ํ‚ค๋ฐ”๋‚˜ ๋งค๋‹ˆ์ง€๋จผํŠธ (Kibana management)

basketball ์ธ๋ฑ์Šค ์ถ”๊ฐ€

$ curl -XPUT localhost:9200/basketball   

์‚ฌ์šฉ๋  ํ•„๋“œ๋“ค์˜ data type์„ ์ง€์ •ํ•ด์ฃผ์–ด ์‹œ๊ฐํ™”์— ๋„์›€์„ ์คŒ. (์ฃผ์˜: ContentType ๋ช…์‹œ)

$ curl -XPUT 'localhost:9200/basketball/record/_mappin' -d @basketball_mapping.json -H 'ContentType:application/json'   

bulk (json์ž๋ฃŒ ํ•œ๊บผ๋ฒˆ์— ์‚ฝ์ž…)

$ curl -XPOST 'localhost:9200/_bulk' --data-binary @bulk_basketball.json   

basketball index ์‚ญ์ œ

$ curl -XDELETE localhost:9200/basketball   

ํ‚ค๋ฐ”๋‚˜ ๋””์Šค์ปค๋ฒ„ (Kibana discover)

Discover ํŽ˜์ด์ง€: ํŠน์ • ์ธ๋ฑ์Šค์˜ ๋ฐ์ดํ„ฐ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Œ.

  • DiscoverํŽ˜์ด์ง€ discover1

  • ๋”ํ•˜๊ธฐ ๋ชจ์–‘ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜์—ฌ ํ•ด๋‹น ๋ฐ์ดํ„ฐ์™€ ์ผ์น˜ํ•˜๋Š” ๊ฒƒ๋“ค๋งŒ ์‹œ๊ฐํ™”ํ•˜๋„๋ก ํ•„ํ„ฐ๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Œ. discover2

  • ์ƒ๋‹จ์—์„œ ํ•„ํ„ฐ๋ชฉ๋ก์„ ๋ณผ ์ˆ˜ ์žˆ์Œ.
    discover3

  • ํ† ๊ธ€ ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ํŠน์ • ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•œ ์ •๋ณด๋“ค๋งŒ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Œ.
    discover4

ํ‚ค๋ฐ”๋‚˜ ๋น„์ฃผ์–ผ๋ผ์ด์ฆˆ (Kibana Visualize)

  • Line Chart
    Linechart

  • Metric
    Metric

  • Dashboard

ํ‚ค๋ฐ”๋‚˜ ์‹ค์Šต ์ฝ”๋กœ๋‚˜ ๋Œ€์‹œ๋ณด๋“œ

  • ํŠœํ† ๋ฆฌ์–ผ
    https://github.com/eskrug/elastic-demos/tree/master/covid19

  • ๋ฐ์ดํ„ฐ
    https://www.kaggle.com/kimjihoo/coronavirusdataset

  • TimeProvince.csv ๋ฐ์ดํ„ฐ์…‹์„ ํŒŒ์ผ์—…๋กœ๋“œ.

  • Mappings๋ฅผ longํƒ€์ž…์ด ๋ถˆํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ๋“ค์„ ๋น„๊ต์  ํฌ๊ธฐ๊ฐ€ ์ž‘์€ integer๋กœ ๋ฐ”๊ฟˆ.

  • ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ ํ™•์ธ
    covid-1

  • EMS(Elastic Map Service)์—์„œ ๋‹ค๋ฅด๊ฒŒ ๋ผ์žˆ๋Š” ์ง€์—ญ๋ช…๊ณผ ๋งค์นญ์ด ๋˜๊ฒŒ ํ•ด์ค˜์•ผ ํ•จ.
    Elastic Map Service : https://maps.elastic.co/#file/south_korea_provinces
    covid-2

  • south-korea-province ์ธ๋ฑ์Šค ์ƒ์„ฑ
    covid-3

  • south-korea-province ์ธ๋ฑ์Šค์— ๊ฐ’ ์ž…๋ ฅ.

    • covid19-name : TimeProvince.csv ํŒŒ์ผ์˜ province ํ•„๋“œ ๊ฐ’
    • ems-name { en, kr} : Elastic Map Service ์˜ South Korea Provinces ๋งต์— ๋งค์นญ๋˜๋Š” ๊ฐ’

covid-4

  • ์ƒ‰์ธ์‹œ ๋ฐ์ดํ„ฐ ํ™•์žฅ์„ ์œ„ํ•œ enrich pipeline ์ƒ์„ฑ ๋ฐ ํ™•์žฅ
    covid-5
  • Enrich Ingest Pipeline ์ƒ์„ฑ
    covid-6
  • Enrich ํ”„๋กœ์„ธ์„œ๋ฅผ ์ ์šฉํ•ด์„œ ์ธ๋ฑ์Šค ๊ฐ’ ์—…๋ฐ์ดํŠธ
    covid-7
    covid-8
    covid-9
  • Index Pattern ์ƒ์„ฑ
    covid-10
  • Discover์—์„œ ๋ฐ์ดํ„ฐ ํ™•์ธ
    covid-11
  • Area Chart
    covid-12
  • Line Chart
    covid-13
  • Dashboard (Maps์™€ Metric๋„ ์ถ”๊ฐ€)
    covid-14

์ปจํ…Œ์ด๋„ˆ Study

OCI์™€ CRI

OCI (OPEN CONTAINER INITIATIVE)

์ตœ๊ทผ์—๋Š” ์ปดํ“จํ„ฐ ์ „์ฒด๋ฅผ ๊ฐ€์ƒํ™”ํ•˜๋Š” ๊ฐ€์ƒ๋จธ์‹ ์— ๋น„ํ•ด ์˜ค๋ฒ„ํ—ค๋“œ๊ฐ€ ์ ์€ ์ปจํ…Œ์ด๋„ˆ ๊ธฐ์ˆ ์ด ์ฃผ๋ชฉ ๋ฐ›๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
๊ฐ€์ƒ๋จธ์‹ ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ปจํ…Œ์ด๋„ˆ๋„ ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€์— ์ €์žฅ๋˜๋Š” ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ๋‹ด๊ณ  ์žˆ๋Š” ํŒŒ์ผ๋“ค์„ ํŒจํ‚ค์ง•ํ•  ์ˆ˜ ์žˆ๋Š” ํฌ๋งท์ด ํ•„์š”ํ•œ๋ฐ,
๊ฐ€์ƒ๋จธ์‹ ์˜ OVF์— ํ•ด๋‹นํ•˜๋Š” ํ‘œ์ค€์ด OCI (Open Container Initiative) ์ž…๋‹ˆ๋‹ค.

CRI(Container Runtime Interface)

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋Š” CRI๋ฅผ ๋งŒ๋“ค์–ด ๋ช…ํ™•ํ•˜๊ฒŒ ์ •์˜๋œ ์ถ”์ƒํ™” ๊ณ„์ธต์„ ์ œ๊ณตํ•จ์œผ๋กœ์จ ๊ฐœ๋ฐœ์ž๊ฐ€ ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„ ๊ตฌ์ถ•์— ์ง‘์ค‘ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
์ดˆ๊ธฐ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋Š” ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•ด ๋„์ปค๋ฅผ ์‚ฌ์šฉํ•˜์˜€๋Š”๋ฐ ์ด๋Š” ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ํด๋Ÿฌ์Šคํ„ฐ ์›Œ์ปค ๋…ธ๋“œ์˜ ์—์ด์ „ํŠธ์ธ Kubelet ์†Œ์Šค์ฝ”๋“œ ๋‚ด๋ถ€์— ํ†ตํ•ฉ๋˜์–ด ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. ์ด์ฒ˜๋Ÿผ ํ†ตํ•ฉ๋œ ํ”„๋กœ์„ธ์Šค๋Š” Kubelet์— ๋Œ€ํ•œ ๊นŠ์€ ์ดํ•ด๋ฅผ ํ•„์š”๋กœ ํ•˜์˜€๊ณ  ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์ปค๋ฎค๋‹ˆํ‹ฐ์— ์ƒ๋‹นํ•œ ์œ ์ง€๋ณด์ˆ˜ ์˜ค๋ฒ„ํ—ค๋“œ๋ฅผ ๋ฐœ์ƒ์‹œ์ผฐ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋Š” CRI๋ฅผ ๋งŒ๋“ค์–ด ๋ช…ํ™•ํ•˜๊ฒŒ ์ •์˜๋œ ์ถ”์ƒํ™” ๊ณ„์ธต์„ ์ œ๊ณตํ•จ์œผ๋กœ์จ ๊ฐœ๋ฐœ์ž๊ฐ€ ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„ ๊ตฌ์ถ•์— ์ง‘์ค‘ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

์ €์ˆ˜์ค€๊ณผ ๊ณ ์ˆ˜์ค€ ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„

  • ์ €์ˆ˜์ค€ ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„
    namespace์™€ cgroup์„ ์„ค์ •ํ•œ ๋‹ค์Œ ํ•ด๋‹น namespace ๋ฐ cgroup ๋‚ด์—์„œ ๋ช…๋ น ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
    OCI๋ฅผ ์ค€์ˆ˜ํ•˜๋Š” ์ €์ˆ˜์ค€ ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„์—๋Š” runC๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.
    ์ €์ˆ˜์ค€ ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„์€ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹ค์ œ ์‹คํ–‰ํ•˜๋Š” ์—ญํ• ์„ ํ•˜์ง€๋งŒ ์ด๋ฏธ์ง€๋กœ๋ถ€ํ„ฐ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ํ•˜๋ ค๋ฉด ์ด๋ฏธ์ง€์™€ ๊ด€๋ จ๋œ API๊ฐ™์€ ๊ธฐ๋Šฅ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” ๊ณ ์ˆ˜์ค€ ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„์—์„œ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

  • ๊ณ ์ˆ˜์ค€ ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„
    ์›๊ฒฉ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋…ผ๋ฆฌ์ ์œผ๋กœ ์‹คํ–‰ํ•˜๊ณ  ๋ชจ๋‹ˆํ„ฐ๋ง ํ•˜๋Š”๋ฐ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐ๋ชฌ ๋ฐ API๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
    ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•ด ์ €์ˆ˜์ค€ ๋Ÿฐํƒ€์ž„ ์œ„์— ๋ฐฐ์น˜ํ•ฉ๋‹ˆ๋‹ค.
    ์ด์ฒ˜๋Ÿผ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ํ•˜๋ ค๋ฉด ์ €์ˆ˜์ค€ ๋ฐ ๊ณ ์ˆ˜์ค€ ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„์ด ํ•„์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ์— OCI ๋Ÿฐํƒ€์ž„๊ณผ ํ•จ๊ป˜ ๋„์ปค๊ฐ€ ๊ทธ ์—ญํ• ์„ ํ–ˆ์Šต๋‹ˆ๋‹ค.
    ๋„์ปค๋Š” docker-containerd๋ผ๋Š” ๊ณ ์ˆ˜์ค€ ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

CRI-O(Container Runtime Interface - Open Container Initiative)

CRI์™€ OCI์—์„œ ์œ ๋ž˜๋œ ํ”„๋กœ์ ํŠธ๋กœ ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„ ๋ฐ ์ด๋ฏธ์ง€๊ฐ€ OCI์™€ ํ˜ธํ™˜๋˜๋Š” ๊ฒƒ์— ์ค‘์ ์„ ๋‘๊ณ  ์žˆ๋‹ค.
CRI ํ‘œ์ค€ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ตœ์†Œํ•œ์˜ ๋Ÿฐํƒ€์ž„์œผ๋กœ ๊ตฌํ˜„ํ•˜๋ฉฐ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์—์„œ ๋ชจ๋“  OCI ํ˜ธํ™˜ ๋Ÿฐํƒ€์ž„ ๋ฐ ์ปจํ…Œ์ด๋„ˆ ์ด๋ฏธ์ง€๋ฅผ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
CRI-O๋Š” ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰๋ชฉ์ ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋„์ปค๊ฐ€ ์ œ๊ณตํ•˜๋Š” ์ปจํ…Œ์ด๋„ˆ ์ƒ์„ฑ ๋ฐ ์ด๋ฏธ์ง€ ๋นŒ๋“œ์™€ ๊ฐ™์€ ๊ธฐ๋Šฅ์€ ์ œ๊ณตํ•˜์ง€ ์•Š๋Š”๋‹ค.

์ปจํ…Œ์ด๋„ˆ์™€ VMs์˜ ์ฐจ์ด ์•„ํ‚คํ…์ฒ˜ ์ ‘๊ทผ ๋ฐฉ์‹

VMs (Hypervisor๊ธฐ๋ฐ˜ ๊ฐ€์ƒํ™”)

VMARCH
VM์€ "hypervisor"๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฌผ๋ฆฌ์  ์‹œ์Šคํ…œ ์œ„์—์„œ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.
hypervisor ์ž์ฒด๋Š” "ํ˜ธ์ŠคํŠธ ๋จธ์‹ "์ด๋ผ๊ณ ํ•˜๋Š” ๋ฌผ๋ฆฌ์  ์ปดํ“จํ„ฐ์—์„œ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.
Hypervisor๊ธฐ๋ฐ˜ Solution์˜ ์ฃผ์š” ์žฅ์ ์€ ์—ฌ๋Ÿฌ๋ถ„์ด ์ „์ฒด ๋ฒ”์œ„ OS๋ฅผ ์šด์˜์„ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•œ๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

Container

ContainerARCH
ํ•˜๋“œ์›จ์–ด ๊ฐ€์ƒํ™”๋ฅผ ์ œ๊ณตํ•˜๋Š” VM๊ณผ ๋‹ฌ๋ฆฌ ์ปจํ…Œ์ด๋„ˆ๋Š” "์‚ฌ์šฉ์ž ๊ณต๊ฐ„"์„ ์ถ”์ƒํ™”ํ•˜์—ฌ ์šด์˜ ์ฒด์ œ ์ˆ˜์ค€์˜ ๊ฐ€์ƒํ™”๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
"The one big difference between containers and VMs is that containers share the host systemโ€™s kernel with other containers."
์ปจํ…Œ์ด๋„ˆ์™€ VM์˜ ํฐ ์ฐจ์ด์ ์€ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ํ˜ธ์ŠคํŠธ ์‹œ์Šคํ…œ์˜ ์ปค๋„์„ ๋‹ค๋ฅธ ์ปจํ…Œ์ด๋„ˆ์™€ ๊ณต์œ ํ•œ๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

VMs์˜ ๊ฒฝ์šฐ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ๋งŒํผ ๊ฒฝ๋Ÿ‰ํ™”ํ•  ์ˆ˜๋Š” ์—†์Šต๋‹ˆ๋‹ค.
๋ฆฌ์†Œ์Šค์™€ ๊ธฐ๋Šฅ์ด ์ œํ•œ๋˜์–ด ์žˆ์„ ๋•Œ๋Š” ์ง‘์ค‘์ ์œผ๋กœ ๋ฐฐํฌํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒฝ๋Ÿ‰ํ™”๋œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
Linux ์ปจํ…Œ์ด๋„ˆ๋Š” ์šด์˜ ์ฒด์ œ์—์„œ ๊ธฐ๋ณธ์œผ๋กœ ์‹คํ–‰๋˜๊ณ  ๋ชจ๋“  ์ปจํ…Œ์ด๋„ˆ ์ „์ฒด์—์„œ ์šด์˜ ์ฒด์ œ๋ฅผ ๊ณต์œ ํ•˜๋ฏ€๋กœ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜๊ณผ ์„œ๋น„์Šค๋ฅผ ๊ฐ€๋ณ๊ฒŒ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ ๋น ๋ฅธ ์†๋„๋กœ ๋™์‹œ์— ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

LXC(Linux ์ปจํ…Œ์ด๋„ˆ) ํ”„๋กœ์ ํŠธ

ํˆด, ํ…œํ”Œ๋ฆฟ, ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ, ์–ธ์–ด ๋ฐ”์ธ๋”ฉ ์„ธํŠธ๋ฅผ ์ œ๊ณตํ•˜๋Š” ์˜คํ”ˆ์†Œ์Šค ์ปจํ…Œ์ด๋„ˆ ํ”Œ๋žซํผ์ž…๋‹ˆ๋‹ค.
LXC์—๋Š” ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹œ์ž‘ํ•  ๋•Œ ์‚ฌ์šฉ์ž ํ™˜๊ฒฝ์„ ๊ฐœ์„ ํ•˜๋Š” ๋‹จ์ˆœํ•œ ์ปค๋งจ๋“œ๋ผ์ธ ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.
LXC๋Š” ๋Œ€๋ถ€๋ถ„์˜ Linux ๊ธฐ๋ฐ˜ ์‹œ์Šคํ…œ์— ์„ค์น˜ํ•  ์ˆ˜ ์žˆ๋Š” ์šด์˜ ์ฒด์ œ ์ˆ˜์ค€์˜ ๊ฐ€์ƒํ™” ํ™˜๊ฒฝ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
์‚ฌ์šฉ ์ค‘์ธ Linux ๋ฐฐํฌ์—์„œ ํŒจํ‚ค์ง€ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋ฅผ ํ†ตํ•ด ์ œ๊ณตํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

๋„์ปค ์‹ค์Šต

๊ธฐ๋ณธ์ ์ธ ๋ช…๋ น์–ด

  • ์šฐ๋ถ„ํˆฌ ์ตœ์‹ ๋ฒ„์ „ ์ด๋ฏธ์ง€ ๋‹ค์šด
$ docker pull ubuntu:latest
  • ๊ฐ„๋‹จํ•˜๊ฒŒ ๋„์ปค ์ด๋ฏธ์ง€ ๋ชฉ๋ก์„ ํ™•์ธ
$ docker images
  • ๋„์ปค ์ด๋ฏธ์ง€๋ฅผ ์‚ญ์ œ
$ docker rmi [OPTIONS] IMAGE [IMAGE...]
  • ์‹คํ–‰์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ ๋ชฉ๋ก์„ ํ™•์ธ (-a : ์ค‘์ง€๋œ ์ปจํ…Œ์ด๋„ˆ๋„ ํ™•์ธ)
$ docker ps
  • ์šฐ๋ถ„ํˆฌ ์ด๋ฏธ์ง€ ๋„์ปค ์‹คํ–‰
    ํ‚ค๋ณด๋“œ ์ž…๋ ฅ์„ ์œ„ํ•ด -it(== โ€i โ€t)์˜ต์…˜์„ ์ค๋‹ˆ๋‹ค.
    --rm์˜ต์…˜์ด ์—†๋‹ค๋ฉด ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์ข…๋ฃŒ๋˜๋”๋ผ๋„ ์‚ญ์ œ๋˜์ง€ ์•Š๊ณ  ๋‚จ์•„์žˆ์Šต๋‹ˆ๋‹ค.
$ docker run --rm -it ubuntu:latest bash
  • ์‹คํ–‰์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ค‘์ง€
$ docker stop [OPTIONS] CONTAINER [CONTAINER...]
  • ์ข…๋ฃŒ๋œ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์™„์ „ํžˆ ์ œ๊ฑฐ
$ docker rm [OPTIONS] CONTAINER [CONTAINER...]
  • ๋ชจ๋“  ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ œ๊ฑฐ
$ docker rm $(docker ps -qa)
  • ์ด๋ฏธ์ง€ ์ œ๊ฑฐ
docker rmi <์ €์žฅ์†Œ ์ด๋ฆ„>/<์ด๋ฏธ์ง€ ์ด๋ฆ„, ID>:<ํƒœ๊ทธ>
  • ์ปจํ…Œ์ด๋„ˆ ๋กœ๊ทธ ํ™•์ธ (-f : ์‹ค์‹œ๊ฐ„์œผ๋กœ ๋กœ๊ทธ ํ™•์ธ)
$ docker logs
  • Busybox(๋งค์šฐ ์ž‘์€ ์ด๋ฏธ์ง€)
$ docker run ---rm it busybox:latest sh
  • ๋„์ปค ์ปจํ…Œ์ด๋„ˆ๋ผ๋ฆฌ ํ†ต์‹ ์„ ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ€์ƒ ๋„คํŠธ์›Œํฌ๋ฅผ ์ƒ์„ฑ
$ docker network create [OPTIONS] NETWORK
  • example > app-network๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ wordpress์™€ mysql์ด ํ†ต์‹ ํ•  ๋„คํŠธ์›Œํฌ ์ƒ์„ฑ
$ docker network create app-network
  • ๊ธฐ์กด์— ์ƒ์„ฑ๋œ ์ปจํ…Œ์ด๋„ˆ์— ๋„คํŠธ์›Œํฌ๋ฅผ ์ถ”๊ฐ€
$ docker network connect [OPTIONS] NETWORK CONTAINER
  • example > ๋งŒ๋“ค์–ด ๋†“์€ mysql ์— ๋„คํŠธ์›Œํฌ๋ฅผ ์ถ”๊ฐ€
$ docker network connect app-network mysql
  • example > ์›Œ๋“œํ”„๋ ˆ์Šค๋ฅผ appโ€network ์— ์†ํ•˜๊ฒŒ ์ƒ์„ฑํ•˜๊ณ  IP ๊ฐ€ ์•„๋‹Œ mysql ์ปจํ…Œ์ด๋„ˆ ip๋กœ ๋ฐ”๋กœ ์ ‘๊ทผ
    ๊ฐ™์€ ๋„คํŠธ์›Œํฌ์— ์†ํ•ด ์žˆ์œผ๋ฉด ์ƒ๋Œ€ ์ปจํ…Œ์ด๋„ˆ์˜ ์ด๋ฆ„์„ DNS ๋กœ ์กฐํšŒํ•˜์—ฌ ๋ฐ”๋กœ ์ ‘๊ทผ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    ํ•˜๋‚˜์˜ ์ปจํ…Œ์ด๋„ˆ๋Š” ์—ฌ๋Ÿฌ๊ฐœ์˜ network ์— ์†ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ Docker Swarm ๊ฐ™์€ ํด๋Ÿฌ์Šคํ„ฐ์—์„œ ํŽธ๋ฆฌํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
$ docker run -d -p 8080:80 \
 --network=app-network \
 -e WORDPRESS_DB_HOST=mysql \
 -e WORDPRESS_DB_NAME=wp \
 -e WORDPRESS_DB_USER=wp \
 -e WORDPRESS_DB_PASSWORD=wp \
 wordpress
  • Mysql ๋„์ปค๋กœ ์‹คํ–‰
$ docker run -d -p 3306:3306 \
-e MYSQL_ALLOW_EMPTY_PASSWORD=true \
--name mysql \
mysql:5.7
  • Mysql์— ์ ‘์†ํ•˜์—ฌ database ๋งŒ๋“ค๊ธฐ
$ docker exec -it mysql mysql
create database wp CHARACTER SET utf8;
grant all privileges on wp.* to wp@'%' identified by 'wp';
flush privileges;
quit
  • exec ๋ช…๋ น์–ด์™€ run ๋ช…๋ น์–ด์˜ ์ฐจ์ด
    exec ๋ช…๋ น์–ด๋Š” run ๋ช…๋ น์–ด์™€ ๋‹ฌ๋ฆฌ ์‹คํ–‰์ค‘์ธ ๋„์ปค ์ปจํ…Œ์ด๋„ˆ์— ์ ‘์†ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋ฉฐ
    ์ผ๋ฐ˜์ ์œผ๋กœ ์ปจํ…Œ์ด๋„ˆ ์•ˆ์— ssh server ๋“ฑ์„ ์„ค์น˜ํ•˜์ง€ ์•Š๊ณ  exec ๋ช…๋ น์–ด๋กœ ์ ‘์†ํ•ฉ๋‹ˆ๋‹ค.

  • docker-compose ์„ค์น˜

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
  • docker-compose.yml ์ƒ์„ฑ(db์™€ wordpress์„œ๋น„์Šค๋ฅผ ํ•˜๋‚˜์˜ ํŒŒ์ผ๋กœ ๋ฌถ์Œ)
    "volumes: " -> ๋ณผ๋ฅจ ๋งˆ์šดํŠธ๋ฅผ ํ•˜์—ฌ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์‚ฌ๋ผ์ง€๋”๋ผ๋„ ๋ฐ์ดํ„ฐ๊ฐ€ ์œ ์‹ค๋˜์ง€ ์•Š๋„๋ก ํ•จ.
version: '2'

services:
   db:
     image: mysql:5.7
     volumes:
       - ./mysql:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: wordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress
   wordpress:
     image: wordpress:latest
     volumes:
       - ./wp:/var/www/html
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_PASSWORD: wordpress
  • docker compose๋ฅผ ์ด์šฉํ•˜์—ฌ ์œ„ ํŒŒ์ผ๋กœ ์ž‘์„ฑํ•œ ๊ฒƒ๊ณผ ๊ฐ™์ด mysql, wordpress ์‹คํ–‰
$ docker-compose up -d
  • docker compose๋กœ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ข…๋ฃŒํ•˜๊ณ  ์‚ญ์ œ
$ docker-compose down

์ด๋ฏธ์ง€ ์ƒ์„ฑ

  • ์ปค์Šคํ…€ ์ด๋ฏธ์ง€๋ฅผ ๋งŒ๋“ค๊ธฐ๊นŒ์ง€ ์ƒํƒœ ๋ณ€ํ™”
    docker_custom_image

์‹ค์Šต : git์„ ์ถ”๊ฐ€์ ์œผ๋กœ ์„ค์น˜ํ•œ ํ™˜๊ฒฝ์„ ์ด๋ฏธ์ง€๋กœ ๋งŒ๋“ค๊ธฐ(์ปจํ…Œ์ด๋„ˆ ํ™˜๊ฒฝ์„ ์ €์žฅ)

  • ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰์‹œํ‚ค๊ณ  git์„ ์„ค์น˜
$ docker run -it ubuntu:latest --name git /bin/bash
# apt update
# apt install git
  • ์ปจํ…Œ์ด๋„ˆ ์ฐจ์ด์  ๋น„๊ต(๋ณ€๊ฒฝ์‚ฌํ•ญ ํ™•์ธ ๊ฐ€๋Šฅ)
$ docker diff CONTAINER_ID
  • ubuntu:git ์ด๋ฆ„์œผ๋กœ ์ด๋ฏธ์ง€ ์ƒ์„ฑ
$ docker commit git ubuntu:git
  • ์ด๋ฏธ์ง€ ์ƒ์„ฑ๋๋Š”์ง€ ํ™•์ธ
$ docker images | grep ubuntu

๊ฒฐ๊ณผ:

ubuntu | git | f98472c1d8aa | 6 seconds ago | 252.2 MB
..

Dockerfile์„ ์ด์šฉํ•œ ์ด๋ฏธ์ง€ ์ƒ์„ฑ ์‹ค์Šต

  • Dockerfile์ด๋ž€?
    ์ด๋ฏธ์ง€ ์ƒ์„ฑ ๊ณผ์ •์„ ๊ธฐ์ˆ ํ•œ Docker์ „์šฉ DSL
  • Dockerfile ์ƒ์„ฑ
$ vim Dockerfile

๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ž‘์„ฑ

# ์–ด๋–ค ์ด๋ฏธ์ง€๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋„์ปค ์ด๋ฏธ์ง€๋ฅผ ์‚ฌ์šฉํ• ์ง€ ๊ฒฐ์ •(๋ฒ ์ด์Šค ์ด๋ฏธ์ง€ ์ง€์ •)   
FROM ubuntu:16.04   
# RUN์€ ์‹คํ–‰ํ•  ๋ช…๋ น์–ด๋ฅผ ์˜๋ฏธ
RUN apt update
RUN apt install -y
  • ํ˜„์žฌ ๊ฒฝ๋กœ์— ์žˆ๋Š” ๋„์ปคํŒŒ์ผ์„ ์ด์šฉํ•˜์—ฌ ubuntu:git ์ด๋ฆ„์œผ๋กœ ์ด๋ฏธ์ง€ ์ƒ์„ฑ
$ docker build -t ubuntu:git2 ./
  • Dockerfile๋กœ ์ƒ์„ฑํ•œ ์ด๋ฏธ์ง€ ์‹คํ–‰ํ•ด๋ณด๊ธฐ
$ docker run --rm -it ubuntu:git2 bash

Dockerfile ๋ช…๋ น์–ด

  • FROM <์ด๋ฏธ์ง€์ด๋ฆ„>
    ๋ฒ ์ด์Šค ์ด๋ฏธ์ง€ ์ง€์ •
  • ADD <์ถ”๊ฐ€ํ•  ํŒŒ์ผ> <์ถ”๊ฐ€๋  ๊ฒฝ๋กœ>
    ํŒŒ์ผ ์ถ”๊ฐ€
ADD data.txt /temp/data.txt
  • RUN <๋ช…๋ น์–ด>
    ๋ช…๋ น์–ด ์‹คํ–‰
  • WORKDIR <๊ฒฝ๋กœ>
    ์ž‘์—… ๋””๋ ‰ํ„ฐ๋ฆฌ ๋ณ€๊ฒฝ(cd <๊ฒฝ๋กœ>์™€ ๋น„์Šทํ•œ ๋Š๋‚Œ)
  • ENV <ํ™˜๊ฒฝ๋ณ€์ˆ˜> <๊ฐ’>
    ํ™˜๊ฒฝ๋ณ€์ˆ˜ ๊ธฐ๋ณธ๊ฐ’ ์ง€์ •
  • EXPOSE <ํฌํŠธ>
    ์ปจํ…Œ์ด๋„ˆ๋กœ ์‹คํ–‰ ์‹œ ๋…ธ์ถœ์‹œํ‚ฌ ํฌํŠธ
  • CMD <๋ช…๋ น์–ด>
    ์ด๋ฏธ์ง€์˜ ๊ธฐ๋ณธ ์‹คํ–‰ ๋ช…๋ น์–ด ์ง€์ •
    <๋ช…๋ น์–ด>๊ฐ€ ๋น„์–ด์žˆ์„ ๋•Œ๋Š” bash๋ฅผ ๊ธฐ๋ณธ์œผ๋กœ ์ง€์ •

๋„์ปคํ—ˆ๋ธŒ push pull

๋„์ปคํ—ˆ๋ธŒ ์ฃผ์†Œ
https://hub.docker.com/

  • tag๋ช…๋ น์–ด๋กœ ์ด๋ฏธ์ง€์— ํƒœ๊ทธ(์ €์žฅ์†Œ ์ด๋ฆ„ : gjlee0802)
$ docker tag mydockerimage:latest gjlee0802/mydockerimage:latest
  • Dockerhub์— ๋กœ๊ทธ์ธ
$ docker login --username=gjlee0802 --email=userid@gmail.com
Password:
WARNING: login credentials saved in /Users/devsun/.docker/config.json
Login Succeeded
  • ๋„์ปคํ—ˆ๋ธŒ์— ์ด๋ฏธ์ง€ push
$ docker push gjlee0802/mydockerimage
  • ๋„์ปคํ—ˆ๋ธŒ๋กœ๋ถ€ํ„ฐ ์ด๋ฏธ์ง€ pull
$ docker pull gjlee0802/mydockerimage

Kafka

Producer์™€ Consumer

kafka_features
๊ฐ์ข… ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ด๋Š” topic์ด๋ผ๋Š” ๊ฐœ๋…์ด ์žˆ๋Š”๋ฐ, ์‰ฝ๊ฒŒ ์ƒ๊ฐํ•ด์„œ ํ(queue) ๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.
ํ์— ๋ฐ์ดํ„ฐ๋ฅผ ๋„ฃ๋Š” ์—ญํ• ์€ Producer๊ฐ€ ํ•˜๊ณ , ํ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ์—ญํ• ์€ Consumer๊ฐ€ ํ•ฉ๋‹ˆ๋‹ค.
Producer์™€ Consumer์€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๋ผ์žˆ์–ด์„œ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ๊ตฌํ˜„์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
์˜ค๊ฐ€๋Š” ๋ฐ์ดํ„ฐ ํฌ๋งท์€ ๊ฑฐ์˜ ์ œํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค.(json, tsv, avro etc... ์—ฌ๋Ÿฌ ํฌ๋งท์„ ์ง€์›)

Producer ์—ญํ• 

  • Topic์— ํ•ด๋‹นํ•˜๋Š” ๋ฉ”์‹œ์ง€๋ฅผ ์ƒ์„ฑ
  • ํŠน์ • Topic์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ publish
  • ์ฒ˜๋ฆฌ ์‹คํŒจ/์žฌ์‹œ๋„

Consumer ์—ญํ• 

  • Topic์˜ partition์œผ๋กœ๋ถ€ํ„ฐ ๋ฐ์ดํ„ฐ polling(๊ฐ€์ ธ์˜ค๊ธฐ)
  • Partition offset(ํŒŒํ‹ฐ์…˜์— ์žˆ๋Š” ๋ฐ์ดํ„ฐ์˜ ๋ฒˆํ˜ธ) ์œ„์น˜ ๊ธฐ๋ก(commit) -> ์–ด๋Š ์ง€์ ๊นŒ์ง€ ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ์—ˆ๋Š”์ง€ ํ™•์ธํ•˜์—ฌ ๊ณ ๊ฐ€์šฉ์„ฑ ๋ณด์žฅ
  • Consumer group์„ ํ†ตํ•ด ๋ณ‘๋ ฌ์ฒ˜๋ฆฌ(ํŒŒํ‹ฐ์…˜ ๊ฐœ์ˆ˜์— ๋”ฐ๋ผ ์ปจ์Šˆ๋จธ๋ฅผ ์—ฌ๋Ÿฌ๊ฐœ ๋ฐฐ์น˜) -> ์ฃผ์˜์ : Consumer ๊ฐœ์ˆ˜ <= partition๊ฐœ์ˆ˜

์ฐธ๊ณ : https://www.youtube.com/watch?v=rBVCvv9skT4&list=PL3Re5Ri5rZmkY46j6WcJXQYRlDRZSUQ1j&index=5
https://jhleed.tistory.com/179

Kafka Topic

Topic์€ ํŒŒ์ผ์‹œ์Šคํ…œ ํด๋”์™€ ์œ ์‚ฌํ•œ ๊ตฌ์กฐ๋ฅผ ๊ฐ€์ง‘๋‹ˆ๋‹ค.
Topic์˜ ์ด๋ฆ„์€ ๋ชฉ์ ์— ๋”ฐ๋ผ ์–ด๋–ค ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ด๋Š”์ง€ ๋ช…ํ™•ํ•˜๊ฒŒ ๋ช…์‹œํ•˜์—ฌ ํŽธ๋ฆฌํ•˜๊ฒŒ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํŒŒํ‹ฐ์…˜

ํ•˜๋‚˜์˜ ํ† ํ”ฝ์€ ์—ฌ๋Ÿฌ๊ฐœ์˜ ํŒŒํ‹ฐ์…˜์œผ๋กœ ๊ตฌ์„ฑ๋  ์ˆ˜ ์žˆ์œผ๋ฉฐ ์ฒซ๋ฒˆ์งธ ํŒŒํ‹ฐ์…˜ ๋ฒˆํ˜ธ๋Š” 0์ž…๋‹ˆ๋‹ค. ํ•˜๋‚˜์˜ ํŒŒํ‹ฐ์…˜์€ ํ์™€ ๊ฐ™์ด ๋ฐ์ดํ„ฐ๊ฐ€ ๋์—์„œ๋ถ€ํ„ฐ ์ฐจ๊ณก์ฐจ๊ณก ์Œ“์ด๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
Kafka Consumer์€ ๋์—์„œ๋ถ€ํ„ฐ(๊ฐ€์žฅ์˜ค๋ž˜๋œ ์ˆœ์œผ๋กœ) ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
Consumer๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ๊ฐ„๋‹ค๊ณ ํ•ด์„œ ๋ฐ์ดํ„ฐ๊ฐ€ ์‚ฌ๋ผ์ง€๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ํŒŒํ‹ฐ์…˜์— ๊ทธ๋Œ€๋กœ ๋‚จ์Šต๋‹ˆ๋‹ค.(๋˜ ๋‹ค๋ฅธ Consumer๊ฐ€ ์—ฐ๊ฒฐ๋˜์–ด ๊ฐ€์ ธ๊ฐˆ ์ˆ˜ ์žˆ๋„๋ก ํ•จ.)
kafka_features

  • ํŒŒํ‹ฐ์…˜์„ ๋Š˜๋ฆฌ๋Š” ์ด์œ : Consumer ๊ฐœ์ˆ˜๋ฅผ ๋Š˜๋ ค ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ๋ฅผ ๋ถ„์‚ฐ์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ํŒŒํ‹ฐ์…˜์˜ ๋ฐ์ดํ„ฐ(record)๋ฅผ ์‚ญ์ œํ•˜๋Š” ํƒ€์ด๋ฐ: ์ตœ๋Œ€ record ๋ณด์กด ์‹œ๊ฐ„, ์ตœ๋Œ€ record ๋ณด์กด ํฌ๊ธฐ๋กœ ๊ฒฐ์ •
  • Kafka๋Š” key๋ฅผ ํŠน์ •ํ•œ ํ•ด์‹œ๋กœ ๋ณ€ํ˜•์‹œ์ผœ ํŒŒํ‹ฐ์…˜๊ณผ 1๋Œ€1 ๋งค์นญ์„ ์‹œํ‚ต๋‹ˆ๋‹ค.
    ํŒŒํ‹ฐ์…˜์—๋Š” ๋™์ผํ•œ key์˜ value๋งŒ ์Œ“์ด๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
    key๋ฅผ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ, ํ‚ค์™€ ํŒŒํ‹ฐ์…˜ ๋งค์นญ์ด ๊นจ์งˆ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ํŒŒํ‹ฐ์…˜ ๊ฐœ์ˆ˜์— ์œ ์˜ํ•˜์—ฌ ํŒŒํ‹ฐ์…˜์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

Broker, Replication, ISR

Broker

Kafka Brocker์€ Kafka๊ฐ€ ์„ค์น˜๋˜์–ด ์žˆ๋Š” ์„œ๋ฒ„ ๋‹จ์œ„๋ฅผ ๋งํ•ฉ๋‹ˆ๋‹ค.
๋ณดํ†ต 3๊ฐœ ์ด์ƒ์˜ broker ์ด์šฉ์„ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค.

Replication

์„œ๋ฒ„์— ์žฅ์• ๊ฐ€ ์ƒ๊ฒผ์„ ๋•Œ, ๋ณต๊ตฌ ํ•  ์ˆ˜ ์žˆ๋Š” ๊ณ ๊ฐ€์šฉ์„ฑ์„ ๋ณด์žฅํ•ฉ๋‹ˆ๋‹ค.(Elastic Search์—์„œ ๊ณต๋ถ€ํ•œ replica ๊ฐœ๋…๊ณผ ๋งค์šฐ ์œ ์‚ฌ)
replication = Leader partition(์›๋ณธ ํŒŒํ‹ฐ์…˜) + Follower partition(๋ณต์ œ ํŒŒํ‹ฐ์…˜)
replication์˜ ๊ฐœ์ˆ˜๋Š” ์ œํ•œ๋ฉ๋‹ˆ๋‹ค.(replication ๊ฐœ์ˆ˜ <= Kafka broker ๊ฐœ์ˆ˜)

ISR - In Sync Replica

๊ฐ๊ฐ์˜ replication group์ด ๋ฐ”๋กœ ISR์ž…๋‹ˆ๋‹ค.
ISR1

  • leader๊ฐ€ down ๋˜๋ฉด์„œ follower๊ฐ€ new leader๊ฐ€ ๋˜๋Š” ๊ณผ์ •
    ISR2
    ISR3
    • topic01์˜ ๊ฒฝ์šฐ, ISR ๋‚ด follower๋Š” ๋ˆ„๊ตฌ๋ผ๋„ leader๊ฐ€ ๋  ์ˆ˜ ์žˆ๋Š” ์กฐ๊ฑด์„ ์ถฉ์กฑํ•˜๊ธฐ ๋•Œ๋ฌธ์— follower -> new leader
      ์ด๋•Œ, ์ผ์‹œ์ ์œผ๋กœ follower๊ฐ€ leader๊ฐ€ ๋˜๋Š” ๊ณผ์ •์—์„œ read/write์˜ timeout์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๊ฒ ์ง€๋งŒ, retry๊ฐ€ ์ผ์–ด๋‚˜๋ฉด new leader์™€ read/write๊ฐ€ ๊ฐ€๋Šฅํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์žฅ์•  ์ƒํ™ฉ์€ ์•„๋‹™๋‹ˆ๋‹ค.
    • topic02์˜ ๊ฒฝ์šฐ, down ๋œ follower๋Š” leader๊ฐ€ ๋  ์ž๊ฒฉ์ด ์—†๊ธฐ ๋•Œ๋ฌธ์— ISR์—์„œ ์ œ์™ธ๊ฐ€ ๋˜๋ฉด์„œ ISR์—๋Š” leader ํ•˜๋‚˜์™€ follower ํ•˜๋‚˜๋งŒ ํฌํ•จ๋˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
      topic01๊ณผ ๋‹ฌ๋ฆฌ topic02์˜ leader๋Š” ๋ณ€ํ•˜์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์— ์•„๋ฌด๋Ÿฐ ํŠน์ด์‚ฌํ•ญ ์—†์ด read/write๊ฐ€ ๊ณ„์† ์ผ์–ด๋‚ฉ๋‹ˆ๋‹ค.

์ฐธ๊ณ : https://www.popit.kr/kafka-%EC%9A%B4%EC%98%81%EC%9E%90%EA%B0%80-%EB%A7%90%ED%95%98%EB%8A%94-topic-replication/

Lag

Producer๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ ๋„ฃ์–ด์ฃผ๋Š” ์†๋„๊ฐ€ Consumer๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ๊ฐ€๋Š” ์†๋„๋ณด๋‹ค ๋น ๋ฅธ ๊ฒฝ์šฐ์—
Producer๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ ๋„ฃ์€ ์˜คํ”„์…‹๊ณผ Consumer๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ๊ฐ„ ์˜คํ”„์…‹ ๊ฐ„์— ์ฐจ์ด๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.
์ด ๋‘ ์˜คํ”„์…‹ ๊ฐ„์˜ ์ฐจ์ด๊ฐ€ Consumer Lag ์ž…๋‹ˆ๋‹ค.
ํŒŒํ‹ฐ์…˜์ด ํ•˜๋‚˜๊ฐ€ ์•„๋‹ˆ๋ผ ์—ฌ๋Ÿฌ๊ฐœ๋ผ๋ฉด Lag๋„ ์—ฌ๋Ÿฌ๊ฐœ๊ฐ€ ์กด์žฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์—ฌ๋Ÿฌ๊ฐœ์˜ Lag์ค‘์— ๊ฐ€์žฅ ๋†’์€ ์ˆซ์ž์˜ Lag์„ records-lag-max๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.
consumer_lag

Burrow

Consumer Lag์„ ๋ชจ๋‹ˆํ„ฐ๋งํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

Burrow์˜ ํŠน์ง•

  • ๋ฉ€ํ‹ฐ ์นดํ”„์นด ํด๋Ÿฌ์Šคํ„ฐ ์ง€์›
  • Sliding window๋ฅผ ํ†ตํ•œ Consumer์˜ status(ERROR/WARING/OK) ํ™•์ธ
  • HTTP api ์ œ๊ณต(๋‹ค์–‘ํ•œ ์ถ”๊ฐ€ ์ƒํƒœ๊ณ„ ๊ตฌ์ถ• ๊ฐ€๋Šฅ)

Zookeeper

์ฃผํ‚คํผ๋ž€?

์ฃผํ‚คํผ๋Š”(Zookeeper)๋Š” ๋ถ„์‚ฐ ์ฝ”๋””๋„ค์ด์…˜ ์„œ๋น„์Šค๋ฅผ ์ œ๊ณตํ•˜๋Š” ์˜คํ”ˆ์†Œ์Šค ํ”„๋กœ์ ํŠธ์ž…๋‹ˆ๋‹ค.
์ฃผํ‚คํผ๋Š” znode๋กœ ์ด๋ฃจ์–ด์ง„ ๋ถ„์‚ฐ ๋ฐ์ดํ„ฐ ๋ชจ๋ธ์„ ์ง€์›ํ•˜๋Š” ์‹œ์Šคํ…œ์ด๋ผ๊ณ  ํ•ด๋„ ๊ณผ์–ธ์ด ์•„๋‹™๋‹ˆ๋‹ค.
์ด ๋ฐ์ดํ„ฐ ๋ชจ๋ธ์€ ๋ฆฌ๋ˆ…์Šค(linux) ํŒŒ์ผ์‹œ์Šคํ…œ๊ณผ ์œ ์‚ฌํ•œ ์‹œ์Šคํ…œ์„ ์ œ๊ณตํ•˜๊ณ  ์ด๊ฒƒ์ด ์ฃผํ‚คํผ์˜ ํ•ต์‹ฌ์ž…๋‹ˆ๋‹ค.
์ฃผํ‚คํผ์— ์ฑ„ํƒ๋œ ์•„ํ‚คํ…์ฒ˜์™€ ๊ธฐ๋ฒ•๋“ค์€ ์ด ๋ฐ์ดํ„ฐ ๋ชจ๋ธ์„ ์•ˆ์ •์ ์œผ๋กœ ์ œ๊ณตํ•˜๊ณ ์ž ํ•˜๊ธฐ ์œ„ํ•จ์ž…๋‹ˆ๋‹ค.
์ด ์‹œ์Šคํ…œ์„ ํ†ตํ•ด ์ฃผํ‚คํผ๋Š” ๊ธ€๋กœ๋ฒŒ๋ฝ, ํด๋Ÿฌ์Šคํ„ฐ ์ •๋ณด, Leader ์„ ์ถœ ๋“ฑ์„ ๊ตฌํ˜„ํ•ด์•ผํ•˜๋Š” ๊ณณ์— ํ™œ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ฃผํ‚คํผ ์‚ฌ์šฉ์šฉ๋„

์ฃผํ‚คํผ๋Š” ํด๋Ÿฌ์Šคํ„ฐ์—์„œ ๊ตฌ์„ฑ ์„œ๋ฒ„๋“ค๋ผ๋ฆฌ ๊ณต์œ ๋˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์œ ์ง€ํ•˜๊ฑฐ๋‚˜ ์–ด๋–ค ์—ฐ์‚ฐ์„ ์กฐ์œจํ•˜๊ธฐ ์œ„ํ•ด ์ฃผ๋กœ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
์ฃผํ‚คํผ๋Š” ์นดํ”„์นด์˜ ๋…ธ๋“œ ๊ด€๋ฆฌ๋ฅผ ํ•ด์ฃผ๊ณ , ํ† ํ”ฝ์˜ offset ์ •๋ณด๋“ฑ์„ ์ €์žฅํ•˜๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
ํด๋Ÿฌ์Šคํ„ฐ ๋‚ด์˜ broker์— ๋Œ€ํ•œ ๋ถ„์‚ฐ ์ฒ˜๋ฆฌ๋Š” Apache ZooKeeper๊ฐ€ ๋‹ด๋‹นํ•ฉ๋‹ˆ๋‹ค.

  • ์„ค์ • ๊ด€๋ฆฌ(Configuration management) : ํด๋Ÿฌ์Šคํ„ฐ์˜ ์„ค์ • ์ •๋ณด๋ฅผ ์ตœ์‹ ์œผ๋กœ ์œ ์ง€ํ•˜๊ธฐ ์œ„ํ•œ ์กฐ์œจ ์‹œ์Šคํ…œ์œผ๋กœ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

  • ํด๋Ÿฌ์Šคํ„ฐ ๊ด€๋ฆฌ(Cluster management) : ํด๋Ÿฌ์Šคํ„ฐ์˜ ์„œ๋ฒ„๊ฐ€ ์ถ”๊ฐ€๋˜๊ฑฐ๋‚˜ ์ œ์™ธ๋  ๋•Œ ๊ทธ ์ •๋ณด๋ฅผ ํด๋Ÿฌ์Šคํ„ฐ ์•ˆ ์„œ๋ฒ„๋“ค์ด ๊ณต์œ ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

  • ๋ฆฌ๋” ์ฑ„ํƒ(Leader selection) : ๋‹ค์ค‘ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ค‘์—์„œ ์–ด๋–ค ๋…ธ๋“œ๋ฅผ ๋ฆฌ๋”๋กœ ์„ ์ถœํ•  ์ง€๋ฅผ ์ •ํ•˜๋Š” ๋กœ์ง์„ ๋งŒ๋“œ๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ์ฃผ๋กœ ๋ณต์ œ๋œ ์—ฌ๋Ÿฌ ๋…ธ๋“œ ์ค‘ ์—ฐ์‚ฐ์ด ์ด๋ฃจ์–ด์ง€๋Š” ํ•˜๋‚˜์˜ ๋…ธ๋“œ๋ฅผ ํƒํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

  • ๋ฝ, ๋™๊ธฐํ™” ์„œ๋น„์Šค(Locking and synchronization service) : ํด๋Ÿฌ์Šคํ„ฐ์— ์“ฐ๊ธฐ ์—ฐ์‚ฐ์ด ๋นˆ๋ฒˆํ•  ๊ฒฝ์šฐ ๊ฒฝ์Ÿ์ƒํƒœ์— ๋“ค์–ด๊ฐˆ ๊ฐ€๋Šฅ์„ฑ์ด ์ปค์ง‘๋‹ˆ๋‹ค. ์ด๋Š” ๋ฐ์ดํ„ฐ ๋ถˆ์ผ์น˜๋ฅผ ๋ฐœ์ƒ์‹œํ‚ต๋‹ˆ๋‹ค. ์ด ๋•Œ, ํด๋Ÿฌ์Šคํ„ฐ ์ „์ฒด๋ฅผ ๋Œ€์ƒ์„ ๋™๊ธฐํ™”ํ•ด( ๋ฝ์„ ๊ฒ€ ) ๊ฒฝ์Ÿ์ƒํƒœ์— ๋“ค์–ด๊ฐˆ ๊ฒฝ์šฐ๋ฅผ ์‚ฌ์ „์— ๋ฐฉ์ง€ํ•ฉ๋‹ˆ๋‹ค.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages