官網(wǎng):https://www.elastic.co/
日志大數(shù)據(jù)系統(tǒng)的組成
日志記錄工具:Log4j 2谤逼、Apache Commons Logging等
日志采集器:部署在每臺服務(wù)器上踢涌,采集數(shù)據(jù)到緩沖隊(duì)列米辐,例如 Elastic Beats、Elastic Logstash庸蔼、Fluentd、Apache Flume
日志緩沖隊(duì)列(可選):RocketMQ,Kafka蟆融,Redis等
日志解析器(可選):從緩沖隊(duì)列里讀取日志,轉(zhuǎn)成JSON守呜,存到日志存儲系統(tǒng)型酥。例如Elastic Logstash、Fluentd
日志存儲系統(tǒng):Elasticsearch查乒、MongoDB等NoSQL
日志檢索系統(tǒng):Elasticsearch弥喉、Apache Solr等
日志展示系統(tǒng):Elastic Kibana等
概念
Elastic Stack:elastic.co發(fā)布的一序列產(chǎn)品
ELK:Elasticsearch、Logstash玛迄、Kibana
ELK Stack:Elastic Stack的曾用名
Beats
功能:輕量級 采集由境、發(fā)送數(shù)據(jù)
產(chǎn)品序列:Filebeat(日志采取)蓖议、Metricbeat(操作系統(tǒng)和應(yīng)用軟件 指標(biāo)數(shù)據(jù)的采集)虏杰、Packetbeat(網(wǎng)絡(luò)數(shù)據(jù)采集)、Heartbeat(健康數(shù)據(jù)采集)
Filebeat
文檔:https://www.elastic.co/guide/en/beats/filebeat/current/index.html
配置參考:https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-reference-yml.html
安裝
1勒虾、下載tar.gz 到 /usr纺阔,解壓tar -zxvf
2、運(yùn)行Filebeat:./filebeat -e -C filebeat.yml
模塊
prospector:勘探者修然,即input笛钝,監(jiān)控文件變化
harvester:收割者,即output愕宋,讀取文件玻靡,發(fā)送給目標(biāo)。發(fā)送的數(shù)據(jù)格式為json掏婶,字段包含采集時間啃奴、采集源、message雄妥,message即所采集的日志
filter:過濾器最蕾,在input和output時依溯,過濾掉部分行和filebeat自己加上的字段
配置
filebeat.yml
filebeat.inputs: # 是個數(shù)組
- type: log # 還可以是標(biāo)準(zhǔn)輸入stdin
paths: # 是個數(shù)組
- /var/log/*.log
exclude_lines: ['^DBG'] # 排除行
include_lines: ['^ERR', '^WARN'] # 包含行
exclude_files: ['.gz$'] # 排除文件
output.elasticsearch: # 輸出到elasticsearch,還可以輸出到console瘟则、file黎炉、Logstash、Kafka醋拧、Redis
hosts: ["localhost:9200"]
processors: # 輸出處理
- drop_event: # 在某情況下丟棄本條日志
when:
equals:
http.code: 200
- drop_fields: # 丟棄字段
fields: ["source", "type"]
- include_fields: # 只取部分字段
fields: ["message"]
filebeat.modules: # 啟用通用模塊
- module: nginx
- module: mysql
- module: system
Packetbeat
文檔:https://www.elastic.co/guide/en/beats/packetbeat/current/index.html
配置參考:https://www.elastic.co/guide/en/beats/packetbeat/current/packetbeat-reference-yml.html
安裝
1慷嗜、下載tar.gz 到 /usr,解壓tar -zxvf
2丹壕、運(yùn)行Packetbeat:./packetbeat -e -C packetbeat.yml
配置
packetbeat.yml
packetbeat.interfaces.device: any # 網(wǎng)卡
packetbeat.protocols: # 抓包目標(biāo)
- type: http
ports: [80, 8080, 8000, 5000, 8002]
send_request: true # 是否抓取請求體
include_body_for: ["application/json"] # 抓取json請求的body
# output 和 processors 配置庆械,與Filebeat類似
Logstash
功能:采集、轉(zhuǎn)換菌赖、發(fā)送數(shù)據(jù)
文檔:https://www.elastic.co/guide/en/logstash/current/index.html
歷史:Jordan Sissel 于 2009年發(fā)布Logstash缭乘,2013年被Elasticsearch公司收購
安裝
1、下載tar.gz 到 /usr琉用,解壓tar -zxvf
2堕绩、運(yùn)行l(wèi)ogstash:bin/logstash -f config/logstash.sample.conf
模塊
input:輸入
filter:過濾與轉(zhuǎn)換
output:輸出
配置
config/logstash.sample.conf
input {
stdin { } # 標(biāo)準(zhǔn)輸入
file { # 文件輸入
path => "/tmp/access_log"
start_position => "beginning"
}
tcp { # 網(wǎng)絡(luò)輸入
port => 5000
type => syslog
}
}
filter {
if [path] =~ "access" { # 過濾
mutate { replace => { "type" => "apache_access" } } # 設(shè)置字段的值
grok {
# 設(shè)置message的格式,COMBINEDAPACHELOG 會被展開成 多個%{pettern:key}
match => { "message" => "%{COMBINEDAPACHELOG}" }
}
}
else if "error" in [request] {
mutate { replace => { type => "apache_error" } }
}
if [type] == "syslog" {
grok {
# %{字段值的來源:字段名}
match => { "message" => "%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program} %{GREEDYDATA:syslog_message}" }
add_field => [ "received_at", "%{@timestamp}" ] # 添加字段
add_field => [ "received_from", "%{host}" ]
}
}
grok { # 結(jié)構(gòu)化
match => { "message" => "%{COMBINEDAPACHELOG}" }
}
date { # 時間處理
match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]
}
}
output {
elasticsearch { hosts => ["localhost:9200"] } # 輸出到elasticsearch
stdout { codec => rubydebug } # 標(biāo)準(zhǔn)輸出邑时,格式為rubydebug
}
grok模式的定義:https://github.com/logstash-plugins/logstash-patterns-core/tree/master/patterns
Elasticsearch
功能:存儲和檢索
詳見:http://www.reibang.com/p/09fdd85d3613
Kibana
功能:web界面展示
文檔:https://www.elastic.co/guide/cn/kibana/current/index.html
安裝:
1奴紧、下載tar.gz,放到/usr晶丘,解壓tar -zxvf
2黍氮、配置 config/kibana.yml
elasticsearch.url: "http://localhost:9200" # ES的位置
server.host: 綁定的IP
server.port: 端口
3、運(yùn)行kibana:bin/kibana
4铣口、訪問 IP:5601
板塊
Dev Tools:編輯和發(fā)送請求
Discover:數(shù)據(jù)查看滤钱,數(shù)量統(tǒng)計(jì)
Dashboard:總覽
Visualize:配置圖表,顯示圖表
Management:設(shè)置 與 管理
Elastic Stack 實(shí)踐
1脑题、Packetbeat部署在業(yè)務(wù)集群
2件缸、Logstash、Elasticsearch 和 Kibana部署在日志監(jiān)控集群
3叔遂、Packetbeat 抓取業(yè)務(wù)包他炊,發(fā)給Logstash,處理后存到Elasticsearch
Packetbeat配置
packetbeat.protocols: # 輸入
- type: http
ports: [80, 8080, 8000, 5000, 8002]
output.logstash: # 輸出
hosts: ["localhost:5044"]
Logstash配置
input { # 輸入
beats {
port => 5044
}
}
output { # 輸出
elasticsearch { hosts => ["localhost:9200"] } # 輸出
}
阿里云
開放搜索:搜索引擎
日志服務(wù)
阿里云 · Elasticsearch