'2020/04'에 해당되는 글 29건

  1. 2020.04.03 [Elastic] Elasticsearch, Metricbeat, Docker Compose 삽질.
  2. 2020.04.03 [Elasticsearch] Index Lifecycle Management 실행 주기
  3. 2020.04.03 [Elasticsearch] Index 생성 시 Name Pattern
  4. 2020.04.02 [Kibana] Docker Compose 구성 하기
  5. 2020.04.02 [Elasticsearch] Docker Compose 구성 하기
  6. 2020.04.01 [Docker] Docker Compose 로 Ubuntu 올리기
  7. 2020.04.01 [Beats] Metricbeat Docker Compose 기본 구성 하기
  8. 2020.04.01 [Kibana] Docker Compose 설정 시 environment 중
  9. 2020.04.01 [Elasticsearch] Docker Compose 구성 시 주의 사항.

[Elastic] Elasticsearch, Metricbeat, Docker Compose 삽질.

Elastic 2020. 4. 3. 18:48

metricbeat 사용 시 템플릿 설정이 잘 못 되었다면 반드시 삭제 하고 다시 생성 합니다.

또는

- setup.template.overwrite: true

를 설정 합니다.

 

metricbeat 에서 데이터를 잘 보내고 있는데 데이터가 정상적으로 들어 오지 않으면, 템플릿을 리셋 하거나 아래 설정을 확인 합니다.

- setup.template.settings._source.enabled: true

 

이미 경험했던 내용이고 기록도 했었는데 바로 찾아 내지 못하고 삽질을 했네요.

반성 중입니다.

:

[Elasticsearch] Index Lifecycle Management 실행 주기

Elastic/Elasticsearch 2020. 4. 3. 14:04

설정 하고 왜 바로 동작 안하지 그랬는데, 다 이유가 있었습니다.

 

[LifecycleSettings.java]

/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License;
 * you may not use this file except in compliance with the Elastic License.
 */
package org.elasticsearch.xpack.core.ilm;

import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.xpack.core.scheduler.CronSchedule;

/**
 * Class encapsulating settings related to Index Lifecycle Management X-Pack Plugin
 */
public class LifecycleSettings {
    public static final String LIFECYCLE_POLL_INTERVAL = "indices.lifecycle.poll_interval";
    public static final String LIFECYCLE_NAME = "index.lifecycle.name";
    public static final String LIFECYCLE_INDEXING_COMPLETE = "index.lifecycle.indexing_complete";
    public static final String LIFECYCLE_ORIGINATION_DATE = "index.lifecycle.origination_date";
    public static final String LIFECYCLE_PARSE_ORIGINATION_DATE = "index.lifecycle.parse_origination_date";
    public static final String LIFECYCLE_HISTORY_INDEX_ENABLED = "indices.lifecycle.history_index_enabled";

    public static final String SLM_HISTORY_INDEX_ENABLED = "slm.history_index_enabled";
    public static final String SLM_RETENTION_SCHEDULE = "slm.retention_schedule";
    public static final String SLM_RETENTION_DURATION = "slm.retention_duration";


    public static final Setting<TimeValue> LIFECYCLE_POLL_INTERVAL_SETTING = Setting.positiveTimeSetting(LIFECYCLE_POLL_INTERVAL,
        TimeValue.timeValueMinutes(10), Setting.Property.Dynamic, Setting.Property.NodeScope);
    public static final Setting<String> LIFECYCLE_NAME_SETTING = Setting.simpleString(LIFECYCLE_NAME,
        Setting.Property.Dynamic, Setting.Property.IndexScope);
    public static final Setting<Boolean> LIFECYCLE_INDEXING_COMPLETE_SETTING = Setting.boolSetting(LIFECYCLE_INDEXING_COMPLETE, false,
        Setting.Property.Dynamic, Setting.Property.IndexScope);
    public static final Setting<Long> LIFECYCLE_ORIGINATION_DATE_SETTING =
        Setting.longSetting(LIFECYCLE_ORIGINATION_DATE, -1, -1, Setting.Property.Dynamic, Setting.Property.IndexScope);
    public static final Setting<Boolean> LIFECYCLE_PARSE_ORIGINATION_DATE_SETTING = Setting.boolSetting(LIFECYCLE_PARSE_ORIGINATION_DATE,
        false, Setting.Property.Dynamic, Setting.Property.IndexScope);
    public static final Setting<Boolean> LIFECYCLE_HISTORY_INDEX_ENABLED_SETTING = Setting.boolSetting(LIFECYCLE_HISTORY_INDEX_ENABLED,
        true, Setting.Property.NodeScope);


    public static final Setting<Boolean> SLM_HISTORY_INDEX_ENABLED_SETTING = Setting.boolSetting(SLM_HISTORY_INDEX_ENABLED, true,
        Setting.Property.NodeScope);
    public static final Setting<String> SLM_RETENTION_SCHEDULE_SETTING = Setting.simpleString(SLM_RETENTION_SCHEDULE,
        // Default to 1:30am every day
        "0 30 1 * * ?",
        str -> {
        try {
            if (Strings.hasText(str)) {
                // Test that the setting is a valid cron syntax
                new CronSchedule(str);
            }
        } catch (Exception e) {
            throw new IllegalArgumentException("invalid cron expression [" + str + "] for SLM retention schedule [" +
                SLM_RETENTION_SCHEDULE + "]", e);
        }
    }, Setting.Property.Dynamic, Setting.Property.NodeScope);
    public static final Setting<TimeValue> SLM_RETENTION_DURATION_SETTING = Setting.timeSetting(SLM_RETENTION_DURATION,
        TimeValue.timeValueHours(1), TimeValue.timeValueMillis(500), Setting.Property.Dynamic, Setting.Property.NodeScope);
}

설정을 하셨다면 이제는 기다리시면 됩니다. 

:

[Elasticsearch] Index 생성 시 Name Pattern

Elastic/Elasticsearch 2020. 4. 3. 11:22

Elastic Stack 을 사용하다 보면 Index 를 자동으로 생성 시켜 주는 설정들을 사용 하게 됩니다.

 

beats 에서는 output elasticsearch 사용 시 설정을 하게 되고,

logstash 에서도 output elasticsearch 사용 시 설정을 하게 됩니다.

 

보통 이 설정을 아래와 같이 하는데요.

 

Logstash)

index

- Value type is string
- Default value is "logstash-%{+YYYY.MM.dd}"

 

Beats)

index

The index name to write events to when you’re using daily indices. 
The default is "beat-%{[agent.version]}-%{+yyyy.MM.dd}" 
(for example, "beat-7.6.2-2020-04-02"). 
If you change this setting, you also need to configure the setup.
template.name and setup.template.pattern options (see Elasticsearch index template).

output.elasticsearch:
  hosts: ["https://localhost:9200"]
  index: "beats-%{[agent.version]}-%{+yyyy.MM.dd}"

- filebeat, metricbeat ...

 

보시면 아시겠지만, Daily rolling 으로 많이 사용하게 됩니다.

무조건 하루 단위로 생성이 되기 때문에 규모가 너무 작거나 너무 크거나 할 경우 효율이 떨어 질 수 밖에 없습니다.

그래서 Index Lifecycle Management 라는 기능을 Elasticsearch 에서 제공하고 있으니 활용 하시기 바랍니다.

 

여기서 문제)

그럼 output.elasticsearch.index 설정과 ilm 설정이 동시에 사용 중일 때 어떤 설정에 맞춰서 index 가 생성이 될까요?

 

정답)

ilm 설정이 우선 합니다. 

 

Elastic 의 공식 메시지는 이렇습니다.

https://www.elastic.co/guide/en/elasticsearch/reference/current/index-lifecycle-management.html

 

You can configure index lifecycle management (ILM) policies to automatically manage indices according to your performance, resiliency, and retention requirements.

 

:

[Kibana] Docker Compose 구성 하기

Elastic/Kibana 2020. 4. 2. 08:28

Kibana를 Docker로 구성 하기 위한 docker-compose.yml 내용을 살펴 봅니다.

 

참고문서)

 

https://www.elastic.co/guide/en/kibana/current/docker.html

 

docker-compose.yml)

version: '2.2'
services:
  ${KIBANA-SERVICE-NAME}:
    image: docker.elastic.co/kibana/kibana:7.6.2
    container_name: ${KIBANA-SERVICE-NAME}
#    depends_on:
#      - ${ES-SERVICE-NAME}
    ports:
      - 5601:5601
    expose:
      - 5601
    environment:
      ELASTICSEARCH_HOSTS: http://host.docker.internal:9200
    networks:
      - ${NETWORK-NAME}

networks:
  ${NETWORK-NAME}:
    driver: bridge

위 설정은 host 에서 Elasticsearch 를 Standalone 으로 띄우고 Kibana 를 컨테이너로 실행 시킨 후 연동 하도록 한 것입니다.

접속은 아래와 같이 하면 됩니다.

- http://localhost:5601

 

만약, docker-compose.yml 파일 내 Elasticsearch 와 Kibana 를 모두 구성해서 띄우실 때는 아래 설정을 맞춰 주면 됩니다.

- depends_on : 섹션에서 Elasticsearch 실행 후 Kibana 가 실행 되도록 구성

- network 구성은  같은 걸 사용하도록 하고 bridge 로 설정

- kibana 에서 elasticsearch 를 찾기 위해 host.docker.internal 이 아닌 ${ES-SERVICE-NAME} 으로 변경

 

또는 다른 인스턴스에 Elasticsearch 가 구성이 되어 있다면,

- environment: 섹션에서 host.docker.internal 이 아닌 Elasticsearch가 구성된 인스턴스의 DNS나 IP로 변경

하시면 됩니다.

 

 

 

 

:

[Elasticsearch] Docker Compose 구성 하기

Elastic/Elasticsearch 2020. 4. 2. 07:49

Elasticsearch 를 Single Node 로 구성 하기 위한 docker-compose.yml 내용을 살펴 봅니다.

 

참고문서)

https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html

 

docker-compose.yml)

version: '2.2'
services:
  ${ES-SERVICE-NAME}:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.6.2
    container_name: ${ES-SERVICE-NAME}
    environment:
      - node.name=${NODE-NAME}
      - cluster.name=${CLUSTER-NAME}
      - discovery.type=single-node
      - discovery.seed_hosts=${NODE-NAME}
      - path.data=/usr/share/elasticsearch/data
      - path.logs=/usr/share/elasticsearch/logs
      - bootstrap.memory_lock=true
      - http.port=9200
      - transport.port=9300
      - transport.compress=true
      - network.host=0.0.0.0
      - http.cors.enabled=false
      - http.cors.allow-origin=/https?:\/\/localhost(:[0-9]+)?/
      - gateway.expected_master_nodes=1
      - gateway.expected_data_nodes=1
      - gateway.recover_after_master_nodes=1
      - gateway.recover_after_data_nodes=1
      - action.auto_create_index=true
      - action.destructive_requires_name=true
      - cluster.routing.use_adaptive_replica_selection=true
      - xpack.monitoring.enabled=false
      - xpack.ml.enabled=false
      - http.compression=true
      - http.compression_level=3
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nproc:
        soft: 1024000
        hard: 1024000
      nofile:
        soft: 1024000
        hard: 1024000
    sysctls:
      net.core.somaxconn: 65000
    healthcheck:
      test: ["CMD-SHELL", "curl --silent --fail localhost:9200/_cat/health || exit 1"]
      interval: 30s
      timeout: 30s
      retries: 3
    restart: always
    volumes:
      - ${NAMED-VOLUME-DATA}:/usr/share/elasticsearch/data:rw
      - ${NAMED-VOLUME-LOG}:/usr/share/elasticsearch/logs:rw
#      - ${FULL-PATH-DATA}:/usr/share/elasticsearch/data:rw
#      - ${FULL-PATH-LOG}:/usr/share/elasticsearch/logs:rw
    ports:
      - 9200:9200
      - 9300:9300
    expose:
      - 9200
      - 9300
    networks:
      - ${NETWORK-NAME}

volumes:
  ${NAMED-VOLUME-DATA}:
    driver: local
  ${NAMED-VOLUME-LOG}:
    driver: local

networks:
  ${NETWORK-NAME}:
    driver: bridge

 

Single Node 로 구성 하기 위해 중요한 설정은

- environment: 섹션에서 discovery.type=single-node 

입니다.

 

만약, Clustering 구성을 하고 싶다면 위 설정을 제거 하고 아래 세개 설정을 작성 하시면 됩니다.

- cluster.initial_master_nodes=# node 들의 private ip 를 등록 합니다.
- discovery.seed_hosts=# node 들의 private ip 를 등록 합니다.

- network.publish_host=# 컨테이너가 떠 있는 host 의 private ip 를 등록 합니다.

 

path.data 에 대한 구성을 복수로 하고 싶으실 경우

- volumes: 섹션에서 named volume 을 여러개 설정 하시거나

- bind mount 설정을 구성 하셔서 

적용 하시면 됩니다.

 

위 docker-compose.yml 을 기준으로 single node 구성과 cluster 구성을 모두 하실 수 있습니다.

 

  • ${....} 는 변수명 입니다.
    • 본인의 환경에 맞춰 작명(?) 하셔서 변경 하시면 됩니다.
:

[Docker] Docker Compose 로 Ubuntu 올리기

Cloud&Container/IaC 2020. 4. 1. 20:41

docker-compose.yml)

version: '3.7'
services:
  ubuntu-mac:
    image: ubuntu:18.04
    container_name: ubuntu-mac
    stdin_open: true
    tty: true
    command: [/bin/bash]

or

$ docker run --rm --name ubuntu-mac -ti ubuntu:18.04 /bin/bash

 

:

[Beats] Metricbeat Docker Compose 기본 구성 하기

Elastic/Beats 2020. 4. 1. 20:38

대부분 올라온 예제가 docker-compose.yml 내 ELKB 구성을 한방에 해서 사용을 하게 되어 있는데,

하고 싶은건 metricbeat 만 컨테이너 기반으로 올려서 agent 형태로 사용하고 다른 노드에서 실행 되고 있는

- Elasticsearch 와

- Kibana 로

통신 하게 하고 싶어서 기록해 봅니다.

 

특별한 내용은 전혀 없습니다.

 

참고문서)

https://www.elastic.co/guide/en/beats/metricbeat/current/running-on-docker.html

 

docker-compose.yml)

version: "3.7"
services:
  metricbeat:
    image: docker.elastic.co/beats/metricbeat:7.6.2
    user: root
    environment:
      - ELASTICSEARCH_HOSTS=http://host.docker.internal:9200
      - KIBANA_HOST=http://host.docker.internal:5601
    network_mode: "host"
    ports:
      - 9200:9200
      - 5601:5601

 

$ docker-compose up -d

 

위 구성은 host 장비에 Elasticsearch 와 Kibana 가 실행 되고 있고,

Metricbeat 를 컨테이너로 실행 시키고 host 장비를 모니터링 하기 위한 구성입니다.

즉, Metricbeat 를 컨테이너 기반의 Agent 로 사용 하는 거라고 보면 될 것 같습니다.

 

관련 문서는 아래 참고 하세요.

https://www.elastic.co/guide/en/beats/metricbeat/current/running-on-docker.html#monitoring-host

 

:

[Kibana] Docker Compose 설정 시 environment 중

Elastic/Kibana 2020. 4. 1. 09:47

kibana docker compose 에서 아래 변수가 어떤 값을 참조 하는지 확인 하시기 바랍니다.

 

참고 문서)

https://www.elastic.co/guide/en/kibana/current/docker.html

environment:
    ELASTICSEARCH_URL: http://${SERVICE-NAME}:9200
    ELASTICSEARCH_HOSTS: http://${SERVICE-NAME}:9200
또는
    ELASTICSEARCH_URL: http://${CONTAINER-NAME}:9200
    ELASTICSEARCH_HOSTS: http://${CONTAINER-NAME}:9200

단일 노드에 Elasticsearch 와 Kibana 두 개의 컨테이너를 띄울 때 Kibana 에서는 Elasticsearch 의 Service 명 또는 Container 명으로 Elasticsearch 를 찾습니다.

:

[Elasticsearch] Docker Compose 구성 시 주의 사항.

Elastic/Elasticsearch 2020. 4. 1. 09:02

정답이라기 보다는 구성 하면서 경험한 내용을 작성 한 것입니다.

나중에 기억이 나지 않을 수도 있으니 정상 동작 했던 내용을 기록 합니다.

 

Elasticsearch Docker Compose 구성 중 주의 사항)

- volume 구성 시 bind mount 를 사용할 경우는 mount 할 storage 를 미리 생성해 두어야 합니다.
- bind mount 사용 시 absolute path 설정을 하셔야 합니다.
- single node 구성 시 network.publish_host 설정은 하지 않아도 됩니다.
- cluster 구성 시 (물리적으로 node 3개) 개별 node 에서 clustering 을 하기 
위해서는 network.publish_host 설정을 하셔야 합니다.
- cluster 구성 시 컨테이너 내부 node 설정에는 private ip 를 등록 합니다.
- sysctls 옵션 에서 vm.max_map_count 설정이 되지 않기 때문에 host 에서 
$ sudo sysctl -w vm.max_map_count=262144 를 실행 해야 합니다.

 

: