Notice
Recent Posts
Recent Comments
Link
ยซ   2024/10   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Tags
more
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

R136A1

ELK Stack ํ™˜๊ฒฝ ๊ตฌ์„ฑ ๋ณธ๋ฌธ

PROJECT/๐Ÿ’™ํ•ญ๋งŒ

ELK Stack ํ™˜๊ฒฝ ๊ตฌ์„ฑ

r136a1x27 2022. 7. 5. 22:13

์˜คํ”ˆ์†Œ์Šค ํ”„๋กœ์ ํŠธ ElasticSearch + LogStash + Kibana์˜ ์•ž ๊ธ€์ž๋งŒ ๋”ฐ์„œ ๋งŒ๋“ค์–ด์ง„ ์šฉ์–ด

LogStash: ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ํŒŒ์ดํ”„๋ผ์ธ, ๋กœ๊ทธ๋ฅผ ์ˆ˜์ง‘ํ•˜์—ฌ ElasticSearch์— ์ „์†ก

ElasticSearch: LogStash๋ฅผ ํ†ตํ•ด์„œ ์ „์†ก๋ฐ›์€ ๋ฐ์ดํ„ฐ ๋ถ„์„ ๋ฐ ์ €์žฅ

Kibana: ElasticSearch์— ์ €์žฅ๋˜์–ด ์žˆ๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์‹œ๊ฐํ™”ํ•˜๊ณ , ์‹ค์‹œ๊ฐ„์œผ๋กœ ๋ถ„์„

 

์œ„์˜ ELK์—์„œ Beat๊นŒ์ง€ ์ถ”๊ฐ€๋˜๋ฉด์„œ ELK Stack์ด๋ผ๊ณ  ๋ถˆ๋ฆผ

Beat: ๋Œ€์ƒ ์„œ๋ฒ„์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์ˆ˜์ง‘ํ•˜๋Š” ์—ญํ•  ๋‹ด๋‹น

https://potato-yong.tistory.com/140


๊ณต์‹ ์„ค์น˜ ๋ฐฉ๋ฒ• https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html 

์„ค์น˜ ๋ฐฉ๋ฒ• - OS์˜ ์ข…๋ฅ˜์— ๋”ฐ๋ผ ๋‚˜๋‰˜์–ด์ ธ์žˆ์Œ

1) Linux, MacOS => tar.gz

2) Windows => .zip

3) Debian-based System(Debian, Ubuntu) => deb

4) RPM-based System(RedHat, CentOS, SLES, OpenSuSE) => rpm

+) Docker

 

Support Matrix๋ฅผ ํ†ตํ•œ OS ์„ ์ • https://www.elastic.co/kr/support/matrix

=> ๊ฐ€์žฅ ํ˜ธํ™˜์„ฑ์ด ์ข‹์€ CentOS 7 ์„ ํƒ

 

๊ณต์‹ ๋‹ค์šด๋กœ๋“œ ๋งํฌ http://isoredirect.centos.org/centos/7/isos/x86_64/

์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋ฒ„์ „ ์กด์žฌ

Minimal - ๋ฆฌ๋ˆ…์Šค ์‹œ์Šคํ…œ์— ์š”๊ตฌ๋˜๋Š” ์ตœ์†Œ ํŒจํ‚ค์ง€. (GUI ๋ฏธํฌํ•จ)

DVD - Minimal ํŒจํ‚ค์ง€๋ฅผ ํฌํ•จํ•˜๊ณ  ๋ช‡๊ฐœ์˜ ์œ ํ‹ธ๋ฆฌํ‹ฐ ํŒจํ‚ค์ง€๋ฅผ ํฌํ•จํ•จ.(๊ธฐ๋ณธ ๊ฐœ๋ฐœํŒจํ‚ค์ง€ ๋ฐ‹ GUI ํŒจํ‚ค์ง€)

Everything - DVD ํŒจํ‚ค์ง€๋ฅผ ํฌํ•จํ•˜๊ณ  ํ–ฅ์ƒ๋œ ์œ ์ €ํŒจํ‚ค์ง€, ๊ฐœ๋ฐœ ํŒจํ‚ค์ง€ ์…‹ ๋ชจ๋‘ ํฌํ•จ.(Smart card support ๋“ฑ)

Netinstall - ๋„คํŠธ์›Œํฌ ์„ค์น˜๋ฅผ ์œ„ํ•œ ์ตœ์†Œ์˜ CD ์ด๋ฏธ์ง€.

 

๋ฐํƒ‘์— ๊ตฌ์„ฑํ•  ๋•Œ๋Š” DVD๋กœ ํ•˜๊ณ  ๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด์— ๊ตฌ์„ฑํ•  ๋•Œ ๋ฌด๊ฑฐ์šด ๊ฒƒ ๊ฐ™์œผ๋ฉด Minimal ํ•˜๋ฉด ๋ ๋“ฏ

 

ElasticSearch

CentOS ๊ณต์‹ ElasticSearch ์„ค์น˜ ๋ฐฉ๋ฒ• https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html

์ค‘๊ฐ„์— sudo ๋ช…๋ น์ด ์•ˆ๋ผ์„œ ๊ณ ์นจ
๋ฃจํŠธ ๊ณ„์ •์œผ๋กœ ์ „ํ™˜ su - root
echo '๊ณ„์ •๋ช… ALL=(ALL) ALL' >> /etc/sudoers ์ž…๋ ฅ
๋‹ค์‹œ su ๊ณ„์ •๋ช… ์œผ๋กœ ์ „ํ™˜ํ•˜์—ฌ sudo ์‚ฌ์šฉํ•˜๋ฉด ์ž˜ ๋จ
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
# /etc/yum.repos.d/ ๋””๋ ‰ํ† ๋ฆฌ์— elasticsearch.repo ์ž‘์„ฑ

$ sudo vim /etc/yum.repos.d/elasticsearch.repo

[elasticsearch]
name=Elasticsearch repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md

centOS์ด๋ฏ€๋กœ yum ์„ ํƒ

sudo yum install --enablerepo=elasticsearch elasticsearch
sudo vim /etc/elasticsearch/elasticsearch.yml

network.host: 192.168.0.1 ์„ 127.0.0.1๋กœ ๋ณ€๊ฒฝ & ์ฃผ์„ ์ œ๊ฑฐ

http.port:9200 ์ฃผ์„ ์ œ๊ฑฐ

curl http://127.0.0.1:9200

curl๋กœ elasticsearch ํ†ต์‹  ๋˜๋Š”์ง€ ํ™•์ธ

 

์ฒ˜์Œ์—” ๊ณต์‹๋ฌธ์„œ ํ† ๋Œ€๋กœ ๋ชจ๋“  ๊ณผ์ •์— ๋Œ€ํ•ด์„œ ์™œ ๊ทธ๋Ÿฐ์ง€ ์ ์œผ๋ ค๊ณ  ํ–ˆ๋Š”๋ฐ

๋ญ๊ฐ€ ์—„์ฒญ ๋งŽ์•„์„œ ๊ทธ๋ƒฅ ํ•˜๋ฉด์„œ ๋ฐฐ์šฐ๊ธฐ๋กœ ํ•จ


Kibana

https://www.elastic.co/guide/en/kibana/8.3/rpm.html#rpm-repo

# /etc/yum.repos.d/ ๋””๋ ‰ํ† ๋ฆฌ์— kibana.repo ์ž‘์„ฑ

$ sudo vim /etc/yum.repos.d/kibana.repo

[kibana-8.x]
name=Kibana repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

centos์ด๋ฏ€๋กœ yum ์„ ํƒ

yum install kibana -y

kibana ์‹คํ–‰

systemctl start kibana
systemctl enable kibana

์™ธ๋ถ€์—์„œ ์ ‘๊ทผํ•   ์ˆ˜ ์žˆ๋„๋ก /etc/kibana/kibana.yml์—์„œ server.host๋ฅผ ์ฃผ์„ ํ•ด์ œํ•˜๊ณ  0.0.0.0 ์œผ๋กœ ๋ณ€๊ฒฝ

file:///usr/share/doc/HTML/index.html

 

ifconfig๋กœ ip์ฃผ์†Œ ํ™•์ธํ•ด์ฃผ๊ณ , 192.168.19.131:5601๋กœ ์ ‘์†ํ•˜๋ฉด ๋œ๋‹ค.(๋˜๋Š” localhost:5601)

๋ญ”๊ฐ€ kibana ์„ค์น˜ํ•˜๊ณ ๋ถ€ํ„ฐ ๋ ‰์ด ๋„ˆ๋ฌด ๊ฑธ๋ ค์„œ...๋žจ ๋Š˜๋ ค์คฌ๋‹ค. (1GB -> 2GB)

sudo /usr/share/kibana/bin/kibana

LogStash

๊ณต์‹ https://www.elastic.co/guide/en/logstash/current/installing-logstash.html 

java -version ์œผ๋กœ ๊น”๋ ค์žˆ๋Š”์ง€ ํ™•์ธ ๋จผ์ €

# /etc/yum.repos.d/์— logstash.repo ์ž‘์„ฑ

[logstash-8.x]
name=Elastic repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
yum install logstash -y
systemctl start logstash
systemctl enable logstash

logstash๋Š” config ํŒŒ์ผ์ด ํ•„์š”ํ•จ(/usr/share/logstash/bin/logstash.conf)

ํŒŒ์ดํ”„๋ผ์ธ 3๊ฐ€์ง€๋กœ ๊ตฌ์„ฑ๋จ (input/filter/output)

# ๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ ํ˜•ํƒœ
input {
	stdin { }
}
output {
	stdout { }
}

