從〇開始ELK之旅

概要:
在CentOS-7上搭建Filebeat+Logstash+Elasticsearch+kibana環

1.1 安裝elasticsearch

首先去elastic官網下載安裝包,當然也可以在線安裝(可能會比較慢)。
在這裏插入圖片描述

elasticsearch不能使用root用戶啓動,所以切換test[管理員]用戶來進行安裝

在/usr/local/目錄下新建 sourcepackage目錄,用來存放安裝包
使用xftp將下載好的安裝包上傳到該目錄
在這裏插入圖片描述

在/usr/local/目錄下創建elastic目錄,作爲elastic生態軟件的安裝目錄

sudo mkdir elastic

將elasticsearch-7.4.2-linux-x86_64.gz解壓到elastic目錄

sudo tar -zxvf sourcepackage/elasticsearch-7.4.2-linux-x86_64.gz  -C elastic/

在這裏插入圖片描述

爲了避免啓動報錯,啓動之前先配置一下,切換到root用戶:
1.編輯 /etc/security/limits.conf:
nofile: 每個用戶打開最大文件數的限制
nproc: 每個用戶創建的進程數的限制

vi /etc/security/limits.conf

在文件尾追加如下內容:

* soft nofile 65536
* hard nofile 65536
* soft nproc 4096
* hard nproc 4096

2.編輯 /etc/profile:

vi /etc/profile

在文件尾追加如下內容:

ulimit -SHn 65536

刷新配置:source /etc/profile

3.虛擬內存配置

vi /etc/sysctl.conf 

在文件尾追加如下內容:

vm.max_map_count=655360

並執行命令:sysctl -p


使用默認配置,啓動elasticsearch
可能需要先修改權限

cd elastic/elasticsearch-7.4.2/

sudo chown -R test elasticsearch-7.4.2/

bin/elasticsearch

啓動完成後,查看是否啓動成功

curl 'http://localhost:9200/?pretty'

在這裏插入圖片描述
看到如上圖所示內容,說明elasticsearch啓動完成,但是此時僅限本機訪問,顯然是不行的,必須要讓其他主機也能訪問,修改配置文件:

vi /usr/local/elastic/elasticsearch-7.4.2/config/elasticsearch.yml

在Network裏面,改成如圖配置:
在這裏插入圖片描述
在Discovery裏面至少要打開一個配置:
在這裏插入圖片描述
否則會報錯:

at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

配置好後,可以在宿主機訪問了
在這裏插入圖片描述

1.2 安裝Logstash

官網下載安裝包—》上傳文件—》解壓—》配置—》啓動。
1.配置管道

cd /usr/local/elastic/logstash-7.4.2/config
vi mypipeline.conf

在文件中輸入:

input {
  beats {
    port => 5044
    codec => "json"
  }
}
output {
  elasticsearch { hosts => ["localhost:9200"] }
  stdout { codec => rubydebug }
}

【此處以filebeat作爲輸入源,elasticsearch作爲輸出端,後面還需要安裝filebeat】

2.配置jdk
elasticsearch自帶了jdk,所以不需要配置。爲了不影響全局環境變量,這裏只設置elastic的jdk。
編輯腳本:

vi /usr/local/elastic/logstash-7.4.2/bin/logstash.lib.sh

在文件開頭加入如下內容:

export JAVA_CMD="/usr/local/elastic/jdk1.8.0_231/bin/"
export JAVA_HOME="/usr/local/elastic/jdk1.8.0_231/"

3.啓動

/usr/local/elastic/logstash-7.4.2/bin/logstash -f /usr/local/elastic/logstash-7.4.2/config/mypipeline.conf --config.reload.automatic

在這裏插入圖片描述
看到輸出這個內容,啓動成功。

在瀏覽器端訪問 http://192.168.135.11:9200/_cat/indices?v 可以看到有logstash的索引:
在這裏插入圖片描述


1.3 安裝Filebeat

官網下載安裝包—》上傳文件—》解壓—》配置—》啓動。

編輯配置文件:

vim /usr/local/elastic/filebeat-7.4.2/filebeat.yml
  1. 配置源日誌文件路徑
    在這裏插入圖片描述
    2.配置輸出
    默認使用elasticsearch作爲輸出,註釋默認配置,此處我們使用Logstash作爲輸出:
    在這裏插入圖片描述
    3.啓動
/usr/local/elastic/filebeat-7.4.2/filebeat -e -c /usr/local/elastic/filebeat-7.4.2/filebeat.yml -d "publish"

1.4 安裝Kibana

官網下載安裝包—》上傳文件—》解壓—》配置—》啓動。

編輯配置文件:

vim /usr/local/elastic/kibana-7.4.2/config/kibana.yml

1.配置elasticsearch地址:
在這裏插入圖片描述
2.想要通過局域網的其他主機訪問kibana,還需要修改server.host配置:
在這裏插入圖片描述

3.啓動

/usr/local/elastic/kibana-7.4.2/bin/kibana -c /usr/local/elastic/kibana-7.4.2/config/kibana.yml --allow-root

啓動成功可以看到如下內容:
在這裏插入圖片描述

在這裏插入圖片描述
接下來就可以開始配置kibana圖形化日誌分析了

發佈了2 篇原創文章 · 獲贊 2 · 訪問量 1041
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章