ELK 安裝部署實戰 (最新6.4.0版本)


一、實戰背景

  根據公司平台的發展速度,對於ELK日志分析日益迫切。主要的需求有:

  1.用戶行為分析

  2.運營活動點擊率分析

  作為上述2點需求,安裝最新版本6.4.0是非常有必要的,大家可根據本人之前博文ELK實戰得知,之前ELK本人主要采用5.5.2 版本,

但是根據平台發展,5.5.2的功能不能完全滿足我們的需求,所以現在博主與大家一起來對 6.4.0 (目前最新穩定版)版本進行安裝部署。

 

二、ELK安裝部署開始

  大家安裝部署之前,可先參考官方文檔進行部署。(官方參考文檔地址可點擊一下超鏈接)

  注:Elasticsearch 6.4.0 默認安裝了x-pack 安全插件,該插件授權 30天試用。(如過期,則自行選擇購買,或者破解,本方案不提供破解方案)

  Elasticsearch 6.4.0      Kibana 6.4.0     Logstash 6.4.0      Filebeat 6.4.0

 1、安裝 Elasticsearch 

  1.1、下載安裝Elasticsearch 6.4.0

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.0.tar.gz
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.0.tar.gz.sha512

# 當shasum命令不存在時,可執行命令安裝 yum install perl-Digest-SHA shasum -a 512 -c elasticsearch-6.4.0.tar.gz.sha512
tar -xzf elasticsearch-6.4.0.tar.gz
cd elasticsearch-6.4.0/ 

   2.1、配置Elasticsearch 集群

    2.1.1 配置服務器hosts

    由於模擬生產環境,提升計算能力,跨主機集群配置為優選

    #1.配置集群之前先配置每台節點主機hosts,下圖以測試環境為例:

    配置 es-node1 es-node2 兩台主機名稱, es-node1為本機主機 ,如若增加主機節點,可配置es-node3 …,elasticsearch可配置上千節點作為集群服務節點。

vi /etc/hosts

192.168.30.21  es-node1
192.168.30.22  es-node2
192.168.30.23  es-node3

   2.1.2 配置Elasticsearch

   A.配置es-node1節點集群配置,如下配置 node.master:true 表示為主節點,node.data:true 表示主節點也作為數據節點

vi config/elasticsearch.yml

cluster.name: my_es_cluster
node.name: es-node1

path.data: /data/elk/es/data
path.logs: /data/elk/es/logs
http.cors.enabled:
true http.cors.allow-origin: "*" node.master: true node.data: true
# 配置白名單 0.0.0.0表示其他機器都可訪問
network.host: 0.0.0.0
transport.tcp.port: 9300
# tcp 傳輸壓縮
transport.tcp.compress: true
http.port: 9200
discovery.zen.ping.unicast.hosts: ["es-node1","es-node2","es-node3"]

    B.配置es-node2節點集群配置

vi config/elasticsearch.yml

cluster.name: my_es_cluster
node.name: es-node2
path.data: /data/elk/es/data
path.logs: /data/elk/es/logs
http.cors.enabled: true 
http.cors.allow
-origin: "*"
node.master:
false
node.data:
true

# 配置白名單 0.0.0.0表示其他機器都可訪問
network.host: 0.0.0.0
transport.tcp.port: 9300
# tcp 傳輸壓縮
transport.tcp.compress: true
http.port: 9200
discovery.zen.ping.unicast.hosts: ["es-node1","es-node2","es-node3"]

  C.配置es-node3節點集群配置

vi config/elasticsearch.yml

cluster.name: my_es_cluster
node.name: es-node3
path.data: /data/elk/es/data
path.logs: /data/elk/es/logs
http.cors.enabled: true 
http.cors.allow
-origin: "*"
node.master:
false
node.data:
true
# 配置白名單 0.0.0.0表示其他機器都可訪問
network.host: 0.0.0.0
transport.tcp.port: 9300
# tcp 傳輸壓縮
transport.tcp.compress: true
http.port: 9200

discovery.zen.ping.unicast.hosts: ["es-node1","es-node2","es-node3"]

  2.1.3 啟動elasticsearch

  A.啟動elasticsearch服務之前,需先配置es用戶組和es用戶(由於es安全因素)

groupadd es              #增加es組
useradd es –g es –p pwd  #增加es用戶並附加到es組
chown -R es:es elasticsearch-6.4.0 #分配es的目錄訪問權限
su –es                  #切換es用戶

  B.啟動命令

/tools/elk/elasticsearch-6.4.0
./bin/elasticsearch

  C.第一次啟動將遇到問題

  ERROR: [2] bootstrap checks failed

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

#切換到root用戶修改
vi /etc/security/limits.conf

#在最后面追加
es hard nofile 65536
es soft nofile 65536

#修改后重新登錄es賬號,使用命令查看上面設置是否成功,結果為65536則成功
ulimit -Hn

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

#切換到root用戶
vi /etc/sysctl.conf

#在最后追加
vm.max_map_count=262144

#使用 sysctl -p 查看修改結果
sysctl -p

   D.解決以上問題,則先啟動 數據節點,最后啟動主節點

/tools/elk/elasticsearch-6.4.0
./bin/elasticsearch

  F.當所有節點啟動成功后,在主節點服務器執行以下curl命令,如下圖所示,標識Elasticsearch集群啟動成功。

curl http://localhost:9200/_nodes/process?pretty

 

 2、安裝 Kibana

  2.1 下載安裝Kibana

wget https://artifacts.elastic.co/downloads/kibana/kibana-6.4.0-linux-x86_64.tar.gz
https://artifacts.elastic.co/downloads/kibana/kibana-6.4.0-linux-x86_64.tar.gz.sha512
shasum -a 512 kibana-6.4.0-linux-x86_64.tar.gz.sha512
tar -xzf kibana-6.4.0-linux-x86_64.tar.gz 
mv kibana-6.4.0-linux-x86_64/ kibana-6.4.0
cd kibana
-6.4.0/

  2.2 配置kibana

vi ./config/kibana.yml

server.host: "192.168.30.21"

  2.3 啟動kibana

./bin/kibana

  2.4 訪問kibana,如下圖所示,表示啟動成功

http://192.168.30.21:5601

 

  3、安裝 Logstash 與 Filebeat

 3.1 下載安裝Logstash和Filebeat

# Logstash
wget https://artifacts.elastic.co/downloads/logstash/logstash-6.4.0.tar.gz
wget https://artifacts.elastic.co/downloads/logstash/logstash-6.4.0.tar.gz.sha512
shasum -a 512 logstash-6.4.0.tar.gz.sha512
tar -xzf logstash-6.4.0.tar.gz
cd
logstash-6.4.0

# Filebeat
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.4.0-linux-x86_64.tar.gz
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.4.0-linux-x86_64.tar.gz.sha512
shasum -a 512 filebeat-6.4.0-linux-x86_64.tar.gz.sha512

tar -xzf
filebeat-6.4.0-linux-x86_64.tar.gz
mv
filebeat-6.4.0-linux-x86_64 filebeat-6.4.0
cd
filebeat-6.4.0

   3.2 配置Logstash、Filebeat (最新版與5.5.2版本有差異,最新版引入module的概念,具體查看官方文檔)

  官方參考地址:https://www.elastic.co/guide/en/logstash/6.4/advanced-pipeline.html

  Filebeat + Kafka + Logstash方案地址(可參考): https://www.cnblogs.com/woodylau/p/9488339.html

  在本篇博文,將僅說明 Logstash與Filebeat的交互,采集日志,該交互參考了以上官方文檔。采集nginx日志。

# Filebeat.yml
filebeat.prospectors:
- type: log
  paths:
    - /path/to/file/logstash-tutorial.log 
multiline.pattern: ^\[
  multiline.negate: true
  multiline.match: after output.logstash: hosts: [
"localhost:5044"]
# Logstash-test.yml
cd
logstash-6.4.0
vi logstash_test.conf

input { beats { port
=> "5044" } } filter { grok { match => { "message" => "%{COMBINEDAPACHELOG}"} } geoip { source => "clientip" } } output { elasticsearch { hosts => [ "localhost:9200" ] } }

     3.3 啟動Logstash、Filebeat 

#后台啟動 filebeat
nohup ./filebeat -c ./filebeat.yml &

#啟動Logstash
nohup ./bin/logstash -f logstash-test.conf &


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM