ELK+FileBeat搭建日志中心
1 搭建ELK
作業系統:Centos7.3
1.1 修改配置
vi /etc/security/limits.conf
添加下面配置:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
并執行指令:
sysctl -p
1.2 下載下傳ELK相關軟體包
官網下載下傳位址
選擇版本:6.5.1
Kibana 6.5.1
Elasticsearch 6.5.1
Logstash 6.5.1
1.3 安裝并配置Elasticsearch
1.3.1 建立普通使用者,Elasticsearch不能用root使用者啟動
1.3.2 下載下傳ik分詞器
在解壓的es安裝包中,
cd elasticsearch-6.5.1/plugins/
将下載下傳的ik分詞器解壓到該目錄下。安裝其他插件的話,也是儲存到該目錄。
1.3.3 下載下傳ES-Head
elasticsearch-head需要使用node啟動,需要單獨安裝node環境。elasticsearch-head 不能放在elasticsearch的 plugins、modules 目錄下,否則elasticsearch啟動會報錯
cd elasticsearch-head
npm install -g grunt-cli //執行後會生成node_modules檔案夾,可以更換淘寶的源
vi Gruntfile.js
增加hostname屬性,設定為*
nohup grunt server &
elasticsearch-head的通路位址:http://ip:9100
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIyZuBnLzUjNyUzM0kTMyEDMxkTMwIzLc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
可以通過elasticsearch-head檢視es中相關資料。
1.3.4 修改es配置并啟動
vim config/elasticsearch.yml
修改:network.host: 0.0.0.0
配置檔案末尾追加:
thread_pool.bulk.queue_size: 1000
http.cors.enabled: true
http.cors.allow-origin: "*"
啟動:
cd elasticsearch-6.5.1/bin
nohup ./elasticsearch -d &
1.4 安裝并配置logstash
cd logstash-6.5.1/config
根據logstash-sample.conf檔案,定義自己的配置檔案
主要是input、filter、output相關配置,filter涉及到grok、kv、date、mutate相關插件。
還可以使用自定義的規則,通過patterns_dir引入。
啟動:
cd logstash-6.5.1/bin
nohup ./logstash -f logstash-sample.conf &
1.5 安裝并配置kibana
cd kibana-6.5.1-linux-x86_64/config
修改kibana.yml中server.host: "0.0.0.0"
啟動:
cd kibana-6.5.1-linux-x86_64/bin
nohup ./kibana &
2 安裝FileBeat
2.1 下載下傳FileBeat6.5.1
2.2 配置并啟動
cd filebeat-6.5.1-linux-x86_64
vim filebeat.yml
例如:
- type: log
enabled: true #設定成true
paths:
- /home/centos/zipelkf/point/*.log #監控日志檔案
fields: #附加的字段資訊
docType: test-log
啟動:
nohup ./filebeat -e -c filebeat.yml &
3 進行整合測試
3.1 根據filebeat配置檔案中監控日志檔案路徑,向日志檔案中添加日志内容。
3.2 檢視kibana界面或者通過es-head檢視。