본문 바로가기

개발/Others

[ELK] 시작한 김에 ELK(1)

Elasticsearch를 적용해보면서, 단순히 ES만 사용할것이 아니라, 일반적으로 하나의 Stack으로 보는

Logstash 와 Kibana도 설치해보기로 했다.

 

기존에 single node 로 구성한 es는 삭제하고, docker-compose 환경으로 새롭게 구성하겠다.

각 모듈을 개별적으로 설치 후 구성할수도 있겠지만.. 여기서는 현대 문명의 혜택을 누리고자 한다.

 

아래의 github으로 가면 Docker 환경에서의 ELK 구축을 위한 구성을 이미 해 두었고, 손쉽게 구축이 가능하다.

https://github.com/deviantony/docker-elk

 

GitHub - deviantony/docker-elk: The Elastic stack (ELK) powered by Docker and Compose.

The Elastic stack (ELK) powered by Docker and Compose. - GitHub - deviantony/docker-elk: The Elastic stack (ELK) powered by Docker and Compose.

github.com

프로젝트 clone 후 ".env" 파일을 열어 나에게 맞는 설정을 해준다. (pwd 부분..)

ELASTIC_VERSION=8.9.1

## Passwords for stack users
#

# User 'elastic' (built-in)
#
# Superuser role, full access to cluster management and data indices.
# https://www.elastic.co/guide/en/elasticsearch/reference/current/built-in-users.html
ELASTIC_PASSWORD='pwd'

# User 'logstash_internal' (custom)
#
# The user Logstash uses to connect and send data to Elasticsearch.
# https://www.elastic.co/guide/en/logstash/current/ls-security.html
LOGSTASH_INTERNAL_PASSWORD='pwd'

# User 'kibana_system' (built-in)
#
# The user Kibana uses to connect and communicate with Elasticsearch.
# https://www.elastic.co/guide/en/elasticsearch/reference/current/built-in-users.html
KIBANA_SYSTEM_PASSWORD='pwd'

# Users 'metricbeat_internal', 'filebeat_internal' and 'heartbeat_internal' (custom)
#
# The users Beats use to connect and send data to Elasticsearch.
# https://www.elastic.co/guide/en/beats/metricbeat/current/feature-roles.html
METRICBEAT_INTERNAL_PASSWORD='pwd'
FILEBEAT_INTERNAL_PASSWORD='pwd'
HEARTBEAT_INTERNAL_PASSWORD='pwd'

# User 'monitoring_internal' (custom)
#
# The user Metricbeat uses to collect monitoring data from stack components.
# https://www.elastic.co/guide/en/elasticsearch/reference/current/how-monitoring-works.html
MONITORING_INTERNAL_PASSWORD='pwd'

# User 'beats_system' (built-in)
#
# The user the Beats use when storing monitoring information in Elasticsearch.
# https://www.elastic.co/guide/en/elasticsearch/reference/current/built-in-users.html
BEATS_SYSTEM_PASSWORD='pwd'

설정 후 "docker-compose.yml" 파일을 열어 kibana와 logstash를 추가해준다.

  setup:
    profiles:
      - setup
    build:
      context: setup/
      args:
        ELASTIC_VERSION: ${ELASTIC_VERSION}
    init: true
    volumes:
      - ./setup/entrypoint.sh:/entrypoint.sh:ro,Z
      - ./setup/lib.sh:/lib.sh:ro,Z
      - ./setup/roles:/roles:ro,Z
    environment:
      ELASTIC_PASSWORD: ${ELASTIC_PASSWORD:-}
      LOGSTASH_INTERNAL_PASSWORD: ${LOGSTASH_INTERNAL_PASSWORD:-}
      KIBANA_SYSTEM_PASSWORD: ${KIBANA_SYSTEM_PASSWORD:-}
      METRICBEAT_INTERNAL_PASSWORD: ${METRICBEAT_INTERNAL_PASSWORD:-}
      FILEBEAT_INTERNAL_PASSWORD: ${FILEBEAT_INTERNAL_PASSWORD:-}
      HEARTBEAT_INTERNAL_PASSWORD: ${HEARTBEAT_INTERNAL_PASSWORD:-}
      MONITORING_INTERNAL_PASSWORD: ${MONITORING_INTERNAL_PASSWORD:-}
      BEATS_SYSTEM_PASSWORD: ${BEATS_SYSTEM_PASSWORD:-}
    networks:
      - elk
    depends_on:
      - elasticsearch
      - kibana
      - logstash

이하 생략..

설정이 완료되면 ELK를 구동한다.

$ docker-compose up setup
$ docker-compose up -d

Docker Desktop에서 확인

localhost:9200 으로 elasticsearch에 연결해본다. (.env에서 설정한 패스워드 필요, 계정은 "elastic")

// 20230827123525
// http://localhost:9200/

{
  "name": "elasticsearch",
  "cluster_name": "docker-cluster",
  "cluster_uuid": "D6mD5B6XRf-ml9jnv7nDfw",
  "version": {
    "number": "8.9.1",
    "build_flavor": "default",
    "build_type": "docker",
    "build_hash": "a813d015ef1826148d9d389bd1c0d781c6e349f0",
    "build_date": "2023-08-10T05:02:32.517455352Z",
    "build_snapshot": false,
    "lucene_version": "9.7.0",
    "minimum_wire_compatibility_version": "7.17.0",
    "minimum_index_compatibility_version": "7.0.0"
  },
  "tagline": "You Know, for Search"
}

localhost:5601로 Kibana에 연결해본다. (.env에서 설정한 패스워드 필요, 계정은 "elastic")


docker-compose를 통해 아주 간단하고 기본적인 환경을 구성해보았다.

다음에는 함께 구축한 logstash를 활용하여 간단한 로그를 발생시켜 확인하는 과정을 진행하고자 한다.

 

참고 : https://xodns.tistory.com/115

 

docker-compose로 ELK 8 버전 사용해보기 1부

https://www.elastic.co/kr/downloads/elasticsearch Download Elasticsearch Download Elasticsearch or the complete Elastic Stack (formerly ELK stack) for free and start searching and analyzing in minutes with Elastic. www.elastic.co https://www.elastic.co/kr/

xodns.tistory.com