ELK Stack

woomยท2023๋…„ 8์›” 17์ผ
0

ELK Stack

๋ชฉ๋ก ๋ณด๊ธฐ
4/4
post-thumbnail

์ถœ์ฒ˜ : ELK ์Šคํƒ์œผ๋กœ ๋ฐ์ดํ„ฐ ๋ถ„์„ - Minsuk Heo
https://github.com/minsuk-heo/BigData/tree/master


๐ŸŒผ ELK Stack

๋กœ๊ทธ ๋ถ„์„ ์‹œ์Šคํ…œ

  • ElasticSearch : ๋กœ๊ทธ๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋กœ ํ™œ์šฉ
  • Logstash : ํด๋ผ์šฐ๋“œ ๋‚ด์—์„œ ๋ฐœ์ƒ๋œ ๋กœ๊ทธ๋ฅผ ์ „๋‹ฌ๋ฐ›์•„์„œ ElasticSearch์— ์ €์žฅ
  • Kibana : ElasticSearch์— ์ €์žฅ๋œ ๋กœ๊ทธ๋ฅผ ๋ธŒ๋ผ์šฐ์ €์— ์ถœ๋ ฅ

๐Ÿ“• Filebeat

Q. Logstash๋Š” ์–ด๋–ป๊ฒŒ ํด๋ผ์šฐ๋“œ์ƒ์˜ ๋กœ๊ทธ ์ •๋ณด๋ฅผ ์ž…๋ ฅ๋ฐ›์„ ์ˆ˜ ์žˆ๋‚˜?

Filebeat : ๊ฐ๊ฐ์˜ ์„œ๋ฒ„(ex. ํด๋ผ์šฐ๋“œ์ƒ์˜ tomcat์„œ๋ฒ„์™€ DB)์— ์„ค์น˜๋˜์–ด์„œ ๋กœ๊ทธ ํŒŒ์ผ์˜ ๋ณ€ํ™”๊ฐ€ ์žˆ์„๋•Œ ๋ณ€ํ™”๋œ ๋กœ๊ทธํŒŒ์ผ์„ Logstash๋กœ ์ „์†ก


๐Ÿฃ Filebeat ์„ค์น˜

  • filebeat.yml(ํ™˜๊ฒฝ์„ค์ • ํŒŒ์ผ) ์„ค์ • ๋ณ€๊ฒฝ
    • input_type log
    • logstash ip (5044ํฌํŠธ)
  • ๋กœ๊ทธ๋ฅผ ๋ฐ›๋Š” logstash๋„ ์„ค์ • ํ•„์š”ํ•จ
    • ์„ค์ •ํŒŒ์ผ : /etc/logstash/conf.d/logstash.conf
input { 
  beats {
    port => 5044
  }
}
output {
        if [beat][hostname] == "ip-172-31-30-178" or [beat][hostname] == "ip-172-31-30-179" {
                elasticsearch {
                        hosts => "localhost:9200"
                        manage_template => false
                        index => "tomcat-%{+YYYY.MM.dd}"
                        document_type => "%{[@metadata][type]}"
                }
        }
        else if [beat][hostname] == "ip-172-31-30-180" {
                elasticsearch {
                        hosts => "localhost:9200"
                        manage_template => false
                        index => "database-%{+YYYY.MM.dd}"
                        document_type => "%{[@metadata][type]}"
                }
        }
        else {
                elasticsearch {
                        hosts => "localhost:9200"
                        manage_template => false
                        index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
                        document_type => "%{[@metadata][type]}"
                }
        }
}

๐Ÿฃ Filebeat ์‹คํ–‰

  • ์žฌ์‹œ์ž‘
    • sudo service kibana restart
    • sudo service elasticsearch restart
    • sudo initctl restart logstash
    • sudo service filebeat restart

๐Ÿ“™ Curator

Q. Disk Size๋Š” ํ•œ์ •๋˜์–ด ์žˆ๊ณ  ๋กœ๊ทธ๊ฐ€ ๊ณ„์† ์Œ“์ด๋ฉด Old Data์‚ญ์ œ ์–ด๋–ป๊ฒŒ ํ•ด?

Curator : ์†์‰ฝ๊ฒŒ Data ๋ณด์กด๊ธฐ๊ฐ„ ๋ฐ Data์ตœ๋Œ€ ์‚ฌ์šฉ๋Ÿ‰์„ ์„ค์ •ํ•ด์„œ ELK Stack์˜ Disk๊ณต๊ฐ„ ๋ถ€์กฑ ๋ฌธ์ œ๊ฐ€ ์—†๋„๋ก ํ•ด์คŒ

Q. ๋งŒ์•ฝ ์˜ค๋ž˜๋œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ด์•ผํ•œ๋‹ค๋ฉด?

๋งค์ผ ๋ฐœ์ƒ๋œ ๋กœ๊ทธ๋ฅผ S3(Amazon)์— ์ €์žฅํ•ด์„œ ํ•„์š”์‹œ ELK Stack ๋กœ๊ทธ ๋ฐฑ์—… ๋ฐ ๋ณต์› ๊ฐ€๋Šฅ


๐Ÿฃ Curator ์„ค์น˜

  • pip install elasticsearch-curator
  • curator.yml(ํ™˜๊ฒฝ์„ค์ • ํŒŒ์ผ) ์„ค์ • ๋ณ€๊ฒฝ
    • ์ผ์ •๊ธฐ๊ฐ„์ด ์ง€๋‚ฌ์„ ๊ฒฝ์šฐ ์‚ญ์ œ(Time Base Delete)
    • ๋””์Šคํฌ ์‚ฌ์šฉ๋Ÿ‰์ด n%๋ฅผ ์ดˆ๊ณผํ–ˆ์„ ๊ฒฝ์šฐ ์‚ญ์ œ(Data Base Delete)

๐Ÿ“’ CRONTAB

  • ์˜ˆ์•ฝ๋œ ์ž‘์—…์„ ์ž๋™์œผ๋กœ ์‹คํ–‰ํ•˜๋Š” ์Šค์ผ€์ค„๋ง ์‹œ์Šคํ…œ(์‚ฌ์šฉ์ž๊ฐ€ ์ง€์ •ํ•œ ์‹œ๊ฐ„์— ์ฃผ๊ธฐ์ ์œผ๋กœ ํŠน์ • ์ž‘์—…์ด๋‚˜ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰)
    • /etc/cron.d
    • curator_cron์— daily๋กœ ์„ค์ •ํ•˜์—ฌ ๋งค์ผ ์ž๋™์œผ๋กœ ์‚ญ์ œํ•˜๋„๋ก ์„ค์ • ๊ฐ€๋Šฅ

profile
Study Log ๐Ÿ“‚

1๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2023๋…„ 8์›” 17์ผ

์ •๋ณด ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