Filebeat 簡介:Filebeat 是一款輕量型日誌收集工具,可轉發彙總日誌、文件等內容。python
其主要特色爲:1. 斷點續傳。(如遇日誌轉發過程當中網絡中斷,會在恢復後從斷開的點繼續轉發)
linux
2. 自適應轉發速率。(當logstash 處理內容滿載時會通知filebeat 轉發率減小,當logstash 處於輕鬆狀態,Filebeat則加大轉發)redis
1、 安裝Filebeat:apache
1. 登錄cpy01.dev.xjh.com(須要下載其餘版本請點擊:https://www.elastic.co/cn/downloads/beats/filebeat )json
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.6.1-linux-x86_64.tar.gz -O /opt/filebeat-5.6.1.tar.gz tar xf filebeat-5.6.1.tar.gz -C /usr/local/ mv /usr/local/filebeat-5.6.1-linux-x86_64 /usr/local/filebeat-5.6.1
2. 將/usr/local/filebeat-5.6.1 整個目錄拷貝到cpy02.dev.xjh.com和cpy03.dev.xjh.com服務器的/usr/local/目錄下tomcat
scp -r /usr/local/filebeat-5.6.1 root@cpy02.dev.xjh.com:/usr/local/ scp -r /usr/local/filebeat-5.6.1 root@cpy03.dev.xjh.com:/usr/local/
2、Filebeat配置文件說明:bash
Filebeat 做爲輸出工具,可向多種收集工具發送內容,如:logstash(本實驗採用直接輸出至logstash)、Elasticsearch、kafka、rabbitmq、redis等......服務器
filebeat.yml 簡述:網絡
yml 文件以鍵值對形式存在,均已相同縮進表明相同級別,列表由'-' 表示,配置文件採用摺疊式命名規範,如:負載均衡
filebeat: prospectors: - input_type : log paths: - /var/log/message.log - /usr/local/logs/business.log 意思是:捕獲 filebeat.prospectors.0.input+type: log.0./var/log/message.log 和filebeat.prospectors.0.input+type: log.1./usr/local/logs/business.log 兩個日誌文件
通常摺疊式寫成:
filebeat.prospectors: - input_type : log paths: ["/var/log/message.log","/usr/local/logs/business.log"]
filebeat.prospectors: #filebeat 命名規範,表示捕獲文件開始
- input_type : log #表示捕獲數據類型爲log
paths: ["/var/log/message.log","/usr/local/logs/business.log"] #表示日誌文件路徑
3、配置Filebeat
1. 配置輸出至logstash
#=========================== Filebeat prospectors ============================= #=========================== 定義捕獲的日誌文件 ============================= filebeat.prospectors: - input_type: log paths: ["/usr/local/apache-tomcat-7.0.57/logs/*"] - input_type: stdin #======================== Filebeat Global ===================================== #======================== Filebeat 全局配置 =================================== filebeat.config_dir:/usr/local/filebeat-5.6.1 #定義filebeat 配置文件目錄路徑 #========================= Filebeat Config prospectors========================= #========================= 配置從新加載配置文件 ========================= filebeat.config.prospectors: path : configs/filebeat.yml reload.enabled : true reload.period : 10s #------------------------- Logstash Output ------------------------------------ #------------------------- 配置輸出到logstash --------------------------------- output.logstash: hosts: ["cpy04.dev.xjh.com:5044"] #該列表若是爲多個,則採用負載均衡模式發送到列表中的logstash服務器
2. 配置輸出至 kafka
#----------------------------- Kafka output -------------------------------- output.kafka: hosts: ["kafka01.dev.xjh.com:9092"] topic: "topicname" partition.round_robin: reachable_only: false required_acks: 1 compression: gzip max_message_bytes: 1000000
3. 配置輸出至 elasticsearch
#----------------------------- Elasticsearch output -------------------------------- output.elasticsearch: hosts:["http://elastic.dev.xjh.com:9200"] username: "elasticsearch-username" password: "elasticsearch-password" template.enabled:true template.path:"filebeat.template.json" template.overwrite:false index:"index-name" ssl.certificate_authorities:["/etc/pki/root/ca.pem"] ssl.certificate:"/etc/pki/client/cert.pem" ssl.key:"/etc/pki/client/cert.key"
4. 配置輸出至 redis
#----------------------------- Elasticsearch output -------------------------------- output.redis: hosts: ["redis.dev.xjh.com"] password: "redis-password" key: "filebeatkeysname" db: 0 timeout: 10
5. 配置輸出至 console
#-------------------------- Console output ------------------------------ output.console: pretty: true
4、檢測配置文件是否有效(如無效,大多爲縮進引發):
sudo /usr/local/filebeat-5.6.1/filebeat -configtest /usr/local/filebeat-5.6.1/filebeat.yml
5、 啓動Filebeat服務:
sudo /usr/local/filebeat-5.6.1/filebeat -c /usr/local/filebeat-5.6.1/filebeat.yml 2>&1 &