ELK套件FileBeat部署
目錄
1.簡介
2.下載
3.直接輸出到ElasticSearch
4.輸出到Logstash
5.更改nginx日志路徑
6.logstash負(fù)載均衡
7.日志文件直接作為輸入
1.簡介
FileBeat用于文件數(shù)據(jù)采集并輸出到ElasticSearch或Logstash中。
ELK搭建過程參見: ELK搭建及Java程序接入
2.下載
下載FileBeats OSS 7.2.1版本
https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-oss-7.2.1-linux-x86_64.tar.gz
tar xzvf filebeat-oss-7.2.1-linux-x86_64.tar.gz
cd filebeat-7.2.1-*
#啟用nginx模塊
./filebeat modules enable nginx
3.直接輸出到ElasticSearch
#設(shè)置初始環(huán)境
./filebeat setup -e
此時(shí)報(bào)錯(cuò)連接不上kibana
instance/beat.go:877?? ?Exiting: error connecting to Kibana: fail to get the Kibana version: HTTP GET request to http://localhost:5601/api/status fails: fail to execute the HTTP GET request: Get http://localhost:5601/api/status: dial tcp [::1]:5601: connect: connection refused. Response: .
Exiting: error connecting to Kibana: fail to get the Kibana version: HTTP GET request to http://localhost:5601/api/status fails: fail to execute the HTTP GET request: Get http://localhost:5601/api/status: dial tcp [::1]:5601: connect: connection refused. Response: .
修改連接kibana的配置
vi filebeat.yml
setup.kibana:
? host: "192.168.81.145:5601"
重新設(shè)置初始環(huán)境
#運(yùn)行filebeat
./filebeat -e
#附:靜默運(yùn)行
nohup ./filebeat -e > service.out&
此時(shí)
kibana中就有了filebeat-*索引,可以看到日志數(shù)據(jù)
多跑一些數(shù)據(jù),打開kibana的Dashboard,選擇filebeat給創(chuàng)建的[Filebeat Nginx] Overview ECS,可以看到如下頁面,地圖展示、柱狀圖餅圖統(tǒng)計(jì)等均有。
?
4.輸出到Logstash
vi filebeat.yml
output.logstash:
? hosts: ["localhost:5044"]
把以下兩個(gè)配置節(jié)注釋掉
setup.kibana:
output.elasticsearch:
重啟filebeat后,nginx訪問日志會(huì)寫入到logstash中,但此時(shí)logstash寫入elasticsearch會(huì)報(bào)錯(cuò):failed to parse field [host] of type [text] in document with id 'E0lsjW4BTdp_eLcgfhbu'
看elasticsearch日志發(fā)現(xiàn)此時(shí)host為一個(gè)json對象,需要變?yōu)樽址判?br /> 修改配置,添加過濾器,把host.name賦值為host
vi config/logstash.conf
filter {
? mutate {
? ? rename => { "[host][name]" => "host" }
? }
}
重啟后即可
5.更改nginx日志路徑
vi modules.d/nginx.yml
- module: nginx
? access:
? ? enabled: true
? ? var.paths: ["/path/to/log/nginx/access.log*"]
? error:
? ? enabled: true
? ? var.paths: ["/path/to/log/nginx/error.log*"]
6.logstash負(fù)載均衡
注意要加loadbalance: true
output.logstash:
? hosts: ["localhost:5044", "localhost:5045"]
? loadbalance: true
7.日志文件直接作為輸入
vi filebeat.yml
- type: log
? enabled: true
? paths:
? ? - /root/*.log
在/root/目錄下新建1.log、2.log隨便寫幾行日志,filebeat重啟后即可入到elasticsearch中。
啟動(dòng)后再增加3.log或往已有的1.log中加日志均可入到elasticsearch中。
總結(jié)
以上是生活随笔為你收集整理的ELK套件FileBeat部署的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android中利用productFla
- 下一篇: Could NOT find SDL_i