filebeat安裝與基礎用法


來自官網,版本為1.2

下載rpm包並安裝

wget -c https://download.elastic.co/beats/filebeat/filebeat-1.2.3-x86_64.rpm
rpm -ivh filebeat-1.2.3-x86_64.rpm

配置文件位於/etc/filebeat/

默認filebeat的日志是to_syslog,就是/var/log/message,而且是error級別以上才打印,最好改一下

vi /etc/filebeat/filebeat.yml(Logging段,一般在文件末尾,配置項都是存在的,取消注釋后修改下即可)

logging:
    to_syslog: false
    to_files: true
    files:
        rotateeverybytes: 10485760 # 默認的10MB
        level: info

修改后,日志文件將位於/var/log/filebeat/

另外要說的是,類似logstash,為了防止重復處理日志,filebeat也會記錄處理進度到文件/var/lib/filebeat/registry

為了測試可以先停止filebeat,清空文件registry,然后再啟動就會重復處理了

下面是簡單將文件傳到elasticsearch的配置

vi /etc/filebeat/filebeat.yml(配置項都是存在的,取消注釋后修改下即可)

filebeat:
    prospectors:
    paths:
        - /data/logs/*.log
    encoding: utf-8
    input_type: log
output:
    elasticsearch:
        hosts: ["localhost:9200"]

paths下面可以配置多個路徑

下面啟動filebeat

/etc/init.d/filebeat

在elasticsearch中可以看到多了一個filebeat-[date]的索引,查一下可以看到直接把每行日志作為一個字符串處理的

所以實際情況下,都是會經過logstash處理后再傳給elasticsearch

首先需要讓logstash做好接收filebeat數據的准備

vi /etc/logstash/conf.d/filebeat.conf

input {
    beats {
        port => 5044
    }
}
output {
    elasticsearch {
        hosts => "localhost"
    }
}

重啟logstash

vi /etc/filebeat/filebeat.yml

output:
    logstash:
        hosts: ["localhost:5044"]

重啟filebeat(如果配置的還是上面的日志文件,記得清理進度緩存)

然后在elasticsearch中可以看到多了一個logstash-[date]的索引

因為沒有在logstash配置filter,所以並沒有進行任何解析,logstash-filter相關的就不在這篇談了。

最后傳輸到elasticsearch的日志默認會帶兩個值:

"beat" : {
  "hostname" : "localhost.localdomain",
  "name" : "localhost.localdomain"
},

hostname當然就是日志來源filebeat所在機器的機器名,name則是可配置的filebeat名稱,默認也是獲取機器名,可以改為ip,多一個過濾屬性

vi /etc/filebeat/filebeat.yml

shipper:
    name: 192.168.1.111

 這樣,傳輸到logstash的日志就是這樣了:

"beat" : {
  "hostname" : "localhost.localdomain",
  "name" : "192.168.1.111"
},

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM