想用filebeat讀取項目的日志,然后發送logstash。logstash官網有相關的教程,但是docker部署的教程都太簡潔了。自己折騰了半天,踩了不少坑,總算是將logstash和filebeat用docker部署好了,這兒簡單記錄一下
部署logstash
1. 編寫logstash配置文件logstasgh.conf
輸入是從filebeat中獲取的,輸出配置的是一個http端
input { beats { port => "5044" } } # The filter part of this file is commented out to indicate that it is # optional. # filter { # # } output { http { http_method => "post" url => "http://127.0.0.1/log" format => "json" } stdout { codec => rubydebug } }
2. 獲取logstash的docker鏡像
docker pull docker.elastic.co/logstash/logstash:7.1.1
3. 通過dokcer啟動logstash
docker run -p 5044:5044 --name logstash -d \ -v /path/to/logstash.conf:/usr/share/logstash/pipeline/logstash.conf \ docker.elastic.co/logstash/logstash:7.1.1
部署filebeat
1. 編寫filebeat的配置文件filebeat.yml
filebeat.inputs: - type: log paths: # 容器內的路徑,可以不用修改,映射到這個路徑就可以 - /val/log/ fields: # 額外添加的字段 project-name: your_project_name # 需要排除和包括的行(正則表達式) exclude_lines: ['INFO'] include_lines: ['ERROR'] # 這個是用來處理異常產生多行數據時,將多行數據當作一條日志處理,根據自己的異常日志的格式做修改 multiline.pattern: '^\[' multiline.negate: true multiline.match: after ignore_older: 168h tail_files: true output.logstash: hosts: ["127.0.0.1:5044"]
2. 獲取filebeat的docker鏡像
docker pull docker.elastic.co/beats/filebeat:7.1.1
3. 通過dokcer啟動filebeat
docker run --name filebeat -d \ -v /path/to/:/var/log/:ro \ -v /path/to/filebeat.yml:/usr/share/filebeat/filebeat.yml \ docker.elastic.co/beats/filebeat:7.1.1
