ELK環境的部署與安裝

ELK簡介

Elasticsearch:是一個高度可擴展的開源全文搜索和分析引擎。能夠快速,實時的存儲,搜索和分析大量數據,通常用做底層引擎技術。

Kibana:是一個開源分析和可視化平臺,是進入Elastic Stack的窗口,可以在Elasticsearch中對程序的數據進行可視化探索和實時分析,旨在與Elasticsearch協同工作。
使用Kibana搜索,查看和與存儲在Elasticsearch索引中的數據進行交互,可以輕鬆執行數據分析,並在各種表格,圖標和地圖中查看數據,基於瀏覽器的界面能夠快速創建和共享動態儀表板

Logstash:是一個具有實時功能的開源數據收集引擎。Logstash可以動態統一來自不同來源的數據,並將數據標準化到所在的目錄文件中
1.水平和擴展的數據處理管道,具有強大的Elasticsearch和Kibana協同作用
2.混合,匹配和編排不同的輸入,過濾器和輸出,以便在管道協調中發揮作用
3.插件豐富,提供能過的靈活性

安裝ELK環境

安裝Elasticsearch

1.下載Elasticsearch

# wget  `https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.3.tar.gz

2.解壓文件

# tar -zxvf elasticsearch-6.4.3.tar.gz 

3.切換到解壓目錄,運行Elasticsearch

# ./bin/elasticsearch

 在後臺運行

# ./bin/elasticsearch -d

4.打開終端,進行測試,能夠返回信息說明運行正常

 curl http://localhost:9200

運行的時候,如果出現下面的現象,可參考之後的解決方案進行嘗試

現象1
在這裏插入圖片描述
這是由於對root用戶的安全保護,需要使用其他的用戶進行授權才能正常啓動

解決辦法

# groupadd elsearch         
# useradd elsearch -g elsearch 
# chown -R elsearch:elsearch  elasticsearch-6.4.3

切換用戶,重新啓動

# su elsearch
# /opt/elasticsearch-6.4.3/bin/elasticsearch

切換用戶,出現下面的情況時,需要修改一下 / 的權限

 SIOCSIFADDR: 不允許的操作
 # chmod 755 /

之後再切換用戶,重新啓動

現象2

解決辦法

修改配置文件,在文件最後加上下面的字段:

# vim ./config/elasticsearch
    xpack.ml.enabled:false

現象3

問題[1]

[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
	 max number of threads [1024] for user [elsearch] likely too low, increase to at least [2048]

解決辦法

# vim /etc/security/limits.conf
	 加入下面的內容
	 * soft nofile 65536
	 * hard nofile 131072
	 * soft nproc 2048
	 * hard nproc 4096
 # vim /etc/security/limits.d/20-nproc.conf
 	 * sort nproc 65535
 	 root soft nproc unlimited

問題[2]

[2]: max virtual memory areas vm.max_map_count [65530] is too low,
     increase to at least [262144]

解決辦法

# vim /etc/sysctl.conf 
	vm.max_map_count=655360
# sysctl -p 

問題[3]

 [3]: system call filters failed to install; check the logs and fix
      your configuration or disable system call filters at your own risk

解決辦法

# vim ./conf/elasticsearch.yml
    bootstrap.memory_lock:false
    bootstrap.system_call_filter:false	
切換用戶 重新啓動elasticsearch

啓動後,沒有問題就說明啓動成功。如果啓動後出現下面的內容

ERROR: [1] bootstrap checks failed
       [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

解決辦法
在配置文件limits.conf的末尾再加上下面的字段

# vim /etc/security/limits.conf
	* hard nofile 65536
	* soft nofile 65536 

之後切換用戶,重新啓動,進行測試,出現端口或者下圖內容說明啓動成功。

# curl http://192.168.10.128:9200
# ss -tnulp | grep 9200

在這裏插入圖片描述

安裝Kibana

安裝的時候需要注意版本號要一致,不然會導致不兼容,在啓動後,就會一致報錯,警告,創建不了索引等等問題。

1.下載與Elasticsearch相同版本號的Kibana

# wget https://artifacts.elastic.co/downloads/kibana/kibana-6.4.3-linux-x86_64.tar.gz

2.解壓文件

# tar vxf kibana-6.4.3-linux-x86_64/

3.修改配置文件,這裏暫時不需要修改配置文件。啓動Kibana

# vim ./config/kibana.yml
# ./bin/kibana

出現下面的信息,表示的是正在進行優化,需要等待,不可關閉

   log   [08:15:25.623] [info][optimize] Optimizing and caching bundles for ml, stateSessionStorageRedirect, status_page, timelion, dashboardViewer, apm and kibana. This may take a few minutes 	  
   log   [08:21:46.222] [info][optimize] Optimization of bundles for ml, stateSessionStorageRedirect, status_page, timelion, dashboardViewer, apm and kibana complete in 380.59 seconds

另開一個終端,當沒有在顯示log的時候,查看5601端口是否開啓,不要關閉剛纔的啓動

# ss -tnulp | grep 5601

之後通過火狐瀏覽器或者谷歌瀏覽器打開網址,能夠正常進入到下圖的狀態表示Kibana安裝完成

# firefox http://192.168.10.128:5602

在這裏插入圖片描述
在這裏插入圖片描述


安裝Logstash

1.下載logstash軟件

# wget https://artifacts.elastic.co/downloads/logstash/logstash-6.4.3.tar.gz

2.解壓文件:

# tar vxf logstash-6.4.3.tar.gz

3.切換目錄

# cd logstash-6.4.3

4.測試是否安裝

# bin / logstash -e " input  { stdin {} } output  { stdout {} }"

出現下面的內容表示安裝成功
Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
[INFO ][logstash.agent  ] Successfully started Logstash API endpoint {:port=>9600}

6.接着在終端下面繼續輸入下面的內容

hello world
能夠顯示下面內容表示安裝成功
hello world
	{
	    "message" => "hello world",
	    "@version" => "1",
		"@timestamp" => 2018-11-15T08:43:54.138Z,
	    "host" => "room0pc99.tedu.cn"
	}

至此,上面的內容就是安裝ELK環境的基本操作,僅供參考。


參考文獻

Elasticsearch文檔
Kibana文檔
Logstash文檔
Elasticsearch集羣部署

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章