個人學習筆記,謝絕轉載!!!
原文:https://www.cnblogs.com/wshenjin/p/13652361.html
filebeat簡介
Beats家族的6個成員:
- Packetbeat:網絡數據(收集網絡流量數據)
- Metricbeat:指標(收集系統、進程和文件系統級別的CPU和內存使用情況等數據)
- Filebeat:日志文件(收集文件數據)
- Winlogbeat:windows事件日志(收集Windows事件日志數據)
- Auditbeat:審計數據(收集審計日志)
- Heartbeat:運行時間監控(收集系統運行時的數據)
早期的ELK架構中使用Logstash收集、解析日志,但是Logstash對內存、cpu、io等資源消耗比較高。Beats在是一個輕量級日志采集器,相比Logstash,Beats所占系統的CPU和內存幾乎可以忽略不計。Filebeat是Beats中的一員,是用於收集轉發日志數據的輕量級傳送工具。Filebeat監視日志文件,收集日志事件,並將它們轉發到Elasticsearch或 Logstash進行索引。
Filebeat的工作方式如下:啟動Filebeat時,它會啟動一個或多個探測器去檢測指定的日志目錄或文件。對於找到的每個日志,Filebeat都會啟動收集器,每個收集器都讀取單個日志以獲取新內容,並將新日志數據發送到libbeat,libbeat將聚集事件,並將聚集的數據發送到output指定的輸出。
filebeat安裝
[root@ ]# wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.9.1-x86_64.rpm
[root@ ]# rpm -ivh filebeat-7.9.1-x86_64.rpm
filebeat配置文件
常用的選項解釋,基於7.9.1版本:
## ================================= filebeat input配置塊 ==================================
filebeat.inputs:
## 每個-都是一個輸入
- type: log
## 是否啟用該輸入
enabled: true
## 日志路徑
paths:
- /data/logs/*.log
- /data/logs/*/*.log
##是否從日志末尾開始讀取日志
tail_files: true
##排除行。排除匹配正則表達式列表的行
exclude_lines: ['^DBG']
##包括行。導出匹配的正則表達式列表的行
include_lines: ['^ERR', '^WARN']
##排除文件。排除匹配正則表達式列表的文件
exclude_files: ['.gz$','nginx_error.log']
##可選附加字段。可以自由選擇這些字段,將附加信息添加網日志文件中進行篩選
fields:
level: debug
review: 1
### 多行選項,多行可以用於跨越多行的日志消息。這對於Java堆棧跟蹤或C-Line延續來說很常見
##匹配多行的正則表達式
multiline.pattern: '^\['
##匹配pattern的行是否合並到上一行,默認是false,匹配pattern的行合並到上一行;true,不匹配pattern的行合並到上一行
multiline.negate: false
##合並到上一行的末尾或開頭
multiline.match: after
##合並的最大行數
multiline.max_lines: 500
## ================================= filebeat output配置塊 ==================================
# ---------------------------- Elasticsearch Output ----------------------------
output.elasticsearch:
enabled: true
##ES的主機端口列表
hosts: ["localhost:9200"]
##協議 - either `http` (default) or `https`.
#protocol: "https"
##身份驗證憑據-API密鑰或用戶名/密碼。
api_key: "id:api_key"
username: "elastic"
password: "changeme"
# ------------------------------ Logstash Output -------------------------------
output.logstash:
enabled: true
## The Logstash hosts
hosts: ["127.0.0.1:5044"]
##使用了負載均衡
loadbalance: true
## Optional SSL. By default is off.
##用於HTTPS服務器驗證的根證書列表
ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]
##SSL客戶端身份驗證證書
ssl.certificate: "/etc/pki/client/cert.pem"
##客戶端證書密鑰
ssl.key: "/etc/pki/client/cert.key"
# ================================== Logging ===================================
##設置日志級別。默認日志級別為info。
## Available log levels are: error, warning, info, debug
logging.level: info
logging.to_files: true
##日志路徑和切割、保留個數、權限
logging.files:
path: /var/log/filebeat
name: filebeat
keepfiles: 7
permissions: 0644
# ================================= 其他 ==================================
## filebeat的程序名稱
name: localhost
## 標簽
tags: ["nginx_log"]
## 可選字段,可以指定將附加信息添加到輸出中
fields:
env: staging
配置實例
1、將/data/logs/*.log的日志文件輸出到文件
配置:
logging.level: info
logging.to_files: true
logging.files:
path: /var/log/filebeat
name: filebeat
keepfiles: 7
permissions: 0644
filebeat.inputs:
- type: log
enabled: true
tail_files: true
paths:
- /data/logs/*.log
exclude_files: ['nginx_error.log']
output.file:
enabled: true
codec.json:
pretty: true
escape_html: true
path: "/data/logs/filebeat"
filename: filebeat_output.log
rotate_every_kb: 10000
number_of_files: 7
permissions: 0600
filebeat.config.modules:
path: ${path.config}/modules.d/*.yml
reload.enabled: false
setup.template.settings:
index.number_of_shards: 1
tags: ["nginx_access_log"]
name: web_server_1.2.3.4
2、將/data/logs/*.log的日志文件輸出到Logstash
logging.level: info
logging.to_files: true
logging.files:
path: /var/log/filebeat
name: filebeat
keepfiles: 7
permissions: 0644
filebeat.inputs:
- type: log
enabled: true
tail_files: true
paths:
- /data/logs/*.log
exclude_files: ['nginx_error.log']
output.logstash:
hosts: ["127.0.0.1:5044"]
filebeat.config.modules:
path: ${path.config}/modules.d/*.yml
reload.enabled: false
setup.template.settings:
index.number_of_shards: 1
tags: ["nginx_access_log"]
name: web_server_1.2.3.4
multiline小結
multiline.negate: false
multiline.match: after ##將匹配到的行和上一行合並
multiline.negate: false
multiline.match: before ##將匹配到的行和下一行合並
multiline.negate: true
multiline.match: before ##將不匹配到的行和下一行合並
multiline.negate: true
multiline.match: after ##將不匹配到的行和上一行合並