1. 程式人生 > >ELK環境的部署與安裝

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]

解決辦法

# 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環境的基本操作,僅供參考。


參考文獻