一、ELK概述
ELK是指Elasticsearch、Logstash、Kibana三個開源軟件的首字母縮寫。通過ELK,我們可以將數據可視化,便於我們進行日誌分析和搜索。下面我們將結合代碼,簡單介紹如何搭建ELK。
二、安裝Elasticsearch
1、安裝Java環境:
yum install java-1.8.0-openjdk-devel
2、下載Elasticsearch:
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.14.0-linux-x86_64.tar.gz
3、解壓Elasticsearch到指定目錄,並且配置Elasticsearch環境變量。
tar -zxvf elasticsearch-7.14.0-linux-x86_64.tar.gz -C /usr/local/
export PATH=$PATH:/usr/local/elasticsearch-7.14.0/bin
4、啟動Elasticsearch
elasticsearch
5、測試是否安裝成功
curl http://localhost:9200
如果您獲得了以下響應,說明您已經成功安裝Elasticsearch並且可以正常使用了。
{
"name": "xxx",
"cluster_name": "elasticsearch",
"cluster_uuid": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxx",
"version": {
"number": "7.14.0",
"build_flavor": "default",
"build_type": "tar",
"build_hash": "dd5a0a2acaa2045ff9624f3729fc8a6f40835aa1",
"build_date": "2021-07-29T20:49:32.864135063Z",
"build_snapshot": false,
"lucene_version": "8.9.0",
"minimum_wire_compatibility_version": "6.8.0",
"minimum_index_compatibility_version": "6.0.0-beta1"
},
"tagline": "You Know, for Search"
}
三、安裝Logstash
1、下載Logstash
wget https://artifacts.elastic.co/downloads/logstash/logstash-7.14.0-linux-x86_64.tar.gz
2、解壓Logstash到指定目錄,並且配置Logstash環境變量。
tar -zxvf logstash-7.14.0-linux-x86_64.tar.gz -C /usr/local/
export PATH=$PATH:/usr/local/logstash-7.14.0/bin
3、創建日誌文件配置文件“test.conf”
input {
stdin { }
}
output {
elasticsearch {
hosts => ["127.0.0.1:9200"]
index => "test"
}
}
4、啟動Logstash並且加載配置文件
logstash -f /usr/local/logstash-7.14.0/config/test.conf
5、測試Logstash是否工作正常
輸入任意字符,回車提交。在Kibana界面,test索引應該出現了。
四、安裝Kibana
1、下載Kibana
wget https://artifacts.elastic.co/downloads/kibana/kibana-7.14.0-linux-x86_64.tar.gz
2、解壓Kibana到指定目錄,並且配置Kibana環境變量。
tar -zxvf kibana-7.14.0-linux-x86_64.tar.gz -C /usr/local/
export PATH=$PATH:/usr/local/kibana-7.14.0-linux-x86_64/bin
3、啟動Kibana
kibana
4、在瀏覽器中打開Kibana http://localhost:5601,您應該可以看到Kibana頁面
五、ELK的優化
1、修改jvm.options文件,根據實際環境修改Heap大小
-Xms4g
-Xmx4g
2、修改Elasticsearch的配置文件
vim /usr/local/elasticsearch-7.14.0/config/elasticsearch.yml
# 在其中添加
thread_pool:
index:
queue_size: 4000
search:
queue_size: 10000
3、為了更加簡潔的展示界面,我們可以配置Kibana的默認索引為“test”
vim /usr/local/kibana-7.14.0-linux-x86_64/config/kibana.yml
# 在其中添加
kibana.index: “test”
六、總結
本文通過代碼結合,詳細描述了如何搭建ELK。ELK是一個非常實用的工具,它可以幫助我們有效地整合和分析數據,在實際開發中具有非常廣泛的應用。通過本文的介紹,相信讀者已經掌握了ELK的相關知識,但是ELK還有着更加豐富的玩法等待您去挖掘。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/199942.html