'kibana'에 해당되는 글 33건

  1. 2022.08.29 [Kibana] Discover 생성 후 삭제
  2. 2022.05.18 [Elastic] Elasticsearch, Kibana, Filebeat, Logstash 8.2.0 구성하기
  3. 2022.05.09 [Elastic] Enterprise Search 8.2 구성 해 보기
  4. 2022.03.24 [Elasticsearch] Terms + Sub Sum Aggs 사례.
  5. 2021.10.27 [Kibana] Discover 에서 데이터 요청 시 _source 와 fields
  6. 2021.10.19 [Elastic] Elastic Stack Installer + No Ansible ㅠ.ㅠ
  7. 2021.09.29 [Elastic] 초간단 모니터링 시스템 만들기
  8. 2021.04.06 [Elasticsearch] Elastic APM Quick 구성
  9. 2021.02.02 [Elastic] Elasticsearch Cluster 구성하기 based on IaC 1
  10. 2020.09.10 [Kibana+Docker] Docker Compose 내 elasticsearch.hosts 설정

[Kibana] Discover 생성 후 삭제

Elastic/Kibana 2022. 8. 29. 11:20

Discover 를 새로 만들어서 저장하는 문서는 아래를 참고하세요.

https://www.elastic.co/guide/en/kibana/current/save-open-search.html

 

생성 후 삭제를 하고 싶은데 관련 내용은 별도 문서를 찾기 못해서 기록해 둡니다.

 

1. Stack Management

2. Kibana > Saved Objects

 

에 들어가서 삭제 하고 싶은 discover 를 찾아서 삭제 하면 됩니다.

 

그리고 추가적으로 Recently viewed 에 나오는 항목에 대한 삭제는 localStorage 에 저장 되기 때문에 직접 찾아서 삭제 하시면 됩니다.

아직까지 삭제 기능을 제공 하고 있지는 않습니다.

 

:

[Elastic] Elasticsearch, Kibana, Filebeat, Logstash 8.2.0 구성하기

Elastic 2022. 5. 18. 13:05

가볍게 Elastic Stack 8.2.0 을 기준으로 설치 및 구성 하는 방법을 기술 합니다.

xpack basic 버전 이지만 security 기능은 사용 하지 않습니다.

security 사용을 적용해 보고 싶으신 분은 아래 글을 참고해 보시면 될 것 같습니다.

 

참고 글)

[Elastic] Enterprise Search 8.2 구성 해 보기

 

[Elastic] Enterprise Search 8.2 구성 해 보기

Enterprise Search (App Search) 를 사용하기 위해서는 먼저 선행 되어야 하는 것들이 있습니다. https://www.elastic.co/guide/en/app-search/current/getting-started.html App Search 이외 Workspace Search 도..

jjeong.tistory.com

 

1. Elasticsearch Setup

$ vi config/elasticsearch.yml
# xpack basic security feature disable.
xpack.security.enabled: false
xpack.security.enrollment.enabled: false
xpack.security.http.ssl.enabled: false
xpack.security.transport.ssl.enabled: false
ingest.geoip.downloader.enabled: false

# JDK 17 ES_JAVA_HOME 설정
$ bin/elasticsearch

xpack.security 기능을 사용하지 않을 거라서 위와 같이 설정을 먼저 진행 합니다.

여기서 출가로 geoip 도 disabled 했습니다. 이유는 보안상 이유로 다운로드가 막혀 있는 경우 에러가 나는데 이게 보기 싫으신 분들은 저렇게 끄고 사용 하시면 됩니다.

 

2. Kibana Setup

$ vi config/kibana.yml
xpack.security.audit.enabled: false

$ bin/kibana

kibana 는 간단 합니다.

어차피 로컬 개발 장비에서 모두 설치 하는 거라 기본 연결 설정 정보는 모두 localhost:9200, localhost:5601 이렇게 구성 됩니다.

 

3. Filebeat Setup

가장 많이 사용 했던 것이 input type log 였는데요.

이게 filestream 으로 개선되어 추가 되었습니다.

아래 문서 참고 하세요.

https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-input-filestream.html

# 기본 설정 예시

$ vi filebeat.yml
# 아래 설정에서 inode_marker 파일은 미리 생성이 되어 있어야 에러가 발생 하지 않습니다.
filebeat.inputs:
- type: filestream
  id: fb-filestream
  enabled: true
  paths:
    - $[PATH}/logs/*.log
  file_identity.inode_marker.path: $[PATH}/logs/.filebeat-marker
  
  encoding: utf-8

processors:
  - decode_json_fields:
      fields: [ "message" ]
      target: "json"

output.elasticsearch:
  hosts: ["localhost:9200"]

# 실행
$ ./filebeat -c filebeat.yml -e

 

4. Logstash Setup

filebeat 연동 시 filebeat.yml 의 output 에 logstash 설정을 합니다.

# filebeat 설치 경로에 가서 수정 합니다.
$ vi filebeat.yml
output.logstash:
  hosts: ["localhost:5044"]

# 이제 logstash 와 filebeat 연동을 위한 설정을 합니다.
$ vi config/logstash-sample.conf
input {
  beats {
    port => 5044
  }
}

output {
  elasticsearch {
    hosts => ["http://localhost:9200"]
    index => "logstash-%{+YYYY.MM.dd}"
  }
}

# 이제 logtash 와 filebeat 를 실행 해서 정상적으로 색인이 되었는지 확인 합니다.
$ bin/logstash -f config/logstash-sample.conf

# pipeline.yml 을 사용하기 위해서는 아래 설정 후 실행 하면 됩니다.
# 기본 설정이기 때문에 한번은 해야 합니다.
$ vi config/logstash.yml
node.name: ${NODE-NAME}
path.data: ${PATH}/data/logstash
path.logs: ${PATH}/logs/logstash
config.reload.automatic: true
config.reload.interval: 60s
http.port: 9600

$ vi config/pipeline.yml
- pipeline.id: filebeat-log-pipeline
  pipeline.workers: 4
  pipeline.batch.size: 20
  path.config: "${PATH}/config/logstash-sample.conf"

# 이제 실행 합니다.
$ bin/logstash

자, 여기까지 Elastic Stack 8.2.0 구성 맛보기 였습니다.

:

[Elastic] Enterprise Search 8.2 구성 해 보기

Elastic 2022. 5. 9. 13:56

Enterprise Search (App Search) 를 사용하기 위해서는 먼저 선행 되어야 하는 것들이 있습니다.

https://www.elastic.co/guide/en/app-search/current/getting-started.html

 

App Search 이외 Workspace Search 도 있습니다.

여기서는 App Search 만 다뤘습니다.

 

1. Elasticsearch 가 설치 되어 있어야 합니다.

Enterprise Search 는 Elasticsearch 를 포함 하고 있지 않습니다.

구성 되어 있는 Elasticsearch Cluster 에 연결 해서 Enterprise Search 를 사용 할 수 있도록 해줍니다.

 

2. Kibana 가 설치 되어 있어야 합니다.

Kibana 가 필요한 이유는 Enterprise Search 의 Web UI 가 Kibana 로 통합 되었기 때문 입니다.

 

3. Enterprise Search 가 설치 되어 있어야 합니다.

Enterprise Search 를 사용하기 위해 필요 하며, Elasticsearch 는 JDK 17 을 요구 하지만, Enterprise Search JDK 11 을 요구 합니다.

사용 하는 JDK 버전을 꼭 확인 하셔야 합니다.

 

 

Elasticsearch 8.2 설치 및 실행)

기본 tar ball 을 다운로드 받고 압축을 해제 한 후 바로 실행 합니다.

전에도 설명 했지만 8.x 부터는 기본 xpack security 기능이 enabled 입니다.

$ bin/elasticsearch
 Elasticsearch security features have been automatically configured!
✅ Authentication is enabled and cluster connections are encrypted.

ℹ️  Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
  0*LbX+orEfOCQx2GPRRy

ℹ️  HTTP CA certificate SHA-256 fingerprint:
  961aea7f1014ee94966ed79be09f3f550236389049d41b41c4dbe196e2bf7a22

ℹ️  Configure Kibana to use this cluster:
• Run Kibana and click the configuration link in the terminal when Kibana starts.
• Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
  eyJ2ZXIiOiI4LjIuMCIsImFkciI6WyIxOTIuMTY4LjAuNzo5MjAwIl0sImZnciI6Ijk2MWFlYTdmMTAxNGVlOTQ5NjZlZDc5YmUwOWYzZjU1MDIzNjM4OTA0OWQ0MWI0MWM0ZGJlMTk2ZTJiZjdhMjIiLCJrZXkiOiJpNWRvcG9BQkhoU20tOF9wY1FVYTpwdUZTMFMtM1J4aVZZUmoyaGJzajZnIn0=

ℹ️  Configure other nodes to join this cluster:
• On this node:
  ⁃ Create an enrollment token with `bin/elasticsearch-create-enrollment-token -s node`.
  ⁃ Uncomment the transport.host setting at the end of config/elasticsearch.yml.
  ⁃ Restart Elasticsearch.
• On other nodes:
  ⁃ Start Elasticsearch with `bin/elasticsearch --enrollment-token <token>`, using the enrollment token that you generated.


Kibana 8.2 설치 및 실행)

기본 tar ball 을 다운로드 받고 압축을 해제 한 후 바로 실행 합니다.

Security Enabled 이기 때문에 Kibana 실행 시 Elasticsearch 에서 생성해 준 코드를 입력해서 연결 합니다.

등록 후 ID, PWD 를 입력 하고 로그인 합니다.

$ bin/kibana
i Kibana has not been configured.

Go to http://localhost:5601/?code=917177 to get started.

# elasticsearch 실행 하면서 생성된 코드를 등록 하고 kibana 구성을 완료 합니다.
# id/pwd 를 입력 하고 로그인 합니다. (역시 elasticsearch 실행 시 생성된 코드를 입력 합니다.)

 

Enterprise Search 8.2 설치 및 실행)

기본 tar ball 을 다운로드 받고 압축을 해제 한 후 바로 실행 합니다.

Enterprise Search 의 경우 필요한 정보는 Elasticsearch 와 Kibana 정보 입니다.

Elasticsearch 의 경우 SSL 연동을 위한 정보도 함께 등록 합니다.

$ bin/enterprise-search
# java 11 버전을 요구 하기 때문에 맞춰서 실행 합니다.

--------------------------------------------------------------------------------

Invalid config file (/Users/henry/Workspace/apps/es8.2.0/enterprise-search-8.2.0/config/enterprise-search.yml):
The setting '#/secret_management/encryption_keys' is not valid
No secret management encryption keys were provided.
Your secrets cannot be stored unencrypted.
You can use the following generated encryption key in your config file to store new encrypted secrets:
todd
secret_management.encryption_keys: [37697db0e75459e7c5e55e6c492c36fde2dc31dcc7b9db9fcc44c702d0a3b9f5]


--------------------------------------------------------------------------------

$ vi config/enterprise-search.yml
secret_management.encryption_keys: [37697db0e75459e7c5e55e6c492c36fde2dc31dcc7b9db9fcc44c702d0a3b9f5]
allow_es_settings_modification: true
elasticsearch.username: elastic
elasticsearch.password: 0*LbX+orEfOCQx2GPRRy
elasticsearch.host: https://127.0.0.1:9200
elasticsearch.ssl.enabled: true
elasticsearch.ssl.certificate_authority: /Users/henry/Workspace/apps/es8.2.0/elasticsearch-8.2.0/config/certs/http_ca.crt
kibana.external_url: http://localhost:5601


# enterprise-search 연동을 위해 kibana 설정을 합니다.
$ vi config/kibana.yml
enterpriseSearch.host: http://localhost:3002


$ bin/enterprise-search
#########################################################

Success! Elastic Enterprise Search is starting successfully.

Advanced tooling and management interfaces are available via Kibana. Learn more about configuring and running
Kibana with Enterprise Search at https://www.elastic.co/guide/en/enterprise-search/master/user-interfaces.html.

In a few moments, you'll be able to access Enterprise Search from Kibana at the following address:

  * Kibana URL: http://localhost:5601/app/enterprise_search/overview

If this is your first time starting Enterprise Search, check the console output above for your user authentication credentials.

Visit the documentation: https://www.elastic.co/guide/en/enterprise-search/master/index.html


WARNING: A new secret session key has been generated.

Set the key in your config file to persist user sessions through process restarts:

secret_session_key: 5c6b7e6034c36ab0753033889e977624e362990f210adac99348e0e94aefb9b758ef8799d8d111b7d7c5c11383a254a50ca5322ed916ce185b2141617aa5924e


#########################################################


Kibana 에 접속해서 Enterprise Search 를 사용해 봅니다.)

# kibana 에 접속 해서 enterprise search 에서 app search 를 생성 합니다.
# app search 에서 engine 생성을 한 후 json 파일을 등록 합니다.
# [ {...}, {...} ] 형태의 개별 문서가 등록이 되어 있어야 하며, bulk request json 과 형식이 다릅니다.
# 문서 등록을 했으면 생성한 엔진으로 접근해서 검색을 실행해 봅니다.
# Relevance Tuning 이나 Search UI 에서 실행 합니다. 또는 Postman 에서 실행 하고자 할 때는
https://www.elastic.co/guide/en/app-search/8.2/search-guide.html
각각의 인증키는 Credentials 에 들어 가면, private-key 와 search-key 가 존재 합니다.

# Endpoint rule
http://localhost:3002/api/as/v1/engines/${ENGINE-NAME}/query_suggestion
http://localhost:3002/api/as/v1/engines/${ENGINE-NAME}/search.json

# Suggestion
curl --location --request POST 'http://localhost:3002/api/as/v1/engines/disney-poc/query_suggestion' \
--header 'Authorization: Bearer search-dupjgg5jdgafcj4cqoykq39k' \
--header 'Content-Type: application/json' \
--data-raw '{"query":"서울"}'

# Search
curl --location --request POST 'http://localhost:3002/api/as/v1/engines/disney-poc/search.json' \
--header 'Authorization: Bearer search-dupjgg5jdgafcj4cqoykq39k' \
--header 'Content-Type: application/json' \
--data-raw '{
    "query":"서울"
}'

# enterprise search 에서 제공 하는 query 에는 QueryDSL 을 사용 할 수 없습니다.
https://www.elastic.co/guide/en/app-search/8.2/search.html#search-api-request-body

# enterprise search 에서 제공 하는 synonyms 기능은 질의 시점에 적용 되는 기능입니다.
https://www.elastic.co/guide/en/app-search/8.2/synonyms.html
Kibana UI 에서 등록 시 처음에 등록 하는 동의어가 원본 동의어가 되며, 이후 등록 하는 value 들이 원본 동의어와 같이 처리가 되어야 하는 동의어가 됩니다.

통신 방법에 따라 사용 유형을 정리해 보면,

Case 1)

Elasticsearch Cluster <--> Enterprise Search <--> Kibana

 

Case 2)

Elasticsearch Cluster <--> Enterprise Search <--> External Search API

 

Vertical Search Engine 으로도 사용이 가능 합니다.

Elasticsearch Cluster <--> Enterprise Search (각 서비스 또는 도메인 별 Enigne 생성) <--> External Search API (Engine 별 Endpoint)

 

단일 클러스터 운영을 하고 여러 Collection(Index) 을 사용하고자 할 때 유용하게 사용 가능해 보입니다.

:

[Elasticsearch] Terms + Sub Sum Aggs 사례.

Elastic/Elasticsearch 2022. 3. 24. 18:13

문제)

하루 동안 데이터 요청을 가장 많이한 IP Top 5 를 구하시오.

 

해결)

GET /kibana_sample_data_logs/_search
{
  "size":0,
  "aggs": {
    "ip_aggs": {
      "terms": {
        "field": "ip"
      },
      "aggs": {
        "sum_aggs": {
          "sum": {
            "field": "bytes"
          }
        },
        "sum_aggs_sort": {
          "bucket_sort": {
            "sort": [
              { "sum_aggs": { "order": "desc" } } 
            ],
            "size": 5
          }
        }
      }
    }
  }
}

 

관련 문서)

https://www.elastic.co/guide/en/elasticsearch/reference/8.1/search-aggregations-bucket-terms-aggregation.html

https://www.elastic.co/guide/en/elasticsearch/reference/8.1/search-aggregations-pipeline-bucket-sort-aggregation.html

 

Elasticsearch 를 설치 하고 Kibana 를 이용해서 Sample Data 를 이용하였습니다.

그냥 Single node 로 구성 해서 테스트 해보실 수 있습니다.

:

[Kibana] Discover 에서 데이터 요청 시 _source 와 fields

Elastic/Kibana 2021. 10. 27. 09:35

Kibana Discover 에서 데이터 요청 시 _source 는 false 로 가져 오지 않습니다.
다만, View 형식을 Table 에서 JSON 으로 변경 시 _source:true 로 데이터를 가져 오게 됩니다.
그렇기 때문에 기본 fields 를 이용해서 문서의 field 를 가져 오게 됩니다.

 

이걸 기록 하는 이유는 

log file ->

filebeat input log -> filebeat processors decode_json_fields -> filebeat output logstash ->

logstash input beat -> logstash output elasticsearch -> logstash output elasticsearch codec json -> 

elasticsearch ->

kibana

이 과정에서 kibana 에서 불필요한 데이터 요청을 하는 것 같아 확인을 해보니 Table 뷰와 JSON 뷰가 다르다는 걸 확인한 결과를 기록 한 부분 입니다.

 

기본 요청은 _source:false 이기 때문에 불필요한 요청을 하지 않습니다.

 

불필요한 요청이라고 하는 이유는 fields 는 _source 에서 정보를 가져오기 때문에 중복입니다.
:

[Elastic] Elastic Stack Installer + No Ansible ㅠ.ㅠ

Elastic 2021. 10. 19. 19:05

이런 저런 이유가 있어서 IaC 적용이 어려워 그냥 Shell Script + SSH Tunneling 기반으로 작성했습니다.

https://github.com/HowookJeong/elastic-stack-installer

 

GitHub - HowookJeong/elastic-stack-installer

Contribute to HowookJeong/elastic-stack-installer development by creating an account on GitHub.

github.com

 

elastic-stack-installer
각 stack 경로로 들어가서 실행 하면 됩니다.
기본 stack 의 start/stop 스크립트는 포함이 되어 있습니다.
$ cd stack/elasticsearch/bin
$ zsh installer
설치 할 운영체제를 선택 하세요.
0. MACOS
1. LINUX_X86_64
2. LINUX_AARCH64
   0
   선택한 운영 체계는 0 번 입니다.
   설치 할 버전을 입력 하세요.
   예) 7.15.1
   7.15.1
   입력한 버전은 7.15.1 입니다.

VPN 연결을 통해 배포가 이루어 지나요? (y/n)
설치 파일을 먼저 다운로드 받습니다. 이후 설치 스크립트를 재실행 하고 이 단계를 'N' 로 입력하고 스킵 합니다.
n
wget --read-timeout=5 --timeout=5 --no-check-certificate https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.15.1-darwin-x86_64.tar.gz
--2021-10-19 18:31:24--  https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.15.1-darwin-x86_64.tar.gz
artifacts.elastic.co (artifacts.elastic.co) 해석 중... 34.120.127.130
다음으로 연결 중: artifacts.elastic.co (artifacts.elastic.co)|34.120.127.130|:443... 연결했습니다.
HTTP 요청을 보냈습니다. 응답 기다리는 중... 200 OK
길이: 338602042 (323M) [application/x-gzip]
저장 위치: `elasticsearch-7.15.1-darwin-x86_64.tar.gz'

elasticsearch-7.15.1-darwin-x86_64.tar.gz       100%[====================================================================================================>] 322.92M  2.93MB/s    /  1m 57s

2021-10-19 18:33:21 (2.75 MB/s) - `elasticsearch-7.15.1-darwin-x86_64.tar.gz' 저장함 [338602042/338602042]

SSH 통신을 위한 KEY 가 필요 한가요? (y/n)
n
SSH 접속 User 를 입력 하세요.
예) deploy
henry
설치할 인스턴스의 IP 를 입력 하세요.
예)
127.0.0.1
localhost
인스턴스에 설치할 경로를 입력 하세요.
예)
/home/deploy/apps/
/Users/deploy/apps/
인스턴스에 설치 파일을 배포할 경로를 입력 하세요.
예)
/home/deploy/dist/elastic-stack/elasticsearch
/Users/deploy/dist/elastic-stack/elasticsearch
Symbolic link 를 사용하시면 입력 하시고 아니면 엔터를 입력 하세요.
elasticsearch
ssh -p 22 -o StrictHostKeychecking=no henry@localhost mkdir -p /Users/deploy/dist/elastic-stack/elasticsearch
ssh -p 22 -o StrictHostKeychecking=no henry@localhost mkdir -p /Users/deploy/apps/
scp -P 22 -o StrictHostKeychecking=no elasticsearch-7.15.1-darwin-x86_64.tar.gz henry@localhost:/Users/deploy/dist/elastic-stack/elasticsearch
ssh -p 22 -o StrictHostKeychecking=no henry@localhost cd /Users/deploy/dist/elastic-stack/elasticsearch; tar -xvzf elasticsearch-7.15.1-darwin-x86_64.tar.gz
ssh -p 22 -o StrictHostKeychecking=no henry@localhost cd /Users/deploy/dist/elastic-stack/elasticsearch; rm -f elasticsearch-7.15.1-darwin-x86_64.tar.gz
ssh -p 22 -o StrictHostKeychecking=no henry@localhost cd /Users/deploy/dist/elastic-stack/elasticsearch; mv elasticsearch-7.15.1 /Users/deploy/apps/
scp -P 22 -o StrictHostKeychecking=no start henry@localhost:/Users/deploy/apps//elasticsearch-7.15.1/bin/
scp -P 22 -o StrictHostKeychecking=no stop henry@localhost:/Users/deploy/apps//elasticsearch-7.15.1/bin/
ssh -p 22 -o StrictHostKeychecking=no henry@localhost cd /Users/deploy/apps//elasticsearch-7.15.1/bin; chmod 755 start
ssh -p 22 -o StrictHostKeychecking=no henry@localhost cd /Users/deploy/apps//elasticsearch-7.15.1/bin; chmod 755 stop
elasticsearch-7.15.1-darwin-x86_64.tar.gz                      100%  323MB 237.0MB/s   00:01    
x elasticsearch-7.15.1/
...중략...

start                                                        100%  211   572.4KB/s   00:00    
stop                                                     100%   97   283.6KB/s   00:00    
ssh -p 22 -o StrictHostKeychecking=no henry@localhost cd /Users/deploy/apps/; rm -f elasticsearch
ssh -p 22 -o StrictHostKeychecking=no henry@localhost cd /Users/deploy/apps/; ln -s elasticsearch-7.15.1 elasticsearch
다운로드 받은 파일을 삭제 합니다.
rm -f elasticsearch-7.15.1-darwin-x86_64.tar.gz

설치 가능한 Stack 은 Elasticsearch, Filebeat, Kibana, Logstash 입니다.

Elastic 사에서 다운로드 경로와 파일명에 대한 Name Rule 을 바꾸지만 않으면 잘 됩니다. :)

:

[Elastic] 초간단 모니터링 시스템 만들기

Elastic 2021. 9. 29. 17:54

구성요소)

- Elasticsearch

- Kibana

- Elastic Agents

 

Basic 용으로 Security Disabled 하고 사용 합니다. (Security 적용 하실 분은 API Key 생성과 User/Password 구성 하시면 됩니다.)

 

Elasticsearch + Kibana Security Disabled)

- elasticsearch.yml

- kibana.yml

xpack.security.enabled: false

 

Elastic Agents 설치)

https://www.elastic.co/guide/en/fleet/current/elastic-agent-installation.html

Standalone 으로 구성하고 설치가 필요한 장비에 설치 하면 됩니다.

(Fleet 구성은 테스트 해보지 않았구요. 필요 시 해보겠습니다.)
$ sudo ./elastic-agent install

 

EA Start & Stop on Mac)

- Start

$ sudo launchctl load /Library/LaunchDaemons/co.elastic.elastic-agent.plist
- Stop

$ sudo launchctl unload /Library/LaunchDaemons/co.elastic.elastic-agent.plist

 

Dashboard & Visualize)

Kibana 를 이용하시면 됩니다.

 

Alert)

이건 Elasticsearch 로 RESTful API 요청해서 Rule 에 따른 알람을 보내면 됩니다.

보통, WAS 로 구현해서 Slack 으로 보내거나, Scheduler 를 이용해서 Script 를 실행시켜 Slack 으로 보내거나 합니다.

 

:

[Elasticsearch] Elastic APM Quick 구성

Elastic/Elasticsearch 2021. 4. 6. 14:39

Elastic 사에서 제공 하는 다양한 도구와 서비스 들이 있습니다.

APM 이라는 아주 좋은 도구도 제공 하는데요.

Quick 하게 필요한 정보만 기록해 봅니다.

 

[Elastic APM Server]

https://www.elastic.co/guide/en/apm/server/current/overview.html
https://www.elastic.co/downloads/apm

 

[Elastic APM Agent]

https://www.elastic.co/guide/en/apm/agent/java/current/intro.html
https://search.maven.org/search?q=g:co.elastic.apm%20AND%20a:elastic-apm-agent

 

<intellij 에서 vm 옵션으로 등록합니다.>
-javaagent:/Users/mzc02-henryjeong/Works/elastic/apm-agent/elastic-apm-agent-1.22.0.jar -Delastic.apm.service_name=poc-service -Delastic.apm.application_packages=com.mzc.poc -Delastic.apm.server_url=http://localhost:8200

 

<Kibana 에서 Index Pattern 등록 하고 Discover 합니다.>

apm-{versin}-onboarding-*
apm-{versin}-span-*
apm-{versin}-error-*
apm-{versin}-transaction-*
apm-{versin}-profile-*
apm-{versin}-metric-*

- alias 로 자동 생성 되어 있음.

 

구성 시 사전 필요한 stack 은)

- Elasticsearch

- Kibana

- Spring Boot Web Application

:

[Elastic] Elasticsearch Cluster 구성하기 based on IaC

Elastic 2021. 2. 2. 12:04

https://github.com/HowookJeong/ecos-installer-web

배포 및 실행 가이드

Prerequisite)

  • bastion machine 은 ubuntu 를 사용 합니다.
  • bastion 및 ec2 instance 에 ssh tunnuling 을 위한 key pairs 생성을 합니다.
  • 로컬 장비에서 실행 하기 위해 계정의 access/secret key 생성을 합니다.

Step 1) Local 실행 환경 구성

$ aws configure --profile ecos 

Put region : ap-northeast-2
Put output : json
Put access key : xxxxxxxxxxxxxx
Put secret key : xxxxxxxxxxxxxx
Put key pairs file to ~/.ssh/

 

Step 2) Terraform & Ansible 환경 설정

$ vi docker-compose.yml

 environment:
 ...중략...
   - serverPort=${SERVER_PORT}
   - configWorkingPath=/tmp/home/mzc/app
   - configTerraformAwsBastionIp=${BASTION_IP}
   - configTerraformAwsSecurityGroup=sg-xxxxxxxxxxxxxxxx
   - configTerraformAwsAz=ap-northeast-2a
   - configTerraformAwsAmi=ami-061b0ee20654981ab
   - configTerraformAwsSubnet=subnet-xxxxxxxxxxxxxxxx
   - configTerraformAwsKeyName=ec2key-gw
   - configTerraformAwsPemFile=ec2key-gw.pem
   - configTerraformAwsPathElasticsearch=/tmp/home/mzc/app/terraform/_CLUSTERNAME_
   - configTerraformAwsPathKibana=/tmp/home/mzc/app/terraform/_CLUSTERNAME_/kibana
   - configTerraformAwsBackendBucket=megatoi-terraform-state
   - configTerraformAwsBackendKeyElasticsearch=_CLUSTERNAME_/terraform.tfstate
   - configTerraformAwsBackendKeyKibana=_CLUSTERNAME_/kibana/terraform.tfstate
 volumes:
 ...중략...
   - /Users/계정/.aws:/root/.aws
   - /Users/계정/.ssh:/root/.ssh

 

Step 3) 배포 된 docker image load

$ sudo docker load -i ecos-installer-web-0.0.1.tar

 

Step 4) 컨테이너 실행/중지

$ ENV=dev TAG=0.0.1 REDIRECT_HTTPS=true SERVER_PORT=8081 docker-compose up -d

$ ENV=dev TAG=0.0.1 REDIRECT_HTTPS=true SERVER_PORT=8081 docker-compose down

Local 개발 환경

  • $ cd .aws
  • $ aws configure --profile ecos
  • $ vi config

[profile ecos]

region = ap-northeast-2

output = json

  • $ vi credentials

[ecos]

aws_access_key_id = xxxxxxxxxxxxxxxxx

aws_secret_access_key = xxxxxxxxxxxxxxxxxx

Project Docker Compose 설정

...중략...
    volumes:
      - /Users/mzc02-henryjeong/.aws:/root/.aws
      - /Users/mzc02-henryjeong/.ssh:/root/.ssh
      - /Users/mzc02-henryjeong/Temp/logs:/home/mzc/logs
      - /var/run/docker.sock:/var/run/docker.sock
      - /Users/mzc02-henryjeong/Works/app/terraform:/home/mzc/backup/terraform
...중략...
  • aws 접속 및 ssh 터널링을 위해 관련 path 에 대한 mount 를 합니다.

Build Step

  • $ ./gradlew clean build bootJar -Pprofile=dev -x test
  • $ docker build --build-arg BASTION_IP=xxx.xxx.xxx.xxx --tag ecos-installer-web:0.0.1 .
  • OR $ ENV=dev TAG=0.0.1 REDIRECT_HTTPS=true SERVER_PORT=8081 docker-compose build
  • $ ENV=dev TAG=0.0.1 REDIRECT_HTTPS=true SERVER_PORT=8081 docker-compose up
  • $ ENV=dev TAG=0.0.1 REDIRECT_HTTPS=true SERVER_PORT=8081 docker-compose down
  • $ docker image ls
  • $ docker rmi -f 7f52709a6615
  • $ docker exec -it ecos-installer-web /bin/sh
  • $ sudo docker save -o ecos-installer-web-0.0.1.tar ecos-installer-web:0.0.1
  • $ sudo docker load -i ecos-installer-web-0.0.1.tar

Terraform path 와 Elasticsearch Cluster 명명 규칙

  • Terraform File Path : /tmp/home/mzc/app/terraform/${CLUSTERNAME}/${TIMESTAMP}
  • Backend Key : ${CLUSTERNAME}/${TIMESTAMP}/terraform.tfstate
  • 신규 생성 시
    • Step 1) Terraform File Path : /tmp/home/mzc/app/terraform/elasticsearch
    • Step 1) Backend Key : elasticsearch/terraform.tfstate
  • 추가 시
    • Step 1) Terraform File Path : /tmp/home/mzc/app/terraform/elasticsearch/1598860075233
    • Step 1) Backend Key : elasticsearch/1598860075233/terraform.tfstate
    • Step 2) Backend Key : elasticsearch/1598860075233/terraform.tfstate
    • 기존 클러스터에 Join 시키기 위해 master ip 정보를 구해야 함

생성 및 설정

  • aws account access/secret key 생성
  • aws configure 설정
  • bastion 서버 생성
  • vpc 내 정보 설정
    • security group
    • subnet
    • az
    • ec2 네트워크 및 보안에서 키 페어 생성 및 등록 (keyName, keyPem)
    • ami
  • terraform 정보 설정
    • terraform working path 설정
    • terraform backend 설정
  • aws cluster instance 설정
    • node topology 설정 (node 유형)
    • instance type 설정 (cpu, mem, network 성능)
    • instance size 설정 (node 규모)
    • disk volume size 설정 (elasticsearch storage)
  • elasticsearch cluster 설정
    • cluster name 설정
    • 설치를 위한 elasticsearch version 지정
    • port 설정 (http, tcp)
    • path.data/logs 설정
  • ansible 설정
    • working path 설정
    • bastion ip 설정

Service Flow

  • TerraformService

    • terraform
      • createTerraformS3Backend
      • readTerraformTemplateForElasticsearch
      • writeTerraformTemplateForElasticsearch
      • runTerraformTemplateForElasticsearch
      • backupTerraformTemplateStateForElasticsearch (if it is not s3 backend)
  • ElasticsearchService

    • docker
      • createDockerComposeConfiguration
    • ansible
      • createAnsibleInventories
      • createAnsibleRoles

runAnsiblePlaybook

:

[Kibana+Docker] Docker Compose 내 elasticsearch.hosts 설정

Elastic/Kibana 2020. 9. 10. 16:56

기본적으로 config/kibana.yml 에서는 array 로 설정을 하게 되어 있습니다.

Kibana : Multi-Elasticsearch 로 등록이 가능 하다는 것인데요.

 

Kibana 를 Docker 로 구성 할 경우 일반적인 yaml 문법의 array 등록 방식으로 작성을 하게 되면 에러가 발생을 합니다.

그래서 아래와 같이 작성을 하셔야 합니다.

 

[Code Example]

version: "3.7"
services:
  dockerr-kibana:
    image: docker.elastic.co/kibana/kibana:7.9.1
    container_name: docker-kibana
    environment:
      ELASTICSEARCH_HOSTS: '["http://host.docker.internal:9200","http://host.docker.internal:9201","http://host.docker.internal:9202"]'
    ports:
      - 5601:5601
    expose:
      - 5601
    restart: always
    network_mode: bridge

 

[Error Code]

version: "3.7"
services:
  dockerr-kibana:
    image: docker.elastic.co/kibana/kibana:7.9.1
    container_name: docker-kibana
    environment:
      ELASTICSEARCH_HOSTS: 
        - "http://host.docker.internal:9200"
        - "http://host.docker.internal:9201"
        - "http://host.docker.internal:9202"
    ports:
      - 5601:5601
    expose:
      - 5601
    restart: always
    network_mode: bridge

[Error Message]

$ docker-compose up
ERROR: The Compose file './docker-compose.yml' is invalid because:
services.dockerr-kibana.environment.ELASTICSEARCH_HOSTS contains ["http://host.docker.internal:9200", "http://host.docker.internal:9201", "http://host.docker.internal:9202"], 
which is an invalid type, it should be a string, number, or a null

 

: