Hello,大家好,今天將給大家帶來ELK的安裝和部署等相關內容。
ELK是Elasticsearch+Logstash+Kibana的縮寫。
E負責索引,存儲,搜索,L負責收集,K則負責的是展現。
Elasticsearch 是一個開源的分佈式 RESTful 搜索和分析引擎,能夠解決越來越多不同的應用場景。
Logstash 是開源的服務器端數據處理管道,能夠同時從多個來源採集數據,轉換數據,然後將數據發送到您最喜歡的 “存儲庫” 中。
Kibana 是通向 Elastic 產品集的窗口, 它可以在 Elasticsearch 中對數據進行視覺探索和實時分析。
一、下載
https://www.elastic.co/downloads
Elastic官方下載地址,之前已經在window系統下安裝使用過,本次在linux服務器上進行搭建。
window下可以直接下載zip包,解壓即可用,真正的開箱即用,確實很強。
Linux環境下載tar.gz包
這裏我們下載好了會是這樣子的:
二、安裝
安裝前,我們確保linux環境已經安裝了jdk1.8+
1.Elasticsearch安裝
進入文件目錄,直接解壓elasticsearch-6.5.1.tar.gz
tar -xzf elasticsearch-6.5.1.tar.gz
解壓之後我們還需要做一些基本配置,才能正常訪問到。
進入elasticsearch配置文件目錄
cd elasticsearch-6.5.1/config/
vi elasticsearch.yml
1.修改Cluster,定義集羣名稱
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: es-cluster
2.修改Node,定義節點名稱
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
3.修改Paths,定義數據存儲目錄和日誌存儲目錄
在/data目錄下新建es/data和es/logs文件夾
注:在創建文件夾目錄的時候一定要控制好文件夾權限
附文件夾權限修改命令:
xxx爲你的用戶名
sudo chown xxx:root $dir
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /data/es/data
#
# Path to log files:
#
path.logs: /data/es/logs
4.修改Memory,定義是否鎖定內存,一般都設置爲false
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
5.修改Network,定義外部訪問路徑和端口
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 服務器IP地址
#
# Set a custom port for HTTP:
#
http.port: 9200
修改以上配置之後就可以啓動了。
注:因爲是單機配置,所以Discovery不需要配置
cd elasticsearch-6.5.1/bin/ #進入bin目錄
./elasticsearch #普通執行啓動命令
因爲我們需要後臺運行,所以我們用nohup來啓動
nohup ./elasticsearch >> /data/es/logs/es.log &
#這樣就可以在後臺運行elasticsearch,並且日誌輸出到/data/es/logs/es.log
啓動後我們可以直接通過 [服務器IP:9200]通過瀏覽器訪問
2.Kibana安裝
kibana安裝也很簡單,安裝三部曲:
1.解壓
tar -xzf kibana-6.5.1-linux-x86_64.tar.gz
2.配置
cd kibana-6.5.1-linux-x86_64/config/
vi kibana.yml
列舉幾個關鍵修改配置,更多配置參考:
server.port: 5601
server.host: "服務器IP"
server.name: "kibana"
elasticsearch.url: "http://ES服務IP:9200" #上面你的elasticsearch服務地址
elasticsearch.preserveHost: true
kibana.index: ".kibana"
修改後保存
3.啓動
cd /data/elk/kibana-6.5.1-linux-x86_64/bin/
./kibana
同樣的,我們可以用nohup來啓動
你將會看到一堆的這樣的信息:
log [07:56:14.839] [info][status][plugin:[email protected]] Status changed from uninitialized to green - Ready
log [07:56:14.886] [info][status][plugin:[email protected]] Status changed from uninitialized to yellow - Waiting for Elasticsearch
log [07:56:14.889] [info][status][plugin:[email protected]] Status changed from uninitialized to yellow - Waiting for Elasticsearch
.
.
.
log [07:56:15.161] [warning][security] Session cookies will be transmitted over insecure connections. This is not recommended.
[BABEL] Note: The code generator has deoptimised the styling of "/data/elk/kibana-6.5.1-linux-x86_64/node_modules/x-pack/plugins/canvas/canvas_plugin/types/all.js" as it exceeds the max of "500KB".
log [07:56:18.182] [info][status][plugin:[email protected]] Status changed from uninitialized to green - Ready
當你看到[listening]字樣的時候,嘿嘿嘿
log [07:56:36.345] [info][listening] Server running at http://服務IP:5601
log [07:56:37.201] [info][status][plugin:[email protected]] Status changed from yellow to green - Ready
你就可以到瀏覽器輸入 http://服務IP:5601訪問了。
首次訪問會有下面這樣一個歡迎頁,提示說你沒數據,要不要搞點簡單數據玩玩?
隨便你選擇哪一種,我反正選的自己玩。
進入主頁後會是這樣子的
到此,我們kibana也就安裝完成咯!
接下來,我們就一起來探索相對麻煩的Logstash吧!!!Gogogo!
3.Logstash安裝
安裝之前,我們稍微對Logstash進行簡單的瞭解。
Logstash 是開源的服務器端數據處理管道,能夠同時從多個來源採集數據,轉換數據,然後將數據發送到您最喜歡的 “存儲庫” 中。(我們的存儲庫當然是 Elasticsearch)
Logstash安裝很簡單,複雜的是配置!
1.解壓
tar -xzf logstash-6.5.1.tar.gz
2.配置
Logstash可以說核心部分就是配置了
最難的也是配置!
簡單來說,Logstash的配置分爲三部分。
一、輸入
輸入,顧名思義就是日誌來源。Logstash有很多的輸入插件,本文將會以S3爲例。
二、解析/過濾器
解析,是把日誌進行過濾,篩選,解析等。本文會用到mutate,ruby,date,json等。
三、輸出/存儲
輸出,比較簡單,我們既然說到ELK,那麼當然是輸出存儲到Elasticsearch。
3.啓動
配置完成後,我們啓動Logstash
cd /data/elk/logstash-6.5.1/bin/
./logstash
如果你配置好了輸入和輸出(過濾不是必須設置項),那麼你將會在kibana中看到對應的索引數據了。
進入kibana中,可以看到在Index Management中會存在你輸出的幾個索引文件
進入Index Patterns中,添加索引:
如下圖所示,創建索引,成功後我們就可以在Discover等模塊進行日誌查詢了。
由於數據敏感,一些數據部分進行打碼處理,請諒解。
至此,ELK的安裝部署就完成了。
關於Logstash的配置部分,我原本是打算在這篇文章一起進行一些說明,考慮篇幅問題,我打算後面單獨寫一篇文章來進行說明。
那麼,本次分享就到這裏吧
大家如果有什麼問題歡迎留言^_^
如果有興趣瞭解更多,可以關注我的公衆號:tanjava