'elastic'에 해당되는 글 130건

  1. 2018.07.25 [Beats] 오랜만에 Filebeat 설치 1
  2. 2018.07.13 [Curator] 5.5 사용해 보기
  3. 2018.07.09 [Logstash] http output plugin - slack chat
  4. 2018.07.05 [Elasticsearch] Default field type 값.
  5. 2018.07.05 [Kibana] start and stop 스크립트
  6. 2018.06.28 [Elasticsearch] HighLevelRestClient 를 이용한 Bulk Indexing 로컬 테스트 결과
  7. 2018.06.27 [Elasticsearch] Move TransportClient to High Level REST Client
  8. 2018.06.27 [Elasticsearch] 6.3 설치 변경 내용
  9. 2018.04.17 [Elasticsearch] elasticsearch-docker 만들어 보기
  10. 2018.04.12 [Elasticsearch] WildcardQuery 알아보기

[Beats] 오랜만에 Filebeat 설치

Elastic/Beats 2018. 7. 25. 20:23

설치환경)

AWS EC2

Ubuntu


다운로드)

https://www.elastic.co/kr/downloads/beats/filebeat

https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.3.1-linux-x86_64.tar.gz


다운 받으시고 그냥 압축 해제 하시면 됩니다.


tree 는 그냥 제 맥북 기준으로 보여 드립니다.


filebeat-6.3.2-darwin-x86_64

├── LICENSE.txt

├── NOTICE.txt

├── README.md

├── fields.yml

├── filebeat

├── filebeat.reference.yml

├── filebeat.yml

├── kibana

│   ├── 5

│   │   ├── dashboard

│   │   │   ├── 0d3f2380-fa78-11e6-ae9b-81e5311e8cab.json

│   │   │   ├── 26309570-2419-11e7-a83b-d5f4cebac9ff.json

│   │   │   ├── 277876d0-fa2c-11e6-bbd3-29c986c96e5a.json

│   │   │   ├── 5517a150-f9ce-11e6-8115-a7c18106d86a.json

│   │   │   ├── 7fea2930-478e-11e7-b1f0-cb29bac6bf8b.json

│   │   │   ├── Filebeat-Apache2-Dashboard.json

│   │   │   ├── Filebeat-MySQL-Dashboard.json

│   │   │   ├── Filebeat-Nginx-Dashboard.json

│   │   │   ├── Filebeat-Traefik-Dashboard.json

│   │   │   ├── Filebeat-syslog-dashboard.json

│   │   │   ├── ML-Nginx-Access-Remote-IP-Count-Explorer.json

│   │   │   ├── ML-Nginx-Remote-IP-URL-Explorer.json

│   │   │   ├── ML-Traefik-Access-Remote-IP-Count-Explorer.json

│   │   │   ├── ML-Traefik-Remote-IP-URL-Explorer.json

│   │   │   ├── b9163ea0-2417-11e7-a83b-d5f4cebac9ff.json

│   │   │   ├── dfbb49f0-0a0f-11e7-8a62-2d05eaaac5cb.json

│   │   │   └── f693d260-2417-11e7-a83b-d5f4cebac9ff.json

│   │   ├── index-pattern

│   │   │   └── filebeat.json

│   │   ├── search

│   │   │   ├── 0ab87b80-478e-11e7-b1f0-cb29bac6bf8b.json

│   │   │   ├── 4ac0a370-0a11-11e7-8b04-eb22a5669f27.json

│   │   │   ├── 62439dc0-f9c9-11e6-a747-6121780e0414.json

│   │   │   ├── 710043e0-2417-11e7-a83b-d5f4cebac9ff.json

│   │   │   ├── 73613570-4791-11e7-be88-2ddb32f3df97.json

│   │   │   ├── 8030c1b0-fa77-11e6-ae9b-81e5311e8cab.json

│   │   │   ├── Apache2-access-logs.json

│   │   │   ├── Apache2-errors-log.json

│   │   │   ├── Filebeat-MySQL-Slow-log.json

│   │   │   ├── Filebeat-MySQL-error-log.json

│   │   │   ├── Filebeat-Nginx-module.json

│   │   │   ├── Filebeat-Traefik-module.json

│   │   │   ├── ML-Filebeat-Nginx-Access.json

│   │   │   ├── ML-Filebeat-Traefik-Access.json

│   │   │   ├── Syslog-system-logs.json

│   │   │   ├── b6f321e0-fa25-11e6-bbd3-29c986c96e5a.json

│   │   │   ├── c876e6a0-2418-11e7-a83b-d5f4cebac9ff.json

│   │   │   ├── eb0039f0-fa7f-11e6-a1df-a78bd7504d38.json

│   │   │   └── ffaf5a30-2413-11e7-a0d9-39604d45ca7f.json

│   │   └── visualization

│   │       ├── 0bc34b60-2419-11e7-a83b-d5f4cebac9ff.json

│   │       ├── 12667040-fa80-11e6-a1df-a78bd7504d38.json

│   │       ├── 2bb0fa70-0a11-11e7-9e84-43da493ad0c7.json

│   │       ├── 2cf77780-2418-11e7-a83b-d5f4cebac9ff.json

│   │       ├── 341ffe70-f9ce-11e6-8115-a7c18106d86a.json

│   │       ├── 346bb290-fa80-11e6-a1df-a78bd7504d38.json

│   │       ├── 3cec3eb0-f9d3-11e6-8a3e-2b904044ea1d.json

│   │       ├── 51164310-fa2b-11e6-bbd3-29c986c96e5a.json

│   │       ├── 5c7af030-fa2a-11e6-bbd3-29c986c96e5a.json

│   │       ├── 5dd15c00-fa78-11e6-ae9b-81e5311e8cab.json

│   │       ├── 5ebdbe50-0a0f-11e7-825f-6748cda7d858.json

│   │       ├── 6295bdd0-0a0e-11e7-825f-6748cda7d858.json

│   │       ├── 78b74f30-f9cd-11e6-8115-a7c18106d86a.json

│   │       ├── 78b9afe0-478f-11e7-b1f0-cb29bac6bf8b.json

│   │       ├── Apache2-access-unique-IPs-map.json

│   │       ├── Apache2-browsers.json

│   │       ├── Apache2-error-logs-over-time.json

│   │       ├── Apache2-operating-systems.json

│   │       ├── Apache2-response-codes-of-top-URLs.json

│   │       ├── Apache2-response-codes-over-time.json

│   │       ├── Errors-over-time.json

│   │       ├── ML-Nginx-Access-Map.json

│   │       ├── ML-Nginx-Access-Remote-IP-Timechart.json

│   │       ├── ML-Nginx-Access-Response-Code-Timechart.json

│   │       ├── ML-Nginx-Access-Top-Remote-IPs-Table.json

│   │       ├── ML-Nginx-Access-Top-URLs-Table.json

│   │       ├── ML-Nginx-Access-Unique-Count-URL-Timechart.json

│   │       ├── ML-Traefik-Access-Map.json

│   │       ├── ML-Traefik-Access-Remote-IP-Timechart.json

│   │       ├── ML-Traefik-Access-Response-Code-Timechart.json

│   │       ├── ML-Traefik-Access-Top-Remote-IPs-Table.json

│   │       ├── ML-Traefik-Access-Top-URLs-Table.json

│   │       ├── ML-Traefik-Access-Unique-Count-URL-Timechart.json

│   │       ├── MySQL-Error-logs-levels.json

│   │       ├── MySQL-Slow-logs-by-count.json

│   │       ├── MySQL-Slow-queries-over-time.json

│   │       ├── MySQL-error-logs.json

│   │       ├── MySQL-slowest-queries.json

│   │       ├── New-Visualization.json

│   │       ├── Nginx-Access-Browsers.json

│   │       ├── Nginx-Access-Map.json

│   │       ├── Nginx-Access-OSes.json

│   │       ├── Nginx-Access-Response-codes-by-top-URLs.json

│   │       ├── Sent-sizes.json

│   │       ├── Syslog-events-by-hostname.json

│   │       ├── Syslog-hostnames-and-processes.json

│   │       ├── Traefik-Access-Browsers.json

│   │       ├── Traefik-Access-Map.json

│   │       ├── Traefik-Access-OSes.json

│   │       ├── Traefik-Access-Response-codes-by-top-URLs.json

│   │       ├── a59b5e00-2417-11e7-a83b-d5f4cebac9ff.json

│   │       ├── c5411910-0a87-11e7-8b04-eb22a5669f27.json

│   │       ├── d16bb400-f9cc-11e6-8115-a7c18106d86a.json

│   │       ├── d1726930-0a7f-11e7-8b04-eb22a5669f27.json

│   │       ├── d2864600-478f-11e7-be88-2ddb32f3df97.json

│   │       ├── d56ee420-fa79-11e6-a1df-a78bd7504d38.json

│   │       ├── d8e5dc40-2417-11e7-a83b-d5f4cebac9ff.json

│   │       ├── dc589770-fa2b-11e6-bbd3-29c986c96e5a.json

│   │       ├── dcccaa80-4791-11e7-be88-2ddb32f3df97.json

│   │       ├── e121b140-fa78-11e6-a1df-a78bd7504d38.json

│   │       ├── f398d2f0-fa77-11e6-ae9b-81e5311e8cab.json

│   │       └── fb09d4b0-2418-11e7-a83b-d5f4cebac9ff.json

│   └── 6

│       ├── dashboard

│       │   ├── Filebeat-Kafka-overview.json

│       │   ├── Filebeat-Mongodb-overview.json

│       │   ├── Filebeat-Postgresql-overview.json

│       │   ├── Filebeat-Postgresql-slowlogs.json

│       │   ├── Filebeat-apache2.json

│       │   ├── Filebeat-auditd.json

│       │   ├── Filebeat-auth-sudo-commands.json

│       │   ├── Filebeat-icinga-debug-log.json

│       │   ├── Filebeat-icinga-main-log.json

│       │   ├── Filebeat-icinga-startup-errors.json

│       │   ├── Filebeat-iis.json

│       │   ├── Filebeat-logstash-log.json

│       │   ├── Filebeat-logstash-slowlog.json

│       │   ├── Filebeat-mysql.json

│       │   ├── Filebeat-new-users-and-groups.json

│       │   ├── Filebeat-nginx-logs.json

│       │   ├── Filebeat-nginx-overview.json

│       │   ├── Filebeat-redis.json

│       │   ├── Filebeat-ssh-login-attempts.json

│       │   ├── Filebeat-syslog.json

│       │   ├── Filebeat-traefik-overview.json

│       │   ├── ml-nginx-access-remote-ip-count-explorer.json

│       │   ├── ml-nginx-remote-ip-url-explorer.json

│       │   ├── ml-traefik-access-remote-ip-count-explorer.json

│       │   ├── ml-traefik-remote-ip-url-explorer.json

│       │   ├── osquery-compliance.json

│       │   └── osquery-rootkit.json

│       └── index-pattern

│           └── filebeat.json

├── module

│   ├── apache2

│   │   ├── access

│   │   │   ├── config

│   │   │   │   └── access.yml

│   │   │   ├── ingest

│   │   │   │   └── default.json

│   │   │   └── manifest.yml

│   │   ├── error

│   │   │   ├── config

│   │   │   │   └── error.yml

│   │   │   ├── ingest

│   │   │   │   └── pipeline.json

│   │   │   └── manifest.yml

│   │   └── module.yml

│   ├── auditd

│   │   ├── log

│   │   │   ├── config

│   │   │   │   └── log.yml

│   │   │   ├── ingest

│   │   │   │   └── pipeline.json

│   │   │   └── manifest.yml

│   │   └── module.yml

│   ├── icinga

│   │   ├── debug

│   │   │   ├── config

│   │   │   │   └── debug.yml

│   │   │   ├── ingest

│   │   │   │   └── pipeline.json

│   │   │   └── manifest.yml

│   │   ├── main

│   │   │   ├── config

│   │   │   │   └── main.yml

│   │   │   ├── ingest

