'elasticsearch'에 해당되는 글 420건

  1. 2019.10.17 [Elasticsearch] 앱 내 사용자 행동로그 수집 파이프라인 구성
  2. 2019.10.17 [Elasticsearch] minimum_master_nodes is not working.
  3. 2019.10.02 [Elasticsearch] Elasticsearch Cluster Auto Scaling 구성 하기.
  4. 2019.09.09 [Elasticsearch] G1GC 설정 변경 사항.
  5. 2019.08.28 [Elasticsearch] Node Topology 7.x
  6. 2019.08.07 [Elasticsearch] elasticsearch-analysis-arirang 7.3.0 출시(?)
  7. 2019.07.11 [Elasticsearch] Shard reroute (6.x)
  8. 2019.01.15 [Elasticsearch] 문서 모델링 펼치기
  9. 2018.12.20 [Elasticsearch] 인증과 알람을 위한 오픈소스 도구들
  10. 2018.12.19 [Elasticsearch] Keyword 와 Text 필드 간단 비교 설명

[Elasticsearch] 앱 내 사용자 행동로그 수집 파이프라인 구성

Elastic/Elasticsearch 2019. 10. 17. 15:13

사용하고자 하는 Software Stack 은 다양하게 많이 있습니다.

일반적으로 아래 파이프라인으로 많이들 구성 합니다.

 

1. App -> Stream service -> Consumer -> Elasticsearch
2. App -> Stream service -> Producer -> Queue -> Consumer -> Elasticsearch
3. App -> Logging service (daemon, http, file ...) -> Consumer -> Elasticsearch
4. App -> Logging service (daemon, http, file ...) -> Producer -> Queue -> Consumer -> Elasticsearch

 

이걸 다시 Elastic Stack 으로 변환 하면

 

Producer 는)

- Filebeat

- Logstash

 

Queue 는)

- Logstash persistent queue

 

Consumer 는)

- Logstash

 

이 외에도 sqs, dynamodb, redis, kafka, fluentd, storm 등 활용 가능한 오픈소스들이 많이 준비되어 있습니다.

 

가장 쉽고 일반적인 구성이라고 보시면 될 것 같습니다.

:

[Elasticsearch] minimum_master_nodes is not working.

Elastic/Elasticsearch 2019. 10. 17. 14:56

7.x breaking changes 에 올라가 있는 내용입니다.

기억력을 돕는 차원에서 기록합니다.

 

The discovery.zen.minimum_master_nodes setting is permitted, but ignored, on 7.x nodes.

 

해당 설정은 더 이상 사용하지 맙시다.

그리고 이제 master node 는 2개로 구성해서는 더 이상 위험해서 못쓰겠내요.

 

참고문서)

https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking-changes-7.0.html#breaking_70_discovery_changes

 

Breaking changes in 7.0 | Elasticsearch Reference [7.4] | Elastic

Reindex indices from Elasticsearch 5.x or before Indices created in Elasticsearch 5.x or before will need to be reindexed with Elasticsearch 6.x in order to be readable by Elasticsearch 7.x.

www.elastic.co

 

:

[Elasticsearch] Elasticsearch Cluster Auto Scaling 구성 하기.

Elastic/Elasticsearch 2019. 10. 2. 16:04

기억하기 위해 작성해 봅니다.

 

ES Cluster 를 아래와 같이 구성 한다고 가정 하고 들어 가겠습니다.

 

1. Master Node 2개

2. Coordinating Node 2개

3. Data Node 2개

 

ES Cluster 를 구성 하다 보면 CPU, MEM, DISK, NETWORK 등 모든 자원을 다 효율적으로 사용하도록 구성 하기는 매우 어렵습니다.

그렇다 보니 CPU 는 부족한데 MEM 은 남는 다던가 MEM 은 부족한데 CPU 는 남는 다던가 또는 가끔 말도 안되게 NETWORK Bandwidth 가 부족 할 때도 나오더군요.

 

암튼 그래서 모든 자원을 다 쥐어 짜듯이 구성 할 수 없으니 적당히 포기 하시길 권장 드립니다.

 

여기서 Auto Scaling 하는 구성은 Coordinating Node 와 Data node 이 두 가지 입니다.

 

우선 ES 는 너무 쉽게 Node 를 추가 하고 삭제 할 수 있습니다.

elasticsearch.yml 파일 내 Master Node 정보만 등록 해 두시면 됩니다.

 

- discovery.zen.ping.unicast.hosts: MASTER_NODE_LIST

 

설정 공식 문서는 아래 링크 참고 하세요.

https://www.elastic.co/guide/en/elasticsearch/reference/6.2/modules-discovery-zen.html

 

Zen Discovery | Elasticsearch Reference [6.2] | Elastic

The zen discovery is the built in discovery module for Elasticsearch and the default. It provides unicast discovery, but can be extended to support cloud environments and other forms of discovery. The zen discovery is integrated with other modules, for exa

www.elastic.co

 

Coordinating Node Auto Scaling  구성 하기)

0. 가장 먼저 하셔야 하는 작업은 elasticsearch.yml 파일 내 Master Node 정보 등록 입니다.

1. 우선 Coordinating Node 들을 LoadBalancer 로 묶습니다. (AWS 를 사용 하시면 ALB/ELB 로 구성 하시면 됩니다.)

    - Coordinating Node 의 경우 "Too many requests" 오류가 발생 할 경우 이를 예방 하기 위해 Auto Scaling 구성을 하면 좋습니다.

    - 보통 트래픽이 몰릴 경우 search thread 가 부족 할 수 있기 때문 입니다.

    - LB 로 묶는 또 다른 이유는 API 단에서 단일 Endpoint 를 바라 보게 해서 운영을 편하게 하기 위함 입니다.

2. Auto Scaling 설정 구성을 합니다.

    - 이 부분은 사용하시는 환경에 맞춰서 구성 하시면 됩니다.

    - 공식 문서를 참고 하시면 됩니다.

    - https://docs.aws.amazon.com/ko_kr/autoscaling/ec2/userguide/scaling_plan.html#scaling_typesof

 

Auto Scaling 그룹의 크기 조정 - Amazon EC2 Auto Scaling

Auto Scaling 그룹의 크기 조정 조정은 애플리케이션의 컴퓨팅 용량을 늘리거나 줄이는 기능입니다. 조정은 이벤트와 함께 시작되거나 Auto Scaling 그룹에 Amazon EC2 인스턴스를 시작 또는 종료하도록 지시하는 조정 작업과 함께 시작됩니다. Amazon EC2 Auto Scaling에서는 여러 가지 방법으로 애플리케이션의 요구 사항에 가장 적합하게 조정 기능을 조절할 수 있습니다. 그러므로 애플리케이션을 충분히 이해하는 것이 중요합니다.

docs.aws.amazon.com

3. 테스트 해보시고 서비스에 적용 하시면 됩니다.

 

 

Data Node Auto Scaling 구성 하기) 

0. 가장 먼저 하셔야 하는 작업은 elasticsearch.yml 파일 내 Master Node 정보 등록 입니다.

0. 더불어 Replica Shard 설정은 (Data Node - 1) 만큼 구성이 되어야 합니다.

0. 더불어 초기 Data Node 수와 Primary Shard 크기를 잘 정의 하셔야 합니다.

0. 이유는 Primary Shard 는 한번 생성 하게 되면 ReIndexing 을 하지 않고서는 변경이 불가능 합니다.

1. Auto Scaling 설정 구성을 합니다.

    - 이 설정 시 Shard reallocation 에 대한 이슈는 없는지 꼭 확인을 하셔야 합니다.

    - CPU, DISk I/O, NETWORK 등에 대한 성능 저하가 발생 할 수 있습니다.

 

1. Auto Scaling 설정 후 수동으로 Shard Allocation 이 가능 합니다.

    - 보통 이런 문제는 트래픽이 몰리거나 운영 시점에 발생을 하기 때문에 미리 스크립트 구성해 놓으시고 re-location  진행 하시면 됩니다.

    - 그래서 Shard Allocation 설정을 꺼 두셔야 합니다.

    - 공식 문서를 참고 하시면 됩니다.

    - https://www.elastic.co/guide/en/elasticsearch/reference/current/shards-allocation.html

 

Cluster level shard allocation | Elasticsearch Reference [7.4] | Elastic

Regardless of the result of the balancing algorithm, rebalancing might not be allowed due to forced awareness or allocation filtering.

www.elastic.co

2. Data Node 의 경우 Auto Scaling 종료 정책에 따라 Primary Shard 가 유실 되지 않도록 구성 하는 것이 좋습니다.

    - 물론 Full Replicaiton 구성이라 다른 Replica 가 Primary Shard 로 선출 되겠지만 그래도 주의 하는게 좋겠죠.

 

마무리를 하면)

Coordinating Node 까지는 쉽게 적용이 가능 합니다.

하지만, Data Node 적용은 실제 운영 경험이 있고 문제 발생 시 신속하게 대응이 가능 하지 않다면 시도 하지 마시라고 말씀 드리고 싶습니다.

:

[Elasticsearch] G1GC 설정 변경 사항.

Elastic/Elasticsearch 2019. 9. 9. 15:11

7.4.1 이상 부터 적용 될 것 같습니다.

https://github.com/elastic/elasticsearch/pull/46169/commits/f4b587257ffd9c7f3d2eecc7096a100b72cb46d6

 

Fix G1 GC default IHOP by henningandersen · Pull Request #46169 · elastic/elasticsearch

G1 GC were setup to use an InitiatingHeapOccupancyPercent of 75. This could leave used memory at a very high level for an extended duration, triggering the real memory circuit breaker even at low a...

github.com

GIGC 를 사용하고 있기 때문에 기록해 봅니다.

:

[Elasticsearch] Node Topology 7.x

Elastic/Elasticsearch 2019. 8. 28. 10:54

사용성에서 정확한 정의가 없어서 많이들 헷갈려 하셨던 Node 가 정리가 된 것 같아 기록해 봅니다.

 

원문 링크)

https://www.elastic.co/guide/en/elasticsearch/reference/7.3/modules-node.html

 

Master Eligible Node

- node.master

마스터 노드는 전용으로 구성 하는 것을 추천 하며, 최소한의 작업을 수행 하도록 하는 것이 좋습니다.

 

Data Node

- node.data

CPU-, Memory-, I/O 성능 영향을 많이 받기 때문에 좋은 장비로 구성 하시길 추천 드립니다.

또한 Network 사용량에 대한 고려도 해야 합니다.

 

Ingest Node

- node.ingest

 

Machine Learning Node (x-pack)

- node.ml

 

Coordinating Node

node.master: false

node.data: false

node.ingest: false

node.ml: false

이 노드의 수를 너무 많이 늘리지 않도록 주의 하는게 좋습니다.

이유는 마스터 노드가 선출 되었을 때 모든 노드의 승인을 기다리게 되어 오히려 성능적으로 손해를 볼 수도 있습니다.

 

Voting Only Node (x-pack)

- node.voting_only

:

[Elasticsearch] elasticsearch-analysis-arirang 7.3.0 출시(?)

Elastic/Elasticsearch 2019. 8. 7. 10:26

Elasticsearch 7.3.0 출시가 되어 아리랑 플러그인도 버전을 올려봤습니다.

 

https://github.com/HowookJeong/elasticsearch-analysis-arirang/releases/tag/7.3.0

 

HowookJeong/elasticsearch-analysis-arirang

korean analyzer (lucene analyzer kr arirang). Contribute to HowookJeong/elasticsearch-analysis-arirang development by creating an account on GitHub.

github.com

 

설치 방법은 아래와 같습니다.

 

로컬 빌드 후 파일로 설치)

elasticsearch-7.3.0$ bin/elasticsearch-plugin install file:///git/elasticsearch-analysis-arirang/target/elasticsearch-analysis-arirang-7.3.0.zip

불러오는 중입니다...

 

github 에 올라간 release 파일로 설치)

elasticsearch-7.3.0$ bin/elasticsearch-plugin install https://github.com/HowookJeong/elasticsearch-analysis-arirang/releases/download/7.3.0/elasticsearch-analysis-arirang-7.3.0.zip

불러오는 중입니다...

 

:

[Elasticsearch] Shard reroute (6.x)

Elastic/Elasticsearch 2019. 7. 11. 13:29

공식문서)

https://www.elastic.co/guide/en/elasticsearch/reference/7.2/cluster-reroute.html

 

Cluster Reroute | Elasticsearch Reference [7.2] | Elastic

The reroute command allows for manual changes to the allocation of individual shards in the cluster. For example, a shard can be moved from one node to another explicitly, an allocation can be cancelled, and an unassigned shard can be explicitly allocated

www.elastic.co

 

6.x 와 7.x 간에 차이 없이 사용 하실 수 있습니다.

 

POST _cluster/reroute
{
  "commands": [
    {
      "allocate_replica": {
        "index": "actlog-2019-07-05",
        "shard": 0,
        "node": "노드명"
      }
    }
  ]
}

POST _cluster/reroute
{
  "commands": [
    {
      "move": {
        "index": "actlog-2018-12-27",
        "shard": 0,
        "from_node": "노드명1",
        "to_node": "노드명2"
      }
    }
  ]
}

공식 문서에 설명이 잘 나와 있어서 제가 특별히 설명을 하지 않아도 될 것 같습니다.

 

move)

started shard 에 대해서 가능 합니다.

 

allocate_replica)

unassigned replica shard 에 대해서 가능 합니다.

 

이번에 제가 사용하게 된 이유는 데이터 노드 3개 중에 하나의 노드의 disk 가 85% 를 넘어서 replica shard 가 unassigned 되는 문제가 발생을 했습니다.

그래서 수동으로 임시 조치 하기 위해 reroute 했고요.

근본적인 해결 방법은 disk 용량을 확보 하시는 것입니다. 또는 85% 가 넘지 않도록 rolling 하시면 됩니다.

:

[Elasticsearch] 문서 모델링 펼치기

Elastic/Elasticsearch 2019. 1. 15. 19:13

상품 모델링을 하다 보니 부득이 flat 하게 펼쳐야 하는 이슈가 생겼습니다.

field 수만 수천개 ㅡ.ㅡ;

사실 C사에 있을 때 봤던 field 수가 1만개 이상 되었던 걸로 기억 하는데 어쩔 수 없이 저도 다르지만 비슷한 구조를 만들게 되었내요.


[원문]

https://www.elastic.co/guide/en/elasticsearch/reference/master/mapping.html#mapping-limit-settings


Elasticsearch 에서 기본 제약 사항은 아래와 같습니다.


index.mapping.total_fields.limit

The maximum number of fields in an index. Field and object mappings, as well as field aliases count towards this limit. The default value is 1000.


index.mapping.depth.limit

The maximum depth for a field, which is measured as the number of inner objects. For instance, if all fields are defined at the root object level, then the depth is 1. If there is one object mapping, then the depth is 2, etc. The default is 20.


index.mapping.nested_fields.limit

The maximum number of nested fields in an index, defaults to 50. Indexing 1 document with 100 nested fields actually indexes 101 documents as each nested document is indexed as a separate hidden document.


index.mapping.nested_objects.limit

The maximum number of nested json objects within a single document across all nested fields, defaults to 10000. Indexing one document with an array of 100 objects within a nested field, will actually create 101 documents, as each nested object will be indexed as a separate hidden document.


혹시라도 문서 모델링 하시다가 field limit 에 대한 정보가 궁금 할 것 같아 일단 북마킹 합니다.

모델링을 flat 하게 펼치게 된 이유는 시간에 대한 다양한 요구사항이 발생을 하다 보니 부득이 이와 같이 펼치게 되었습니다.

:

[Elasticsearch] 인증과 알람을 위한 오픈소스 도구들

Elastic/Elasticsearch 2018. 12. 20. 09:31

다양한 방법이 있을 수 있지만, 아래 도구를 잘 활용하는 것도 방법 입니다. :)


- elastalert

  https://elastalert.readthedocs.io/en/latest/


- readonlyrest

  https://readonlyrest.com/free/


- search guard

  https://search-guard.com/



:

[Elasticsearch] Keyword 와 Text 필드 간단 비교 설명

Elastic/Elasticsearch 2018. 12. 19. 10:12

초 간단 비교)

- 둘 다 searchable 합니다.

- keyword 는 형태소 분석을 하지 않습니다. (not analyzed)

- text 는 형태소 분석을 합니다. (analyzed)


시작 하기에 앞서 먼저 공홈에서 제공하는 레퍼런스 부터 보시죠.


[Keyword]

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


[Text]

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


사실 위 문서만 자세히 읽어 보셔도 두 필드의 용도와 차이점이 어떻게 되는지는 쉽게 아실 수 있습니다.

다만, 사용하다 보면 놓치는 부분이 발생을 하는데 여기서는 제가 놓친 부분에 대해서 같은 실수를 하지 않기 위해 글로 남겨 보려 합니다.


keyword 는 기본적으로 exact value 입니다.

문서에서는 이렇게 표현 하고 있습니다.


They are typically used for filtering (Find me all blog posts where status is published), for sorting, and for aggregations. Keyword fields are only searchable by their exact value.


- filtering

- sorting

- aggregations

- searchable

- exact value


이 내용만 보시면 어떤 부분이 빠져 있다는 걸 알아채셔야 합니다.

결과적으로 말씀 드리면, 검색에 대한 내용만 있고 색인에 대한 내용은 빠져 있습니다.


색인에 대한 내용은 사실 문서의 

https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html#keyword-params

이 부분을 보시면 되긴 합니다.

하지만 이 내용을 보더라도 쉽게 놓칠 수 있는 부분이 있습니다.

바로 형태소 분석이 어떻게 이루어 지느냐 입니다.


기본 analyzer 설정을 하지 않으면 standard analyzer 로 지정이 됩니다.

이 analyzer 는 기본적으로 lowercase filter 적용이 되어 있습니다.

그럼 keyword field 의 value 는 모두 lowercase filter 적용이 되겠지요?


뭐 아시겠지만 lowercase filter 적용이 되지 않습니다.

parameter 설정을 찾아 보셔서 아시겠지만 analyzer 설정 하는 내용이 없습니다.

text 의 경우 per field analyzer 설정이 가능 합니다.

하지만 keyword 는 설정을 할 수가 없습니다.

이 말은 keyword field 의 value 는 입력 상태 그대로의 값이 저장 된다고 보시면 됩니다.

별도의 token filter 적용이 되지 않는 다는 것입니다.


[KeywordFieldMapper]

public static class Defaults {
public static final MappedFieldType FIELD_TYPE = new KeywordFieldType();

static {
FIELD_TYPE.setTokenized(false);
FIELD_TYPE.setOmitNorms(true);
FIELD_TYPE.setIndexOptions(IndexOptions.DOCS);
FIELD_TYPE.freeze();
}

public static final String NULL_VALUE = null;
public static final int IGNORE_ABOVE = Integer.MAX_VALUE;
}


여기서 그럼 이 야기를 왜 하는 것일까요?

한글은 대소문자 구분이 없어서 상관 없지만 영문자와 같은 경우 대소문자 구분이 된다는 이야기를 드리기 위해서 이렇게 서론이 길었습니다.



결론)

Keyword 필드의 Value 는 Token filter 적용이 되지 않습니다.

대소문자 구분에 주의 해서 사용 하셔야 합니다.



: