filebeat input 에서는 inode marker 를 이용해서 file offset 에 대한 처리 정보를 기록 합니다. 이를 통해서 데이터를 처리 하게 되는데 여러개의 filestream 을 등록 하게 되면 같은 파일에 대해서 데이터를 중복으로 처리 하거나 우선순위에 따라 먼저 선점한 filestream 이와 다른 filestream 에서 처리가 안되는 경우가 발생 할 수 있습니다. 이를 해결 하기 위해서는 사전에 등록된 file 의 inode marker 를 리셋 하거나 filestream 설정에서 id 지정을 통해서 해결 할 수 있습니다.
Each filestream input must have a unique ID. Omitting or changing the filestream ID may cause data duplication. Without a unique ID, filestream is unable to correctly track the state of files.
Changing input ID may cause data duplication becauin the state of the files will be lost and they will be read from the beginning again.
id 값은 유니크 해야 하고 변경 시 데이터가 중복 발생 할 수 있다는 내용입니다. 실제 설정에서 id 설정을 하지 않더라도 실행에는 문제가 되지 않습니다.
Elasticsearch 8.3.2 + Lucene 9.2.0 에서 변경된 내용을 정리해 봅니다.
Lucene 8.11 to 9.2)
pom.xml 내 수정
# lucene-analyzers-common 은 9.x 에서는 더 이상 지원 하지 않음
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-common</artifactId>
<version>${lucene.version}</version>
</dependency>
to
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analysis-common</artifactId>
<version>${lucene.version}</version>
</dependency>
package 변경
org.apache.lucene.analysis.util.TokenFilterFactory
to
org.apache.lucene.analysis.TokenFilterFactory
org.apache.lucene.analysis.standard.ClassicFilter
to
org.apache.lucene.analysis.classic.ClassicFilter
org.apache.lucene.analysis.util.TokenizerFactory
to
org.apache.lucene.analysis.TokenizerFactory
org.apache.lucene.analysis.util.TokenFilterFactory
to
org.apache.lucene.analysis.TokenFilterFactory
org.apache.lucene.analysis.util.TokenFilterFactory
to
org.apache.lucene.analysis.TokenFilterFactory
elasticsearch analyzer plugin)
# AbstractIndexAnalyzerProvider 에서 IndexSettings 제거됨
org.elasticsearch.client.node.NodeClient
to
org.elasticsearch.client.internal.node.NodeClient
JDK 수정
build 시 jdk 17 사용
$jenv local 17
<java.version>17</java.version> 수정
❖ lucene 에서는 analyzer 패키지 변경이 있었으며, elasticsearch 에서는 NodeClient 에 대한 패키지 변경이 있었습니다.
"reason"=>"failed to parse field [message] of type [text] in document with id '3UI29IEBerapX-zaQi4L'.
Preview of field's value:
...중략...
"caused_by"=>{"type"=>"illegal_state_exception", "reason"=>"Can't get text on a
START_OBJECT at 1:529"}
이런 에러메시지를 접하게 되면 두 눈 크게 뜨고 Template 에서 정의한 type 정보와 실제 들어 오는 값이 잘 매핑이 되어 있는지 확인을 해보시기 바랍니다.
# 기본 설정 예시
$ 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