'filebeat'에 해당되는 글 14건

  1. 2022.10.25 [Beats] Filebeat Output.logstash 전송 방식.
  2. 2022.05.18 [Elastic] Elasticsearch, Kibana, Filebeat, Logstash 8.2.0 구성하기
  3. 2021.10.27 [Kibana] Discover 에서 데이터 요청 시 _source 와 fields
  4. 2021.10.19 [Elastic] Elastic Stack Installer + No Ansible ㅠ.ㅠ
  5. 2021.10.07 [Filebeat] ignore_older 와 tail_files 관련.
  6. 2021.01.20 [Filebeat] registry 파일 내 offset 초기화.
  7. 2020.06.03 [Filebeat] ilm 조심 하자.
  8. 2020.06.03 [Filebeat] template 설정 setup.template.append_fields
  9. 2020.05.25 [Filebeat] setup.ilm & setup.template 잘 쓰려면.
  10. 2020.05.11 [Beats] Filebeat 내 JSON 처리.

[Beats] Filebeat Output.logstash 전송 방식.

Elastic/Beats 2022. 10. 25. 15:19

 

Filebeats output.logstash 는 기본 async 로 전송 합니다.

공홈 문서)
https://www.elastic.co/guide/en/beats/filebeat/current/logstash-output.html#_pipelining

pipelining

Configures the number of batches to be sent asynchronously to Logstash while waiting for ACK from Logstash.
Output only becomes blocking once number of pipelining batches have been written. 
Pipelining is disabled if a value of 0 is configured.
The default value is 2.



소스코드)
https://github.com/elastic/beats/blob/main/libbeat/outputs/logstash/logstash.go

if config.Pipelining > 0 {
  client, err = newAsyncClient(beat, conn, observer, config)
} else {
  client, err = newSyncClient(beat, conn, observer, config)
}
 

Configure the Logstash output | Filebeat Reference [8.4] | Elastic

If ILM is not being used, set index to %{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd} instead so Logstash creates an index per day, based on the @timestamp value of the events coming from Beats.

www.elastic.co

 

내용과 코드를 보시면 쉽게 이해가 됩니다.

pipelining 설정은 기본 2 이고 이 값이 0 보다 크면 async 로 전송 하게 됩니다.

참고하세요.

 

더불어ㅏ서 pipelining 값은 core 크기와 동일하게 맞춰서 사용 하시면 성능적 효과를 얻을 수 있습니다.
(정답은 아니고 장비에 대한 용도와 올라가는 어플리케이션에 따라 다를 수 있으니 성능 테스트는 꼭 해보시기 바랍니다.)

:

[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 구성 맛보기 였습니다.

:

[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 을 바꾸지만 않으면 잘 됩니다. :)

:

[Filebeat] ignore_older 와 tail_files 관련.

Elastic/Beats 2021. 10. 7. 19:08

이 두 설정은 같이 고려 하는게 좋습니다.

각 설정은 아래 공홈 문서 참고 하시면 됩니다.

 

https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-input-log.html#filebeat-input-log-ignore-older

https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-input-log.html#_tail_files_3

 

[Case 1] filebeat 재시작 시 데이터 유실 없이 사용하기 위한 설정

filebeat.inputs:
- type: log
...중략...
  ignore_older: 0
  tail_files: false
...중략...

 

[Case 2] filebeat 빠른 재시작 시 사용하기 위한 설정

filebeat.inputs:
- type: log
...중략...
  ignore_older: 10m
  tail_files: true
...중략...

가볍게 설정에 대해서 알아보면,

- ignore_older 는 파일의 시간을 가지고 설정된 시간이 지난 파일은 무시 하게 됩니다.

- tail_files 는 파일의 처음 부터 읽을 건지 마지막 부터 읽을 건지 설정을 하게 됩니다.

 

:

[Filebeat] registry 파일 내 offset 초기화.

Elastic/Beats 2021. 1. 20. 15:14

filebeat 의 registry 관련 설정 정보는 아래 공식 문서를 참고하세요.

www.elastic.co/guide/en/beats/filebeat/current/configuration-general-options.html

 

문서 설명에도 있지만, 

 

- 기본 경로는 아래와 같습니다.

The default is ${path.data}/registry

 

Registry 의 구조체를 확인해 보면 아래와 같은데요.

type Registry struct {
	Path          string        `config:"path"`
	Permissions   os.FileMode   `config:"file_permissions"`
	FlushTimeout  time.Duration `config:"flush"`
	CleanInterval time.Duration `config:"cleanup_interval"`
	MigrateFile   string        `config:"migrate_file"`
}

설정에서 path 를 잡아 주지 않으면, 코드 상으로는  "filebeat.py"

default_registry_path = 'registry/filebeat'

위 경로 아래 meta.json 과 log.json 두 개의 파일이 생기고 파일들에 대한 offset 관리가 이루어 집니다.

 

Logstash input file 의 sincedb 와 같이 offset  정보를 reset 하기 위해서는 

- log.json 에서 offset 설정을 다시 해주거나

- 걍 registry 삭제 하고 재 시작 하시면 됩니다.

 

tail_files 설정도 있고 해당 log file 삭제를 하는 것도 있고, 용도와 목적에 맞게 시도해 보시면 될 것 같습니다.

 

:

[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 로 설정을 해야 해서 이 설정을 사용했습니다.

 

:

[Filebeat] setup.ilm & setup.template 잘 쓰려면.

Elastic/Beats 2020. 5. 25. 17:09

가끔 설정은 yml 에 잘 했는데 안될 때가 있습니다.

이게 어디에서 뭘로 했느냐에 따라 다른데요.

 

보통 beats 를 이용할 경우 자동으로 alias 생성 및 설정이 됩니다.

이 경우 elasticsearch 에서 동일하게 사용 하기 위한 ilm 과 template 설정을 하게 되면 동작이 잘 안되는 경우가 있는데요.

 

큰 차이는 is_write_index 설정 때문 입니다.

뭐 이것도 경우에 따라 다르게 나올 수 있지만 일반적이라면 저 설정 때문이다 생각 하시면 됩니다.

 

beats 에서는 libbeat 에서 자동으로 설정을 해줍니다.

 

// CreateAlias sends request to Elasticsearch for creating alias.
func (h *ESClientHandler) CreateAlias(alias Alias) error {
	// Escaping because of date pattern
	// This always assume it's a date pattern by sourrounding it by <...>
	firstIndex := fmt.Sprintf("<%s-%s>", alias.Name, alias.Pattern)
	firstIndex = url.PathEscape(firstIndex)

	body := common.MapStr{
		"aliases": common.MapStr{
			alias.Name: common.MapStr{
				"is_write_index": true,
			},
		},
	}

	// Note: actual aliases are accessible via the index
	status, res, err := h.client.Request("PUT", "/"+firstIndex, "", nil, body)
	if status == 400 {
		// HasAlias fails if there is an index with the same name, that is
		// what we want to check here.
		_, err := h.HasAlias(alias.Name)
		if err != nil {
			return err
		}
		return errOf(ErrAliasAlreadyExists)
	} else if err != nil {
		return wrapErrf(err, ErrAliasCreateFailed, "failed to create alias: %s", res)
	}

	return nil
}

하지만, elasticsearch 에서 수동으로 설정을 한다고 하면 꼭 "is_write_index:true" 설정을 해주셔야 alias 생성 및 등록이 잘 된다는거 알고 넘어 가자고요.

 

:

[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

 

: