'elastic'에 해당되는 글 130건

  1. 2020.06.03 [Filebeat] ilm 조심 하자.
  2. 2020.06.03 [Filebeat] template 설정 setup.template.append_fields
  3. 2020.05.11 [Beats] Filebeat 내 JSON 처리.
  4. 2020.04.16 [Logstash] Docker Compose 구성 하기.
  5. 2020.04.08 [Elasticsearch] UTC 를 사용 하는 이유.
  6. 2020.04.07 [Kibana] Visualize Metric JSON Input 예제
  7. 2020.04.07 [Elasticsearch] Docker Compose 실행 시 permission denied
  8. 2020.04.03 [Elastic] Elasticsearch, Metricbeat, Docker Compose 삽질.
  9. 2020.04.03 [Elasticsearch] Index Lifecycle Management 실행 주기
  10. 2020.04.03 [Elasticsearch] Index 생성 시 Name Pattern

[Filebeat] ilm 조심 하자.

Elastic/Beats 2020. 6. 3. 14:19

참고 문서)

https://www.elastic.co/guide/en/beats/filebeat/current/ilm.html

 

setup.ilm.check_exists

When set to false, disables the check for an existing lifecycle policy.

The default is true.

You need to disable this check if the Filebeat user connecting to a secured cluster doesn’t have the read_ilm privilege.

If you set this option to false, set setup.ilm.overwrite: true so the lifecycle policy can be installed.

 

setup.ilm.overwrite

When set to true, the lifecycle policy is overwritten at startup. The default is false.

 

이 설정은 template  설정과 output.elasticsearch.index 랑도 연관이 됩니다.

아주 삽질을 하게 만드는 설정이 될 수도 있습니다.

단, 알고 쓰면 삽질 안하고 모르고 쓰면 삽질 할 수도 있습니다.

 

늘 그렇지만, Elastic 사는 그냥 모르면 기본 설정만 사용하세요. :)

:

[Filebeat] template 설정 setup.template.append_fields

Elastic/Beats 2020. 6. 3. 14:15

참고 문서)

https://www.elastic.co/guide/en/beats/filebeat/current/configuration-template.html

 

설정 중에 필요한 내용이 있어서 기록해 봅니다.

 

setup.template.append_fields

 

A list of fields to be added to the template and Kibana index pattern.

This setting adds new fields. It does not overwrite or change existing fields.

This setting is useful when your data contains fields that Filebeat doesn’t know about in advance.

If append_fields is specified along with overwrite: true,

Filebeat overwrites the existing template and applies the new template when creating new indices.

Existing indices are not affected.

If you’re running multiple instances of Filebeat with different append_fields settings,

the last one writing the template takes precedence.

Any changes to this setting also affect the Kibana index pattern.

 

Example config:

setup.template.overwrite: true

setup.template.append_fields:

  - name: test.name

     type: keyword

  - name: test.hostname

     type: long

 

이 설정으로 dynamic mapping 이나 template 관련 번거로움을 간단하게 해결 할 수 있습니다.

저는 몇 개 field 에 대해서 date 로 설정을 해야 해서 이 설정을 사용했습니다.

 

:

[Beats] Filebeat 내 JSON 처리.

Elastic/Beats 2020. 5. 11. 14:18

1. input type log 에서 처리 하는 방법과

2. processor 에서 decode_json_fields 로 처리 하는 방법이 있습니다.

 

1번은 그냥 전체 로그에 대해서 처리

2번은 특정 필드의 메시지에 대해서 처리

 

자세한건 문서를 참고해 주세요.

 

[Reference]

https://www.elastic.co/guide/en/beats/filebeat/7.6/filebeat-input-log.html

https://www.elastic.co/guide/en/beats/filebeat/7.6/decode-json-fields.html

 

:

[Logstash] Docker Compose 구성 하기.

Elastic/Logstash 2020. 4. 16. 17:08

Elastic 공식 문서로는 아직 못본 것 같습니다.

기본 Docker 문서는 아래 문서를 참고 하시기 바랍니다.

 

[공식문서]

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

 

그러나 아예 예제가 없는 건 아닙니다.

Elastic 사의 github 에 들어가 보시면 참고 하실 수 있는 template 파일이 있습니다.

 

[github logstash-docker]

https://github.com/elastic/logstash-docker/tree/master/templates

 

위 템플릿 기반으로 logstash 만 설정해서 구성 하시면 쉽게 할 수 있습니다.

그 이외는 on premise 방식의 logstash 사용 방법과 크게 다른게 없습니다.

 

[실행방법]

$ docker-compose up -d

 

이와 같이 실행 하시면 background 로 자동 실행 됩니다.

 

[docker-compose.yml 예제]

version: '3.7'
services:
  logstash:
    image: docker.elastic.co/logstash/logstash:7.6.2
    volumes:
      - ./examples/logstash.conf/:/usr/share/logstash/pipeline/logstash.conf
    network_mode: bridge
:

[Elasticsearch] UTC 를 사용 하는 이유.

Elastic/Elasticsearch 2020. 4. 8. 12:28

분명히 어디선가 공식 문서 또는 글을 봤는데 찾지를 못하겠습니다.

 

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

https://discuss.elastic.co/t/elastic-utc-time/191877

 

discuss 에 보면 elastic team member 가 코멘트 한 내용이 있습니다.

Elasticsearch doesn't have a native concept of a "pure" date, only of instants in time. 
Given that, I think that it is reasonable to represent a pure date as the instant of 
midnight UTC on that date. 
If you use a different timezone then you will encounter problems as some "dates" 
will not be a whole number of days apart, because of occasions 
when the clocks go forwards or back for daylight savings.

Formatting a date as an instant without an explicit timezone is probably a bad idea, 
because something somewhere will have to guess what timezone to use 
and you may get inconsistent results if those guesses are inconsistent. 
Always specify the timezone, and in this case I recommend UTC as I mentioned above.

When you run an aggregation involving times, 
you can tell Elasticsearch what timezone to use 27. 
It defaults to UTC according to those docs.

I do not, however, know how to get Kibana to interpret 
these dates as you want in a visualisation. 
It's probably best to ask on the Kibana forum for help with that.

그리고 reference 문서에는 아래와 같은 내용이 있습니다.

Internally, dates are converted to UTC (if the time-zone is specified) 
and stored as a long number representing milliseconds-since-the-epoch.

그냥 Elastic Stack 은 기본적으로 @timestamp 값을 저장 시 UTC 0 를 기준으로 저장을 한다고 이해 하시고 질의 시점에 변환을 하거나 별도 localtime 에 맞는 custum timestamp field 를 추가해서 사용하는게 정신 건강에 좋다고 생각 하십시오.

 

추가적으로,

 

Date Query 관련 질의 시 

- "time_zone" 파라미터 설정은 now 값에 영향을 주지 않습니다.

참고 하세요.

:

[Kibana] Visualize Metric JSON Input 예제

Elastic/Kibana 2020. 4. 7. 20:11

kibana 에서 visualize 중 metric 을 구성 할 때 또는 다른 visualize 이더라도 비슷 합니다.

JSON Input 은 아래와 같이 넣으 실 수 있습니다.

{
  "script": {
    "inline": "doc['system.filesystem.free'].value / 1024 / 1024 /1024",
    "lang": "painless"
  }
}

좀 더 자세한 내용이 궁금 하신 분들은 아래 문서 한번 보시면 좋습니다.

 

공식문서)

https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting-fields.html

 

 

:

[Elasticsearch] Docker Compose 실행 시 permission denied

Elastic/Elasticsearch 2020. 4. 7. 15:54

docker compose 실행 시  permission denied 에러 경험을 하실 수 있습니다.

아래와 같은 방법으로 문제를 해결 할 수 있으니 환경에 맞게 적용 해 보면 좋을 것 같습니다.

 

docker-compose.yml)

    volumes:
      - /elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
      - /elasticsearch/data:/usr/share/elasticsearch/data:rw
      - /elasticsearch/logs:/usr/share/elasticsearch/logs:rw

 

Case 1)

$ chmod 777 /elasticsearch/data

$ chmod 777 /elasticsearch/logs

 

Case 2)

- docker-compose.yml 안에 uid, gid 를 설정

user: "1002:0" # uid 는 host user 로 설정, gid 는 container group 으로 설정

 

Elasticsearch 의 경우 docker 로 구성 하시면 Container 내부에서 1000:0 으로 실행 됩니다.

즉, uid 1000(elasticsearch), gid 0(root) 가 됩니다.

그래서 bind mount 의 경우 host 에서의 권한과 container 에서의 권한을 잘 맞춰 주셔야 합니다.

 

$ id -u username

$ id -g username

$ docker exec -it container-name /bin/bash

 

그럼 즐거운 Elastic 되세요.

:

[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.

 

: