集中式日誌分析平臺 Elastic Stack(部署)
1、架構選型
接下來我們進行初步的探視,利用測試環境體驗下ELK Stack + Filebeat,測試環境我們就不進行 Kafka 的配置了,因為他的存在意義在於提高可靠性。
2、軟件版本
Filebeat 6.4.0
Logstash 6.4.0
Elasticsearch 6.4.0
Kibana 6.4.0
JDK 1.8.0_181
3、服務器準備
IP | 系統 | 角色 |
---|---|---|
172.18.2.100 | CentOS 7.4.1708 | Logstash, ES, Kibana |
172.18.2.101 | CentOS 7.4.1708 | Filebeat |
172.18.2.102 | CentOS 7.3.1611 | Filebeat |
4、SSH免秘鑰
需要打通172.18.2.100
至所有 agent 的 SSH 免密登錄。
[root@ES ~]# ssh-copy-id 172.18.2.101
[root@ES ~]# ssh-copy-id 172.18.2.102
5、JDK安裝
ELK 需要 Oracle 1.7(或者是 OpenJDK 1.7) 及以上,建議下載 Oracle 官方的 JDK,我們這裏下載的是官方的 rpm 包。
rpm -ivh jdk-8u181-linux-x64.rpm
二、ELK 服務安裝
ELK 官網對於每種軟件提供了多種格式的安裝包(zip/tar/rpm/DEB),以 Linux 系列系統為例,如果直接下載 RPM,可以通過 rpm -ivh path_of_your_rpm_file直接安裝成系統 service。以後就可以使用 service 命令啟停。比如service elasticsearch start/stop/status。很簡單,我們主要就使用這種方式進行安裝。
1、ElasticSearch
下載軟件包(172.18.2.100)
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.0.rpm
安裝
rpm -ivh elasticsearch-6.4.0.rpm
修改配置
修改/etc/elasticsearch/elasticsearch.yml
。
cluster.name: myes node.name: es1.wzlinux.com path.data: /var/lib/elasticsearch path.logs: /var/log/elasticsearch network.host: 172.18.2.100 http.port: 9200
啟動ES
systemctl daemon-reload
systemctl start elasticsearch.service
systemctl enable elasticsearch.service
驗證
[root@ES ~]# curl ‘http://172.18.2.100:9200‘
{
"name" : "es1.wzlinux.com",
"cluster_name" : "myes",
"cluster_uuid" : "q54RkYTLTKuVaSytrTXiAg",
"version" : {
"number" : "6.4.0",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "595516e",
"build_date" : "2018-08-17T23:18:47.308994Z",
"build_snapshot" : false,
"lucene_version" : "7.4.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
可以看到,它跟其他的節點的傳輸端口為9300,接受HTTP請求的端口為9200。
[root@ES ~]# netstat -tlnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 903/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1001/master
tcp6 0 0 172.18.2.100:9200 :::* LISTEN 11885/java
tcp6 0 0 172.18.2.100:9300 :::* LISTEN 11885/java
tcp6 0 0 :::22 :::* LISTEN 903/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1001/master
2、Logstash
下載安裝包(172.18.2.100)
wget https://artifacts.elastic.co/downloads/logstash/logstash-6.4.0.rpm
安裝
rpm -ivh logstash-6.4.0.rpm
安裝組件beats
一個Logstash的pipeline由3部分組成:input, filter, output。
在我們的架構中,Logstash的input是beats,output是ES,需要對應的插件。
cd /usr/share/logstash/
bin/logstash-plugin install logstash-input-beats
配置
修改文件/etc/logstash/conf.d/logstash.conf
。
input {
beats {
port => 5044
}
}
output {
elasticsearch {
hosts => "172.18.2.100:9200"
manage_template => false
index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
document_type => "%{[@metadata][type]}"
}
}
Logstash 使用該配置使用 ES 的索引,和 Filebeat 做的事情是一樣的,不過擁有了額外的緩存以及強大豐富的插件庫。
啟動
systemctl start logstash.service
3、Kibana
Kibana 從 ES 獲取數據做前端的可視化展示。 它提供了用戶體驗極佳的高定制化 UI,可以靈活配置出你需要的 Dashboard。 Dashboard 可以輕易的保存、鏈接和分享。
下載(172.18.2.100)
wget https://artifacts.elastic.co/downloads/kibana/kibana-6.4.0-x86_64.rpm
安裝
rpm -ivh kibana-6.4.0-x86_64.rpm
配置
編輯/etc/kibana/kibana.yml
。
elasticsearch.url: "http://172.18.2.100:9200"
server.host: "172.18.2.100"
啟動
systemctl daemon-reload
systemctl start kibana.service
查看
在瀏覽器中訪問http://172.18.2.100:5601
。
4、Filebeat
在172.18.2.101、172.18.2.102上進行Filebeat的安裝。
下載
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.4.0-x86_64.rpm
安裝
rpm -ivh filebeat-6.4.0-x86_64.rpm
配置
修改/etc/filebeat/filebeat.yml
,把日誌輸出指向logstash,關閉Elasticsearch output。
#----------------------------- Logstash output --------------------------------
output.logstash:
hosts: ["172.18.2.100:5044"]
添加 Index Pattern
- 在 Elasticsearch 中, Index Pattern 用於定義字段應如何分析的設置和映射。
- Filebeat 的默認 Index Pattern 由軟件包安裝。 如果使用默認的配置文件 filebeat.yml,則 Filebeat 在成功連接到Elasticsearch後會自動加載模板。 如果模板已存在,默認不會覆蓋,但是可以通過配置進行覆蓋。
- 如果要禁用自動模板加載,或者要加載自己的模板,可以在Filebeat配置文件中更改模板加載的設置。
因為我們的輸出不是 ES,所以我們需要手動添加 Index Pattern。
[root@node2 ~]# filebeat setup --template -E output.logstash.enabled=false -E ‘output.elasticsearch.hosts=["172.18.2.100:9200"]‘
Loaded index template
啟動
systemctl start filebeat
集中式日誌分析平臺 Elastic Stack(部署)