filebeatde的安裝,讀取文件寫入到ElasticSearch(es)
前置條件:
確保ES和fileBeat的版本是一致的,我們本次使用的版本是7.16.2,filebeat的下載地址:https://www.elastic.co/cn/downloads/beats/filebeat
選擇下載版本 7.16.2
下載到本地並且 解壓到本地:接下來我們修改一下filebeat.yml文件
增加如下內容,讀取本地路徑的log文件 並且輸入到es里面,前置條件必須已經安裝過es 並且啟動起來
該文件里面的內容 copy后的文件:
# ============================== Filebeat inputs =============================== filebeat.inputs: - type: log #默認是log 從日志文件讀取每一行 stdin 從標准輸入讀取 enabled: true paths: ## 日志存儲的地址 - C:\Users\junnan.lang\log\logs\filebeat.log multiline.pattern: '^\d{4}\-\d{2}\-\d{2}\s\d{2}:\d{2}:\d{2}' #匹配的正則 不是以2019-09-08 12:23:23 格式開頭的將合並到上一行 multiline.negate: true #多行匹配模式后配置的模式是否取反,默認false multiline.match: after #定義多行內容被添加到模式匹配行之后還是之前,默認無,可以被設置為after或者before fields: index: 'filebeat' # ---------------------------- Elasticsearch Output ---------------------------- output.elasticsearch: # Array of hosts to connect to. hosts: ["127.0.0.1:9200"] #本次es的地址和端口 indices: - index: "filebeat-%{+yyyy.MM.dd}" #索引名 按照日期 when.contains: fields: index: "filebeat"
保存文件后,我們從cmd命令窗口進入 ,並且啟動 filebeat的服務
命令如下:
filebeat -e -c filebeat.yml 因為我本地已經啟動了,所以在啟動顯示被占用