前提條件
安裝jdk
liunx安裝jdk教程:https://blog.csdn.net/qq_42670220/article/details/90753244
1.下載下傳ELK安裝包
版本:6.4.0
百度雲連結:https://pan.baidu.com/s/1Uw7MKa2sSAZbsN9LuFCFHw
提取碼:ycqn
第一次搭建的小夥伴一定要注意,下載下傳最新版本的ELK時,記得考慮elasticsearch版本與kibana、logstash相容的問題,樓主已采坑;
建立放ELK檔案夾
mkdir /usr/local/elk
下載下傳完後,将檔案放入檔案夾進行解壓
解壓檔案
tar -zxvf kibana-6.4.0-linux-x86_64.tar.gz
tar -zxvf logstash-6.4.0.tar.gz
tar -zxvf elasticsearch-6.4.0.tar.gz
2.Elasticsearch配置及啟動
解壓後進入config目錄 ,編輯配置檔案
cd /usr/local/elk/elasticsearch-6.4.0/config
vi elasticsearch.yml
在檔案最後面加入以下代碼
network.host: 0.0.0.0
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
注意,root使用者是不能直接啟動elasticsearch的,需要建立使用者,然後切換使用者去啟動elasticsearch,如下:
- 建立elsearch使用者組及elsearch使用者
groupadd elsearch
useradd elsearch -g elsearch -p elasticsearch
- 更改elasticsearch-6.4.2檔案夾及内部檔案的所屬使用者及組為elsearch:elsearch
cd切換到elasticsearch-6.4.2的父路徑下
chown -R elsearch:elsearch elasticsearch-6.4.2
- 切換到elsearch使用者再啟動
su elsearch
cd elasticsearch-6.4.2/bin
sh elasticsearch &
至此,elasticsearch配置啟動完畢
啟動報錯,bootstrap checks failed解決方案:https://blog.csdn.net/qq_36218267/article/details/104203661
可以在浏覽器輸入url: 伺服器外網ip:9200 檢視是否成功啟動:
如果通路失敗,可以看看是否端口沒有開放:檢視端口是否開放及解決方案https://blog.csdn.net/qq_36218267/article/details/104203799
3.Kibana配置
先切回root,指令:su root,然後進入kibana配置檔案夾
cd /usr/local/elk/kibana-6.4.0-linux-x86_64/config
vi kibana.yml 編輯配置檔案,在最後面加上如下配置:
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.url: "http://localhost:9200"
kibana.index: ".kibana"
cd 進入bin目錄
sh kibana & 啟動kibana
啟動完畢,可以浏覽器輸入url: 伺服器外網ip:5601 檢視是否成功啟動:
4.Logstash配置啟動
cd /usr/local/elk/logstash-6.4.0/bin 進入bin目錄
建立檔案 vi logstash1.conf ,寫入内容(監聽日志):
input {
file {
path => "/opt/logs/*.log"
start_position => beginning
}
}
filter {
}
output {
elasticsearch {
hosts => "localhost:9200"
}
}
啟動logstash:sh logstash -f logstash1.conf &
完了在kibana可以看到同步過去的資料,我的是這樣的
至此,elk基本內建完畢!