│   │   │   │   └── pipeline.json

│   │   │   └── manifest.yml

│   │   ├── module.yml

│   │   └── startup

│   │       ├── config

│   │       │   └── startup.yml

│   │       ├── ingest

│   │       │   └── pipeline.json

│   │       └── manifest.yml

│   ├── iis

│   │   ├── access

│   │   │   ├── config

│   │   │   │   └── iis-access.yml

│   │   │   ├── ingest

│   │   │   │   └── default.json

│   │   │   └── manifest.yml

│   │   └── error

│   │       ├── config

│   │       │   └── iis-error.yml

│   │       ├── ingest

│   │       │   └── default.json

│   │       └── manifest.yml

│   ├── kafka

│   │   ├── log

│   │   │   ├── config

│   │   │   │   └── log.yml

│   │   │   ├── ingest

│   │   │   │   └── pipeline.json

│   │   │   └── manifest.yml

│   │   └── module.yml

│   ├── logstash

│   │   ├── log

│   │   │   ├── config

│   │   │   │   └── log.yml

│   │   │   ├── ingest

│   │   │   │   ├── pipeline-json.json

│   │   │   │   └── pipeline-plain.json

│   │   │   └── manifest.yml

│   │   ├── module.yml

│   │   └── slowlog

│   │       ├── config

│   │       │   └── slowlog.yml

│   │       ├── ingest

│   │       │   ├── pipeline-json.json

│   │       │   └── pipeline-plain.json

│   │       └── manifest.yml

│   ├── mongodb

│   │   ├── log

│   │   │   ├── config

│   │   │   │   └── log.yml

│   │   │   ├── ingest

│   │   │   │   └── pipeline.json

│   │   │   └── manifest.yml

│   │   └── module.yml

│   ├── mysql

│   │   ├── error

│   │   │   ├── config

│   │   │   │   └── error.yml

│   │   │   ├── ingest

│   │   │   │   └── pipeline.json

│   │   │   └── manifest.yml

│   │   ├── module.yml

│   │   └── slowlog

│   │       ├── config

│   │       │   └── slowlog.yml

│   │       ├── ingest

│   │       │   └── pipeline.json

│   │       └── manifest.yml

│   ├── nginx

│   │   ├── access

│   │   │   ├── config

│   │   │   │   └── nginx-access.yml

│   │   │   ├── ingest

│   │   │   │   └── default.json

│   │   │   ├── machine_learning

│   │   │   │   ├── datafeed_low_request_rate.json

│   │   │   │   ├── datafeed_remote_ip_request_rate.json

│   │   │   │   ├── datafeed_remote_ip_url_count.json

│   │   │   │   ├── datafeed_response_code.json

│   │   │   │   ├── datafeed_visitor_rate.json

│   │   │   │   ├── low_request_rate.json

│   │   │   │   ├── remote_ip_request_rate.json

│   │   │   │   ├── remote_ip_url_count.json

│   │   │   │   ├── response_code.json

│   │   │   │   └── visitor_rate.json

│   │   │   └── manifest.yml

│   │   ├── error

│   │   │   ├── config

│   │   │   │   └── nginx-error.yml

│   │   │   ├── ingest

│   │   │   │   └── pipeline.json

│   │   │   └── manifest.yml

│   │   └── module.yml

│   ├── osquery

│   │   ├── module.yml

│   │   └── result

│   │       ├── config

│   │       │   └── result.yml

│   │       ├── ingest

│   │       │   └── pipeline.json

│   │       └── manifest.yml

│   ├── postgresql

│   │   ├── log

│   │   │   ├── config

│   │   │   │   └── log.yml

│   │   │   ├── ingest

│   │   │   │   └── pipeline.json

│   │   │   └── manifest.yml

│   │   └── module.yml

│   ├── redis

│   │   ├── log

│   │   │   ├── config

│   │   │   │   └── log.yml

│   │   │   ├── ingest

│   │   │   │   └── pipeline.json

│   │   │   └── manifest.yml

│   │   ├── module.yml

│   │   └── slowlog

│   │       ├── config

│   │       │   └── slowlog.yml

│   │       ├── ingest

│   │       │   └── pipeline.json

│   │       └── manifest.yml

│   ├── system

│   │   ├── auth

│   │   │   ├── config

│   │   │   │   └── auth.yml

│   │   │   ├── ingest

│   │   │   │   └── pipeline.json

│   │   │   └── manifest.yml

│   │   ├── module.yml

│   │   └── syslog

│   │       ├── config

│   │       │   └── syslog.yml

│   │       ├── ingest

│   │       │   └── pipeline.json

│   │       └── manifest.yml

│   └── traefik

│       ├── access

│       │   ├── config

│       │   │   └── traefik-access.yml

│       │   ├── ingest

│       │   │   └── pipeline.json

│       │   ├── machine_learning

│       │   │   ├── datafeed_low_request_rate.json

│       │   │   ├── datafeed_remote_ip_request_rate.json

│       │   │   ├── datafeed_remote_ip_url_count.json

│       │   │   ├── datafeed_response_code.json

│       │   │   ├── datafeed_visitor_rate.json

│       │   │   ├── low_request_rate.json

│       │   │   ├── remote_ip_request_rate.json

│       │   │   ├── remote_ip_url_count.json

│       │   │   ├── response_code.json

│       │   │   └── visitor_rate.json

│       │   ├── manifest.yml

│       │   └── tests

│       │       ├── test.log

│       │       └── test.log-expected.json

│       └── module.yml

└── modules.d

    ├── apache2.yml.disabled

    ├── auditd.yml.disabled

    ├── icinga.yml.disabled

    ├── iis.yml.disabled

    ├── kafka.yml.disabled

    ├── logstash.yml.disabled

    ├── mongodb.yml.disabled

    ├── mysql.yml.disabled

    ├── nginx.yml.disabled

    ├── osquery.yml.disabled

    ├── postgresql.yml.disabled

    ├── redis.yml.disabled

    ├── system.yml.disabled

    └── traefik.yml.disabled


97 directories, 254 files


도움말)

Usage:

  filebeat [flags]

  filebeat [command]


Available Commands:

  export      Export current config or index template

  help        Help about any command

  keystore    Manage secrets keystore

  modules     Manage configured modules

  run         Run filebeat

  setup       Setup index template, dashboards and ML jobs

  test        Test config

  version     Show current version info


Flags:

  -E, --E setting=value      Configuration overwrite

  -M, --M setting=value      Module configuration overwrite

  -N, --N                    Disable actual publishing for testing

  -c, --c string             Configuration file, relative to path.config (default "filebeat.yml")

      --cpuprofile string    Write cpu profile to file

  -d, --d string             Enable certain debug selectors

  -e, --e                    Log to stderr and disable syslog/file output

  -h, --help                 help for filebeat

      --httpprof string      Start pprof http server

      --memprofile string    Write memory profile to this file

      --modules string       List of enabled modules (comma separated)

      --once                 Run filebeat only once until all harvesters reach EOF

      --path.config string   Configuration path

      --path.data string     Data path

      --path.home string     Home path

      --path.logs string     Logs path

      --setup                Load sample Kibana dashboards and setup Machine Learning

      --strict.perms         Strict permission checking on config files (default true)

  -v, --v                    Log at INFO level


Use "filebeat [command] --help" for more information about a command.


filebeat.yml 예제)

filebeat:

  prospectors:

    -

      paths:

        - /mnt/apps/apache-tomcat/logs/catalina.out

      encoding: utf-8

      input_type: log


      exclude_lines: ['DEBUG', 'INFO']

      include_lines: ['(E|e)rror', 'ERROR', '(E|e)xception', 'EXCEPTION']


      document_type: error-log


      ignore_older: 5m


      scan_frequency: 10s


      multiline:

        pattern: '^[[:space:]]+|^Caused by:'

        negate: false

        match: after

        max_lines: 10

        timeout: 5s


      tail_files: true


      backoff: 1s

      max_backoff: 10s

      backoff_factor: 2


  registry_file: /mnt/config/filebeat/.filebeat-tomcat


output:

  logstash:

    hosts: ["localhost:5044"]


shipper:


logging:

  to_syslog: false

  to_files: true


  level: warning


  files:

    path: /mnt/logs/filebeat

    name: filebeat-tomcat.log

    rotateeverybytes: 10485760 # = 10MB


logstash 예제)

input {

  beats {

    port => 5044

  }

}


output {

  stdout { codec => rubydebug }


  http {

    url => "https://slack.com/api/chat.postMessage"

    content_type => "application/json"

    http_method => "post"

    format => "json"

    mapping => [ "channel", "slack-bot", "text", "%{message}" ]

    headers => ["Authorization", "Bearer xoxb-XXXXXXXXXXXXXXXXXXXXX"]

  }

#  elasticsearch {

#    host => "localhost"

#    port => "9200"

#    protocol => "http"

#    index => "%{[@metadata][index]}"

#    document_type => "%{[@metadata][type]}"

#  }

}


위 예제는 그냥 filebeat 이 log file 을 리스닝 하고 있다가 error 또는 exception 발생 시 바로 slack 으로 해당 에러는 보내주는 예제 입니다.

:

[Curator] 5.5 사용해 보기

Elastic/Curator 2018. 7. 13. 19:34

오랜만에 사용해 보려고 했더니 또 기억이나질 않아서 기록해 봅니다.


공식문서)

https://www.elastic.co/guide/en/elasticsearch/client/curator/5.5/index.html


설치)

https://www.elastic.co/guide/en/elasticsearch/client/curator/5.5/pip.html


설치 방법이 예전이랑 좀 달라진게 있더군요.

저는 아래 방법으로 설치 했습니다.


$ pip install --user elasticsearch-curator


실행)

https://www.elastic.co/guide/en/elasticsearch/client/curator/5.5/command-line.html

https://www.elastic.co/guide/en/elasticsearch/client/curator/5.5/singleton-cli.html


$ curator [--config CONFIG.YML] [--dry-run] ACTION_FILE.YML 


이 방식으로 이전 3.x 버전에서는 command 를 주고 사용했었으나 4.2 버전 이후 부터는 Singleton command line interface 를 사용해야 합니다. 


- prefix 방식

$ curator_cli --host localhost --port 9200 show_indices --filter_list '{"filtertype":"pattern", "kind":"prefix", "value":"search-"}'


- regex 방식

$ curator_cli --host localhost --port 9200 show_indices --filter_list '{"filtertype":"pattern", "kind":"regex", "value":"^(search-).*$"}'


예제)

https://www.elastic.co/guide/en/elasticsearch/client/curator/5.5/examples.html


더 많은 예제는 위 문서에서 찾아 보시면서 해보시면 될 것 같습니다.


:

[Logstash] http output plugin - slack chat

Elastic/Logstash 2018. 7. 9. 12:19


예전에는 output slack_chat 이라고 플러그인을 만들어서 사용을 했었는데 logstash output http 가 있어서 그냥 이걸로 바로 사용하겠습니다.


공식문서에 잘못된 정보가 있기 때문에 그대로 보고 따라 하시면 시간을 낭비 하실 수 있습니다.

(6.3.0 에서 테스트 되었습니다.)


Reference)

https://www.elastic.co/guide/en/logstash/current/plugins-outputs-http.html


input {

stdin {}

}


output {

stdout { codec => rubydebug }

http {

url => "https://slack.com/api/chat.postMessage"

content_type => "application/json"

http_method => "post"

format => "json"

mapping => [ "channel", "CXXXXXXXXX", "text", "%{message}" ]

headers => ["Authorization", "Bearer xoxb-xxxxxxxxxxx"]

}

}


문서 내 잘못된 정보)

https://www.elastic.co/guide/en/logstash/current/plugins-outputs-http.html#plugins-outputs-http-mapping


mapping 이 hash 로 되어 있는데 실제 나와 있는 예제로는 동작 하지 않습니다.


잘못된 예)

   mapping => {"foo" => "%{host}"
              "bar" => "%{type}"}


바른 예)

mapping => [ "channel", "CXXXXXXXXX", "text", "%{message}" ]



:

[Elasticsearch] Default field type 값.

Elastic/Elasticsearch 2018. 7. 5. 11:04

elasticsearch 문서 모델링 하면서 잘 알고 있다고 생각 하지만 늘 그렇듯 잘 잊어버립니다.

그래서 올려 봅니다. (어딘가에 글 올려 놓은게 있긴 할테지만.. )



우선, FieldMapper 클래스를 확인 합니다.

여기서 보면 MappedFieldType 클래스로 넘어 가게 됩니다.


그래서 default field type 은 아래와 같습니다.


public MappedFieldType() {
setTokenized(true);
setStored(false);
setStoreTermVectors(false);
setOmitNorms(false);
setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
setBoost(1.0f);
}


:

[Kibana] start and stop 스크립트

Elastic/Kibana 2018. 7. 5. 09:52

Kibana 실행 스크립트.

$ bin/kibana 귀찮아서 그냥 es 에서 쓰던거 복붙.


[start.sh]


#!/bin/bash


DIR_NAME=`dirname "$0"`

DIR_HOME=`cd $DIR_NAME; cd ..; pwd`


$DIR_HOME/bin/kibana> /dev/null 2>&1 & KIBANA_PID=$!

echo $KIBANA_PID > $DIR_HOME/bin/kibana.pid



[stop.sh]


#!/bin/bash


DIR_NAME=`dirname "$0"`

DIR_HOME=`cd $DIR_NAME; cd ..; pwd`


KIBANA_PID=`cat $DIR_HOME/bin/kibana.pid`

kill -9 $KIBANA_PID

echo "Kibana Daemon($KIBANA_PID) is killed"

rm -f $DIR_HOME/bin/kibana.pid


:

[Elasticsearch] HighLevelRestClient 를 이용한 Bulk Indexing 로컬 테스트 결과

Elastic/Elasticsearch 2018. 6. 28. 11:35


arirang plug 을 적용해서 돌려본 실행 속도 입니다.


[DEBUG] 2018-07-02 13:12:18.407 [main] MainIndexer - Bulk operation elapsed time [811.0869750976562] sec

[DEBUG] 2018-07-02 13:14:16.595 [main] MainIndexer - Force merge operation elapsed time [118.18800354003906] sec


[Settings]

"settings":{
"number_of_shards":1,
"number_of_replicas":0,
"index.refresh_interval":"1h",
"index.routing.allocation.require.box_type":"indexing",
"index.similarity.default.type":"BM25",
"index":{
"analysis":{
"analyzer":{
"arirang_custom_analyzer":{
"tokenizer":"arirang_tokenizer",
"filter":[
"lowercase",
"trim",
"custom_synonym",
"arirang_filter"
]
}
},
"filter":{
"custom_synonym":{
"type":"synonym_graph",
"synonyms":[]
}
}
}
}
}


[Mappings]

"mappings" : {
"_doc": {
"_source": {
"enabled": true
},
"dynamic_templates": [
{
"strings": {
"match_mapping_type": "string",
"mapping": {
"type": "text",
"analyzer": "arirang_custom_analyzer",
"fields": {
"raw": {
"type": "keyword",
"ignore_above": 50
}
}
}
}
}
]
}
}





얼마전 밋업에서 김종민님이 공유해 주신 위키피디아 문서를 가지고 테스트한 결과 입니다.

그냥 제가 만든 Indexer 모듈에 대한 성능 테스트용도로 한번 실험 삼아 돌려 본거라 별 도움이 안될 수 있습니다.


아래 문서는 언제까지 올라가 있을지 모르겠습니다.

빨리 받으시면 될 듯 하내요.


문서 다운로드 링크)

https://s3.ap-northeast-2.amazonaws.com/kr.elastic.co/sample-data/kr-wikipedia-dump.json.tar.gz


위키피디아 문서 색인 테스트 결과)

MacBook Pro

CPU 2.8G i7

MEM 16GB

API : HighLevelRestClient

REST API : _bulk

Settings

primary shard : 1

replica shard : 0

refresh_interval : 1h

similarity : BM25

default analyzer (standard)

Mappings

dynamic mapping

Indexing File Source Size 

3.6GB

Indexing Segment File Size (force merge 전)

11 GB

Indexing Segment File Size (force merge 후)

4.28 GB

Bulk Request Thread Size

5

Bulk Request Document Size (per thread)

500

Bulk Indexing / Force Merge Time

[DEBUG] 2018-06-28 11:06:13.780 [main] MainIndexer - Bulk operation elapsed time [366.6780090332031] sec

[DEBUG] 2018-06-28 11:08:22.254 [main] MainIndexer - Force merge operation elapsed time [128.47300720214844] sec

Indexing Documents

Total indexed document are 1020662


결과적으로 튜닝한 내용은 전혀 없고 그냥 색인기 기능 테스트 정도로 보셔도 될 것 같습니다.


:

[Elasticsearch] Move TransportClient to High Level REST Client

Elastic/Elasticsearch 2018. 6. 27. 11:46

이번에 새로 Indexer 모듈을 만들다 보니 아래 문서의 내용을 확인하게 되었습니다.


Reference)

https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/client.html

https://github.com/elastic/elasticsearch/tree/master/client/rest/src/test/java/org/elasticsearch/client


원문발췌)

We plan on deprecating the TransportClient in Elasticsearch 7.0 and removing it completely in 8.0. Instead, you should be using the Java High Level REST Client, which executes HTTP requests rather than serialized Java requests. The migration guidedescribes all the steps needed to migrate.

The Java High Level REST Client currently has support for the more commonly used APIs, but there are a lot more that still need to be added. You can help us prioritise by telling us which missing APIs you need for your application by adding a comment to this issue: Java high-level REST client completeness.

Any missing APIs can always be implemented today by using the low level Java REST Client with JSON request and response bodies.


사실 저도 TransportClient 를 사용하면 version 때문에 고민을 하긴했었는데요.

이 참에 그냥 REST Client 로 넘어 가야 겠다고 생각해서 새로 작성 하였습니다.


기본적인 예제 코드는 아래 내용 참고 하시면 됩니다.


public static void main(String[] args) {
requestRestClient();
}

public static void requestRestClient() {
int numNodes = 5; //randomIntBetween(1, 5);
HttpHost[] hosts = new HttpHost[numNodes];
for (int i = 0; i < numNodes; i++) {
hosts[i] = new HttpHost("localhost", 9200);
}
RestClientBuilder builder = RestClient.builder(hosts);
RestClient restClient = builder.build();

builder.setMaxRetryTimeoutMillis(10000);

builder.setFailureListener(new RestClient.FailureListener() {
@Override
public void onFailure(HttpHost host) {
System.out.println("onFailure");
}
});

builder.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
@Override
public RequestConfig.Builder customizeRequestConfig(
RequestConfig.Builder requestConfigBuilder) {
return requestConfigBuilder.setSocketTimeout(10000);
}
});

Map<String, String> params = new HashMap<>();
params.put("preference", "_shards:0,1,2,3");

HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory consumerFactory =
new HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory(
30 * 1024 * 1024);
try {
Response response = restClient
.performRequest("GET", "/hello/_search", params, null, consumerFactory);

System.out.println(response.toString());

// Read Case 1
RequestLine requestLine = response.getRequestLine();
HttpHost host = response.getHost();
int statusCode = response.getStatusLine().getStatusCode();
Header[] headers = response.getHeaders();
String responseBody = EntityUtils.toString(response.getEntity());

System.out.println(requestLine);
System.out.println(host);
System.out.println(statusCode);
System.out.println(headers);
System.out.println(responseBody);

// Read Case 2 - old fashion
BufferedReader reader = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));

String inputLine;
StringBuffer buffer = new StringBuffer();

while ((inputLine = reader.readLine()) != null) {
buffer.append(inputLine);
}

reader.close();

// System.out.println(buffer.toString());
} catch (IOException e) {
e.printStackTrace();
}

try {
restClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}

public static int randomIntBetween(int min, int max) {
return RandomNumbers.randomIntBetween(random(), min, max);
}

public static Random random() {
return RandomizedContext.current().getRandom();
}




:

[Elasticsearch] 6.3 설치 변경 내용

Elastic/Elasticsearch 2018. 6. 27. 07:54

Elasticsearch 6.3 이 릴리즈 되면서 가장 큰 변화는 Elastic 용과 OSS 용 이렇게 두개로 설치 패키지가 나뉜것입니다.

즉, Elastic 사의 license 를 기반으로 동작하는 x-pack 들을 사용하기 위해서는 Elastic 버전을 설치 하셔야 한다는 이야기 입니다.


Basic  라이센스의 경우 free 이기 때문에 OSS 버전을 설치 하고 사용할 수 있겠다 생각 하시면 안되는 걸 경험 하실 수 있습니다. (제가 그랬습니다 ^^;)


전에는 x-pack 을 elasticsearch-plugin 으로 설치가 가능 했지만 6.3 에서는 지원을 하고 있지 않습니다.

또한 x-pack 을 쓰기 위해서는 default system index 생성이 필요 한데 아래 설정이 되어 있으면 오류가 발생을 하게 됩니다.


action.auto_create_index: false


이 설정은 잘 아시겠지만 index 가 없을 때 자동으로 생성을 하게 해주는 설정인데요.

저는 보안이랑 관리적인 부분에서 disable 하고 사용했었는데 basic 버전을 사용하기 위해서 이 설정을 과감히 포기 했습니다.


몇 가지 removed 된 설정들이 있는데요.

5.x 올라 오면서 변경된 내용과 일부 비슷한 것들이 있어서 링크 겁니다.


[Elasticsearch] 2.4.x to 5.2.x 으로의 elasticsearch.yml

그리고 Elastic 에서 제공하는 Breaking Changes 를 보시는 것도 도움이 됩니다.



정리하면)

1. x-pack 버전과 oss 버전이 있으니 용도와 목적에 맞게 설치 하시면 됩니다.

- basic license 를 사용하기 위해서는 x-pack  버전을 사용하셔야 합니다.


2. x-pack 버전 사용 시 action.auto_create_index: true 로 설정 하셔야 합니다.

- default system index 를 생성 해야 하기 때문입니다.


:

[Elasticsearch] elasticsearch-docker 만들어 보기

Elastic/Elasticsearch 2018. 4. 17. 18:14

이미 Elastic 사에서 docker 를 제공하고 있습니다.

정보는 아래 링크를 참고하세요.


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

https://github.com/elastic/elasticsearch-docker

https://docs.docker.com/get-started/


Docker 를 이용해서 이미지를 만들어 보고 실행 및 클러스터 구성을 어떻게 하는지 단계 별 실행 코드를 따라 하면서 배워 보도록 하겠습니다.

그냥 따라만 하시면 될 겁니다. (Maybe)


제 개발 환경은 mac 입니다.

- docker 당연히 설치가 되어 있어야 합니다.

그 이외는 음... 그냥 개발자시면 쉽게 하실 수 있을 실거예요. ^^


Step 1) 이미지를 만들기 위한 repo 를 하나 만듭니다.

$ mkdir elasticsearch-docker

$ cd elasticsearch-docker


Step 2) 이미지에 패키징 할 패키지들을 준비해 둡니다.

$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.3.tar.gz

$ download jdk-8u152-linux-x64.tar.gz


Step 3) 혹시 커스텀 설정을 하실 거라면 만들어 보세요.

$ mkdir config

$ touch elasticsearch.yml

$ touch jvm.options

$ touch log4j2.properties


# elasticsearch default config 파일로 구성을 합니다.

# 또는 변경이 필요할 경우 작성을 합니다.


Step 4) 이미지 생성을 위한 도커 파일을 만듭니다.

$ vi Dockerfile

From ubuntu:14.04

MAINTAINER HENRY JEONG sophistlv@gmail.com


ARG arg_user_home

ARG arg_es_version


ENV PATH $arg_user_home/apps/elasticsearch/bin:$arg_user_home/apps/jdk/bin:$PATH

ENV ES_HOME $arg_user_home/apps/elasticsearch

ENV JAVA_HOME $arg_user_home/apps/jdk


RUN groupadd -g 1000 elasticsearch && useradd elasticsearch -u 1000 -g 1000 -m -b $arg_user_home -d $arg_user_home -s /bin/bash

USER 1000


# 기본 디렉토리를 생성 합니다.

WORKDIR $arg_user_home

RUN mkdir apps


# 현재 작업 디렉토리를 선언 합니다.

WORKDIR $arg_user_home/apps


# 아래와 같이 다운로드를 받거나 이미 받아 놓은 파일을 추가 합니다.

#RUN wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-$arg_es_version.tar.gz

COPY elasticsearch-$arg_es_version.tar.gz .

COPY jdk-8u152-linux-x64.tar.gz .


# 압축을 해제 합니다.(자동으로 해제 됩니다.)

RUN tar -xvzf elasticsearch-$arg_es_version.tar.gz

RUN tar -xvzf jdk-8u152-linux-x64.tar.gz

RUN rm -f elasticsearch-$arg_es_version.tar.gz

RUN rm -f jdk-8u152-linux-x64.tar.gz


# 설정 파일을 추가 합니다.

COPY config/elasticsearch.yml elasticsearch-$arg_es_version/config/

COPY config/jvm.options elasticsearch-$arg_es_version/config/

COPY config/log4j2.properties elasticsearch-$arg_es_version/config/


# symlink 를 설정 합니다.

RUN ln -s elasticsearch-$arg_es_version elasticsearch

RUN ln -s jdk1.8.0_152 jdk


# WORKDIR 을 변경 합니다.

WORKDIR elasticsearch-$arg_es_version

RUN set -ex && for path in data logs config/scripts; do \

        mkdir -p "$path"; \

        chown -R elasticsearch:elasticsearch "$path"; \

    done


# 데몬을 실행 합니다.

#CMD bin/elasticsearch


EXPOSE 9200 9201 9300 9301


Step 5) 이미지를 생성 합니다.

$ docker build -t elasticsearch-6.2.3-ubuntu-14.04-jdk8u152 . --build-arg arg_user_home=/home/es --build-arg arg_es_version=6.2.3

Sending build context to Docker daemon  218.9MB

Step 1/26 : From ubuntu:14.04

---> 67759a80360c

Step 2/26 : MAINTAINER HENRY JEONG sophistlv@gmail.com

---> Using cache

---> be0de8404ce2

Step 3/26 : ARG arg_user_home

---> Using cache

---> 9cad1b4a18c5

Step 4/26 : ARG arg_es_version

---> Using cache

---> 693e1b4ae411

Step 5/26 : ENV PATH $arg_user_home/apps/elasticsearch/bin:$arg_user_home/apps/jdk/bin:$PATH

---> Using cache

---> 5a249008ab07

Step 6/26 : ENV ES_HOME $arg_user_home/apps/elasticsearch

---> Using cache

---> 095bc65a6dfb

Step 7/26 : ENV JAVA_HOME $arg_user_home/apps/jdk

---> Using cache

---> cb02bd60ea16

Step 8/26 : RUN groupadd -g 1000 elasticsearch && useradd elasticsearch -u 1000 -g 1000 -m -b $arg_user_home -d $arg_user_home -s /bin/bash

---> Running in 64ebd0c6b8cf

Removing intermediate container 64ebd0c6b8cf

---> 49759958cddd

Step 9/26 : USER 1000

---> Running in 849c7bde5f44

Removing intermediate container 849c7bde5f44

---> e0f04944d08c

Step 10/26 : WORKDIR $arg_user_home

Removing intermediate container a7e04ccfe107

---> c5b262000886

Step 11/26 : RUN mkdir apps

---> Running in 0272f8c59b01

Removing intermediate container 0272f8c59b01

---> 5e860b3ae335

Step 12/26 : WORKDIR $arg_user_home/apps

Removing intermediate container 093bbfc52201

---> 541e34eb3f99

Step 13/26 : COPY elasticsearch-$arg_es_version.tar.gz .

---> b7f35e466950

Step 14/26 : COPY jdk-8u152-linux-x64.tar.gz .

---> d47f3d93cfd6

Step 15/26 : RUN tar -xvzf elasticsearch-$arg_es_version.tar.gz

---> Running in ec1b02ec10b4

...중략...

Removing intermediate container ec1b02ec10b4

---> 79d8bec8ee89

Step 16/26 : RUN tar -xvzf jdk-8u152-linux-x64.tar.gz

---> Running in c8ae086e2868

Removing intermediate container b94059a73a2c

---> 6fa8928d2367

...중략...

Step 17/26 : RUN rm -f elasticsearch-$arg_es_version.tar.gz

---> Running in beec4cdec4eb

Removing intermediate container beec4cdec4eb

---> 0c30468566ea

Step 18/26 : RUN rm -f jdk-8u152-linux-x64.tar.gz

---> Running in 998cd2eb3d33

Removing intermediate container 998cd2eb3d33

---> 8e1d588a3bbc

Step 19/26 : COPY config/elasticsearch.yml elasticsearch-$arg_es_version/config/

---> b2faa21e1692

Step 20/26 : COPY config/jvm.options elasticsearch-$arg_es_version/config/

---> 36c3ce020763

Step 21/26 : COPY config/log4j2.properties elasticsearch-$arg_es_version/config/

---> 48314fe634e1

Step 22/26 : RUN ln -s elasticsearch-$arg_es_version elasticsearch

---> Running in 2f7610ab8ce4

Removing intermediate container 2f7610ab8ce4

---> 539eb5fce438

Step 23/26 : RUN ln -s jdk1.8.0_152 jdk

---> Running in 1f4585206800

Removing intermediate container 1f4585206800

---> f61c467a833b

Step 24/26 : WORKDIR elasticsearch-$arg_es_version

Removing intermediate container 786de237b577

---> a92587ddf7bf

Step 25/26 : RUN set -ex && for path in data logs config/scripts; do         mkdir -p "$path";         chown -R elasticsearch:elasticsearch "$path";     done

---> Running in dfe771b1d02d

+ mkdir -p data

+ chown -R elasticsearch:elasticsearch data

+ mkdir -p logs

+ chown -R elasticsearch:elasticsearch logs

+ mkdir -p config/scripts

+ chown -R elasticsearch:elasticsearch config/scripts

Removing intermediate container dfe771b1d02d

---> 90193d0f5dcc

Step 26/26 : EXPOSE 9200 9201 9300 9301

---> Running in b14404086bc4

Removing intermediate container b14404086bc4

---> a2c69d28a015

Successfully built a2c69d28a015

Successfully tagged elasticsearch-6.2.3-ubuntu-14.04-jdk8u152:latest


Step 6) Elasticsearch 가 사용할 네트워크를 생성 합니다.

$ docker network create es-net

$ docker network ls

NETWORK ID          NAME                DRIVER              SCOPE

ed35ea6eb949        bridge              bridge              local

a6c8b4fd7996        es-net              bridge              local

f3ab4273e30a        host                host                local

9d6aa0be922f        none                null                local


Step 7) 만들어진 이미지가 잘 되었는지 한번 명령어를 실행 시켜 봅니다.

$ docker run elasticsearch-6.2.3-ubuntu-14.04-jdk8u152 ls -al

total 248

drwxr-xr-x  1 elasticsearch elasticsearch   4096 Apr 17 07:45 .

drwxr-xr-x  1 elasticsearch elasticsearch   4096 Apr 17 07:45 ..

-rw-r--r--  1 elasticsearch elasticsearch  11358 Mar 13 10:02 LICENSE.txt

-rw-r--r--  1 elasticsearch elasticsearch 191887 Mar 13 10:07 NOTICE.txt

-rw-r--r--  1 elasticsearch elasticsearch   9268 Mar 13 10:02 README.textile

drwxr-xr-x  2 elasticsearch elasticsearch   4096 Apr 17 07:44 bin

drwxr-xr-x  1 elasticsearch elasticsearch   4096 Apr 17 07:45 config

drwxr-xr-x  2 elasticsearch elasticsearch   4096 Apr 17 07:45 data

drwxr-xr-x  2 elasticsearch elasticsearch   4096 Mar 13 10:08 lib

drwxr-xr-x  1 elasticsearch elasticsearch   4096 Mar 13 10:08 logs

drwxr-xr-x 16 elasticsearch elasticsearch   4096 Mar 13 10:08 modules

drwxr-xr-x  2 elasticsearch elasticsearch   4096 Mar 13 10:08 plugins


Step 8) 마지막으로 클러스터 구성을 테스트 합니다.

# -d 를 추가 하면 daemonize 로 동작


$ docker run -p 9200:9200 -p 9300:9300 elasticsearch-6.2.3-ubuntu-14.04-jdk8u152 bin/elasticsearch

# Single node 실행


$ docker run --memory=2g -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -p 9200:9200 -p 9300:9300 -u 1000 elasticsearch-6.2.3-ubuntu-14.04-jdk8u152:latest \

bin/elasticsearch \

-Ecluster.name=cluster-docker \

-Enode.name=node-docker1 \

-Enode.master=true \

-Enode.data=true \

-Ediscovery.zen.minimum_master_nodes=1 \

-Enetwork.host=0.0.0.0 \

-Ediscovery.zen.ping.unicast.hosts=192.168.221.237:9301 \

-Ehttp.port=9200 \

-Etransport.tcp.port=9300


$ docker run --memory=2g -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -p 9201:9200 -p 9301:9300 -u 1000 elasticsearch-6.2.3-ubuntu-14.04-jdk8u152:latest \

bin/elasticsearch \

-Ecluster.name=cluster-docker \

-Enode.name=node-docker2 \

-Enode.master=false \

-Enode.data=true \

-Ediscovery.zen.minimum_master_nodes=1 \

-Enetwork.host=0.0.0.0 \

-Ediscovery.zen.ping.unicast.hosts=192.168.221.237:9300 \

-Ehttp.port=9200 \

-Etransport.tcp.port=9300


별로 어려운것 없이 쉽게 할 수 있습니다.

여기서 개선 및 업그레이드는 각자 편하게 하시면 될 것 같습니다.

:

[Elasticsearch] WildcardQuery 알아보기

Elastic/Elasticsearch 2018. 4. 12. 15:46

참고문서)

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html


WildcardQuery 는 사실 추천 하지 않지만 필요에 따라 사용해야 할 수도 있습니다.

성능적으로 좋은 API 는 아니기 때문에 추천 하지 않는 것이지 기능적으로는 유용할 수도 있습니다.


[Field Type]

Keyword : not_analyzed

Text(String) : analyzed


[Lucene]

WildcardQuery -> MultiTermQuery


[Elasticsearch]

WildcardQueryBuilder


[Usage]

WildcardQuery 는 기본적으로 field type 의 색인 속성과는 상관 없습니다.

not_analyzed field 에 대해서 질의 할 때와 analyzed field 에 대해서 질의 할 때 조금 모호 할 수 있습니다.

즉, term query 를 사용하기 때문에 아래와 같이 예를 들겠습니다.

Field name : title

Text value : nike clothes


Case 1)

not_analyzed field)

term : nike clothes


"query" : {

"wildcard" : {

"title" : "ni*e"

}

}


not matched


결과가 나오지 않는 이유는 추출된 term 이 "nike clothes" 이기 때문에 "ni*e" 로 했을 경우 추출 텀의 제일 마지막 문자가 e 가 아니기 때문에 매칭이 되지 않은 것입니다.

매칭이 되게 하려면 "ni*" 또는 "ni*s" 로 해야 매칭이 됩니다.


Case 2)

analyzed field)

terms : [nike, clothes]


"query" : {

"wildcard" : {

"title" : "ni*e"

}

}


matched


이 경우는 추출된 term 이 두 개 이며, nike 라는 텀에 대해서 매칭이 된 것입니다.



: