Kubernetes Elastic Stack 구성하기 (Elasticsearch, Kibana, Beats...

Kubernetes Elastic Stack 구성하기 (Elasticsearch, Kibana, Beats...

반응형

반응형

ELK Stack에 데이터 수집 플랫폼인 Beat가 추가되어 4개의 조합은 Elastic Stack으로 불린다.

일반적으로 Elasticsearch> Kibana> Logstash> Beats 순서로 구성하고, 모든 구성 요소는 버전을 고려하여 구성한다. (본문에서는 CentOS 8 기반으로 한다.)

ELK Stack은 https://github.com/elastic/helm-charts 참고하여 Helm으로 설치 가능하다. (또는 제공되는 Docker Image로 실행할 수 있다.)

1. Elasticsearch 설치

- Java와 SHASUM을 설치한다. (Java 경로 설정 필요)

sudo dnf install java-11-openjdk-devel.x86_64 yum install -y perl-Digest-SHA

- Elasticsearch v7.11.1 RPM을 설치한다.

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.11.1-x86_64.rpm wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.11.1-x86_64.rpm.sha512 shasum -a 512 -c elasticsearch-7.11.1-x86_64.rpm.sha512 sudo rpm --install elasticsearch-7.11.1-x86_64.rpm

- Elasticsearch는 설치 후 자동으로 실행되지 않는다. 부팅 시 자동 실행될 수 있도록 설정한다.

sudo chkconfig --add elasticsearch sudo /bin/systemctl daemon-reload sudo /bin/systemctl enable elasticsearch.service

- Elasticsearch 노드가 정상적으로 실행 중인지 확인한다.

curl -X GET "localhost:9200/_cat/health?v=true&pretty;"

- Status는 green이고 노드가 1개 실행 중임을 확인할 수 있다.

Elasticsearch 실행 상태

2. Kibana 설치

- RPM을 이용하여 Kibana 7.11을 설치한다.

wget https://artifacts.elastic.co/downloads/kibana/kibana-7.11.1-x86_64.rpm shasum -a 512 kibana-7.11.1-x86_64.rpm sudo rpm --install kibana-7.11.1-x86_64.rpm

- /etc/kibana/kibana.yml에서 아래 부분은 주석 제거 및 수정한다.(/etc/kibana/kibana.yml)

server.port: 5601 http.host: 0.0.0.0 elasticsearch.hosts: ["http://localhost:9200"]

- systemctl restart kibana를 통해 재실행하고, 브라우저에서 http://서버IP:5601로 접속하여 확인한다.

Kibana Home

3. Logstash 설치

- RPM을 이용하여 Logstash 7.11을 설치한다.

sudo wget https://artifacts.elastic.co/downloads/logstash/logstash-7.11.1-x86_64.rpm shasum logstash-7.11.1-x86_64.rpm sudo rpm --install logstash-7.11.1-x86_64.rpm

- logstash-sample.conf에서 host => "0.0.0.0" 추가한다. (logstash-sample.conf)

input { beats { port => 5044 host => "0.0.0.0" } }

4. Filebeat 구성

- 로그 수집 대상 노드에 Filebeat를 설치한다.

sudo yum install -y perl-Digest-SHA wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.11.1-x86_64.rpm shasum filebeat-7.11.1-x86_64.rpm sudo rpm --install filebeat-7.11.1-x86_64.rpm

- filebeat modules list 통해 모듈을 확인한다. 테스트 용도로 filebeat modules enable apache를 통해 모듈 활성화한다. /etc/filebeat/modules.d/apache.yml에서 수집 정보를 설정한다.(/etc/filebeat/modules.d/apache.yml)

# Module: apache # Docs: https://www.elastic.co/guide/en/beats/filebeat/7.11/filebeat-module-apache.html - module: apache # Access logs access: enabled: true input: fields: server_name: test-web log_type: apache_access var.paths: ["/var/log/httpd/access_log"] # Set custom paths for the log files. If left empty, # Filebeat will choose the paths depending on your OS. #var.paths: # Error logs error: enabled: true input: fields: server_name: test-web log_type: apache_error var.paths: ["/var/log/httpd/error_log"] # Set custom paths for the log files. If left empty, # Filebeat will choose the paths depending on your OS. #var.paths:

- /etc/filebeat/filebeat.yml에서 전송할 로그 목적지를 설정한다. (ELK 구성되어 있는 노드 IP로 수정한다.) systemctl restart filebeat로 재실행한다.(/etc/filebeat/filebeat.yml)

# ------------------------------ Logstash Output ------------------------------- output.logstash: # The Logstash hosts hosts: ["50.0.0.10:5044"]

참고 Link

1. 서비스 확인 : https://www.elastic.co/guide/en/beats/libbeat/7.x/beats-reference.html#beats-reference

2. 버전 확인 : https://www.elastic.co/kr/support/matrix

3. ELK 설치 : https://www.elastic.co/guide/index.html, https://github.com/elastic/helm-charts/tree/master/elasticsearch

반응형

from http://joobly.tistory.com/59 by ccl(A) rewrite - 2021-11-10 22:00:57