beats 平台集合了多種單一用途資料採集器。這些採集器安裝後可用作輕量型**,從成百上千或成千上萬臺機器向 logstash 或 elasticsearch 傳送資料。常用的beats有filebeat(收集檔案)、metricbeat(收集服務、系統的指標資料)、packetbeat(收集網路包)等。這裡主要介紹filebeat外掛程式。
一、架構圖
二、安裝filebeat
wget
tar -xzf filebeat-6.3.2-linux-x86_64.tar.gz -c /usr/local/
cd /usr/local/
ln -s filebeat-6.3.2-linux-x86_64 filebeat
2、自定義配置檔案① 簡單版本的配置檔案
cd /usr/local/filebeat/
cat > test.yml << end
filebeat.inputs:
- type: stdin
enabled: true
setup.template.settings:
index.number_of_shards: 3
output.console:
pretty: true
enable: true
end#啟動filebeat,啟動filebeat的時候使用者需要用filebeat使用者或者root使用者
./filebeat -e -c test.yml
#測試啟動好後輸入任意字串,如hello,即可輸出對應資訊。
#啟動引數說明:./filebeat -e -c test.yml
-e:輸出到標準輸出,預設輸出到syslog和logs下
-c:指定配置檔案
②收集日誌檔案
cd /usr/local/filebeat/
cat > test.yml << end
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
- /var/log/messages
exclude_lines: ['^dbg',"^$",".gz$"]
setup.template.settings:
index.number_of_shards: 3
output.console:
pretty: true
enable: true
end#啟動filebeat
./filebeat -e -c test.yml
③自定義字段收集日誌檔案
cd /usr/local/filebeat/
cat > test.yml << end
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
- /var/log/messages
exclude_lines: ['^dbg',"^$",".gz$"]
tags: ["web","item"] #自定義tags
fields: #新增自定義字段
from: itcast_from #值隨便寫
fields_under_root: true #true為新增到根節點中,false為新增到子節點中
setup.template.settings:
index.number_of_shards: 3
output.console:
pretty: true
enable: true
end#啟動filebeat
./filebeat -e -c test.yml
#如果有tags欄位在logstash中的書寫格式
if "web" in [tags]
④收集nginx日誌檔案輸出到es或者logstash中
cd /usr/local/filebeat/
cat > nginx.yml << end
filebeat.inputs:
- type: log
enabled: true
paths:
- /usr/local/nginx/access/*.log
exclude_lines: ['^dbg',"^$",".gz$"]
document_type: filebeat-nginx_accesslog
tags: ["web","nginx"]
fields:
from: nginx
fields_under_root: true
setup.template.settings:
index.number_of_shards: 3
output.elasticsearch:
hosts: ["192.168.0.117:9200","192.168.0.118:9200","192.168.0.119:9200"]
#output.logstash:
# hosts: ["192.168.0.117:5044"]
end#啟動filebeat
./filebeat -e -c nginx.yml
三、filebeat收集各個日誌到logstash,然後由logstash將日誌寫到redis,然後再寫入到es
1、filebeat配置檔案
cat > dashboard.yml << end
filebeat.inputs:
- input_type: log
paths:
- /var/log/*.log
- /var/log/messages
exclude_lines: ['^dbg',"^$",".gz$"]
document_type: filebeat-systemlog
- input_type: log
paths:
- /usr/local/tomcat/logs/tomcat_access_log.*.log
exclude_lines: ['^dbg',"^$",".gz$"]
document_type: filebeat-tomcat-accesslog
multiline.pattern: '^[0-9]-[0-9]-[0-9]'
multiline.negate: true
multiline.match: after
- type: log
enabled: true
paths:
- /usr/local/nginx/access/*.log
exclude_lines: ['^dbg',"^$",".gz$"]
document_type: filebeat-nginx-accesslog
output.logstash:
hosts: ["192.168.0.117:5044"]
enabled: true
worker: 3
compression_level: 3
end##啟動
./filebeat -e -c dashboard.yml
2、logstash配置檔案①將beats收集的日誌寫入到logstash中
cat > beats.conf << end
input
}output
} if [type] == "filebeat-tomcat-accesslog"
} if [type] == "filebeat-nginx-accesslog"
}}end
②從redis中讀取日誌寫入es
cat > redis-es.conf << end
input
redis
redis }
output "
}} if [type] == "filebeat-tomcat-accesslog" "
}} if [type] == "filebeat-nginx-accesslog" "}}}
end
備註:使用negate: true和match: after設定來指定任何不符合指定模式的行都屬於上一行。更多多行匹配配置請參考
四、通過kibana展示即可
簡易輕量級http介面採集器
配置路徑,key為具體的類別,value為具體的路徑 pathconfig 獲取當日 defget today import time return time.strftime y m d time.localtime time.time 例項bottle 路由 hell 例如 訪問127.0.0....
安裝 loki 輕量級日誌監控系統
文章 自 使用docker compose安裝 yum install y docker composewget o docker compose.yaml 修改docker compose.yaml檔案,設定指定的日誌檔案路徑 nano docker compose.yaml 修改 promtai...
XHProf php輕量級的效能分析工具
xhprof php輕量級的效能分析工具 其中有一篇野馬分享的 php效能檢測擴充套件 xhprof 不錯,之前就有聽說,這次就行動一下。xhprof是facebook開源出來的乙個php輕量級的效能分析工具,跟xdebug類似,但效能開銷更低,還可以用在生產環境中,也可以由程式開 關來控制是否進行...