stdin = ํ‚ค๋ณด๋“œ๋กœ input(์ž…๋ ฅ)์„ ๋ฐ›๊ฒ ๋‹ค

stdout = ๋ชจ๋‹ˆํ„ฐ๋กœ output(์ถœ๋ ฅ) ํ•˜๊ฒ ๋‹ค

ํ•˜๊ณ  ./logstash -f logstash.conf ํ–ˆ๋”๋‹ˆ ์ด๋”ด ์˜ค๋ฅ˜ ๋œธ...

https://www.reddit.com/r/elasticsearch/comments/9d04av/how_do_i_solve_this_problem/

๋ฉ”๋ชจ๋ฆฌ ๋ถ€์กฑํ•˜๋‹ค๊ธธ๋ž˜ 2GB์—์„œ 3GB๋กœ ๋Š˜๋ ค์คŒ.

[root@localhost bin]# ./logstash -f logstash.conf

Using bundled JDK: /usr/share/logstash/jdk
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000ca660000, 899284992, 0) failed; error='Not enough space' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 899284992 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /usr/share/logstash/bin/hs_err_pid18636.log

๋‹ค์‹œ ํ–ˆ๋”๋‹ˆ ๋ญ”๊ฐ€ ์„ฑ๊ณตํ•œ๊ฒƒ๊ฐ™๊ธด ํ•จ

Using bundled JDK: /usr/share/logstash/jdk
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
hello
WARNING: Could not find logstash.yml which is typically located in $LS_HOME/config or /etc/logstash. You can specify the path using --path.settings. Continuing using the defaults
Could not find log4j2 configuration at path /usr/share/logstash/config/log4j2.properties. Using default config which logs errors to the console
[WARN ] 2022-07-16 13:43:34.801 [main] runner - NOTICE: Running Logstash as superuser is not recommended and won't be allowed in the future. Set 'allow_superuser' to 'false' to avoid startup errors in future releases.
[INFO ] 2022-07-16 13:43:34.833 [main] runner - Starting Logstash {"logstash.version"=>"8.3.2", "jruby.version"=>"jruby 9.2.20.1 (2.5.8) 2021-11-30 2a2962fbd1 OpenJDK 64-Bit Server VM 11.0.15+10 on 11.0.15+10 +indy +jit [linux-x86_64]"}
[INFO ] 2022-07-16 13:43:34.834 [main] runner - JVM bootstrap flags: [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djruby.compile.invokedynamic=true, -Djruby.jit.threshold=0, -XX:+HeapDumpOnOutOfMemoryError, -Djava.security.egd=file:/dev/urandom, -Dlog4j2.isThreadContextMapInheritable=true, -Djruby.regexp.interruptible=true, -Djdk.io.File.enableADS=true, --add-opens=java.base/java.security=ALL-UNNAMED, --add-opens=java.base/java.io=ALL-UNNAMED, --add-opens=java.base/java.nio.channels=ALL-UNNAMED, --add-opens=java.base/sun.nio.ch=ALL-UNNAMED, --add-opens=java.management/sun.management=ALL-UNNAMED]
[INFO ] 2022-07-16 13:43:34.899 [main] settings - Creating directory {:setting=>"path.queue", :path=>"/usr/share/logstash/data/queue"}
[INFO ] 2022-07-16 13:43:34.906 [main] settings - Creating directory {:setting=>"path.dead_letter_queue", :path=>"/usr/share/logstash/data/dead_letter_queue"}
[WARN ] 2022-07-16 13:43:35.515 [LogStash::Runner] multilocal - Ignoring the 'pipelines.yml' file because modules or command line options are specified
[INFO ] 2022-07-16 13:43:35.571 [LogStash::Runner] agent - No persistent UUID file found. Generating new UUID {:uuid=>"d7e5f1d9-778f-436b-a965-b3a32e0280d2", :path=>"/usr/share/logstash/data/uuid"}
[INFO ] 2022-07-16 13:43:37.559 [Agent thread] configpathloader - No config files found in path {:path=>"/usr/share/logstash/logstash-simple.conf"}
[ERROR] 2022-07-16 13:43:37.563 [Agent thread] sourceloader - No configuration found in the configured sources.
[INFO ] 2022-07-16 13:43:37.787 [Api Webserver] agent - Successfully started Logstash API endpoint {:port=>9600, :ssl_enabled=>false}
[INFO ] 2022-07-16 13:43:37.881 [LogStash::Runner] runner - Logstash shut down.

๊ทผ๋ฐ ์ด๋Ÿฐ ๊ณผ์ •์€ ๋ชปํ–ˆ์Œ...

https://www.youtube.com/watch?v=FpEubrKOoVE&t=160s

# logstash script ์ ์šฉ

$ cd /usr/share/logstash/bin
$ ./system-install


Successfully created system startup script for Logstash ๊ฐ€ ๋œจ๋ฉด ์„ฑ๊ณต์ด๋‹ค

 

Comments