天天看點

ELK搭建(filebeat、elasticsearch、logstash、kibana)

ELK部署(文章有點兒長,搭建時請到官網将tar包下載下傳好,按步驟可以完成搭建使用)

ELK指的是ElasticSearch、LogStash、Kibana三個開源工具

LogStash是負責資料的收集和過濾處理

ElasticSearch 是一個開源分布式搜尋引擎,負責資料的存儲、檢索和分析

Kibana 是提供可視化的頁面,對資料進行可視化預覽

首先前提安裝好java環境,java1.8

yum -y list java

yum install java-1.8.0-openjdk.x86_64

然後在官方下載下傳ElasticSearch Kibana LogStash包

https://www.elastic.co/cn/downloads

這邊用的版本elasticsearch-6.3.2 Kibana-6.3.2 LogStash-6.3.2

一、對系統參數做調整

vim /etc/security/limits.conf (修改如下内容)

* soft nofile 65536

* hard nofile 65536

* soft nproc 65536

* hard nproc 65536

ELK搭建(filebeat、elasticsearch、logstash、kibana)

vim /etc/security/limits.d/20-nproc.conf (修改如下内容)

* soft nproc  4096

root soft nproc  unlimited

ELK搭建(filebeat、elasticsearch、logstash、kibana)

vim /etc/sysctl.conf  (添加如下内容)

vm.max_map_count = 655360

fs.file-max=655360

ELK搭建(filebeat、elasticsearch、logstash、kibana)

sysctl -p 使内容生效

確定所有生效 必須重新開機伺服器一遍 reboot

二、安裝Elasticsearch

elasticsearch需要建立一個使用者用來啟動

useradd -d /home/els -m els

su els

mkdir -p /home/els/tools/

将tar包放置 /home/els/tools

cd /home/els/tools

tar -xzf elasticsearch-6.3.2.tar.gz

mv elasticsearch-6.3.2 /home/els/

cd /home/els/elasticsearch-6.3.2/

vim config/elasticsearch.yml(修改如下内容)

path.data: /home/els/elasticsearch-6.3.2/data    #自定義 資料存放位址

path.logs: /home/els/elasticsearch-6.3.2/logs   #自定義 日志存放位址

http.cors.enabled: true #開啟跨域通路支援 預設為false

http.cors.allow-origin: "*" #跨域通路允許的域名位址,支援正則

network.host: 0.0.0.0  #任意IP可以通路

chown -R els.els /home/els/elasticsearch-6.3.2

nohup ./bin/elasticsearch &   

浏覽器通路 ip:9200 得到如下内容 便搭建成功

ELK搭建(filebeat、elasticsearch、logstash、kibana)

三、搭建elasticsearch_head

mkdir -p /root/ELK

cd /root/ELK

yum install git npm

git clone https://github.com/mobz/elasticsearch-head.git

cd elasticsearch-head

npm install

nohup npm run start &

然後浏覽器通路ip:9100 連接配接你的Elasticsearch  ip:9200

ELK搭建(filebeat、elasticsearch、logstash、kibana)

四、安裝Logstash

Logstash的安裝同樣如此,可以直接用root使用者 将6.3.2的tar包解壓,進入目錄

Vim /你定義的目錄/logstash-6.3.2/config/test.conf

input {

file{

path => [“/var/log/messages”,] #這可以是個清單 多個Log日志也是可以的

    start_position => "beginning"

}

}

output{

ctdout{

codec => rubydebug #直接輸出到螢幕

}

elasticsearch {

        hosts => ["http://13.1.18.135:9200"]  #同時輸出到elastisearch

        index => "syslog-%{+YYYY.MM.dd}"

        action => "index"

        document_type => "test"

}

cd /你定義的目錄/logstash-6.3.2/

./bin/logstash  -f config/test.conf

ELK搭建(filebeat、elasticsearch、logstash、kibana)

螢幕有輸出,同時浏覽器通路ip:9100,也能看到根據索引的輸出資訊

後期會詳細說Logstash檢索功能以及通過緩存中間件來傳遞資料接收資料

五、安裝kibana

同樣時将tar包解壓到你的目錄下

tar zxvf kibana-6.2.2-darwin-x86_64.tar.gz

cd /你的目錄/kibana-6.2.2-darwin-x86_64

vim config/kibana.yml (修改如下内容)

server.host: "0.0.0.0"

elasticsearch.url: "http://localhost:9200"   #我這裡使用同一台伺服器 不是的話請用IP

nohup ./bin/kibana -H 0.0.0.0 &  #背景啟用

浏覽器通路 ip:5601

ELK搭建(filebeat、elasticsearch、logstash、kibana)

然後到左邊菜單最下方Management 設定索引值

ELK搭建(filebeat、elasticsearch、logstash、kibana)

create Index Patern

輸入 syslog* *比對所有,與之前Logstash中輸出output的index值

ELK搭建(filebeat、elasticsearch、logstash、kibana)
ELK搭建(filebeat、elasticsearch、logstash、kibana)

最後建立

然後到左邊菜單中Discover中檢視資訊

左邊設定目前的索引 ,右上角設定檢索日期,和設定自動更新

ELK搭建(filebeat、elasticsearch、logstash、kibana)

搭建完成

接着以一個資料傳遞方式添加一個filebeat工具 是個輕量級的資料采集 可以直接輸出到Logstash或者elasticsearch

配置同樣簡單

下載下傳filebeat-6.3.2-linux-x86_64.tar.gz

解壓到你的目錄下 (修改下輸入參數和輸出參數)

vim filebeat-6.3.2-linux-x86_64/filebeat.yml

ELK搭建(filebeat、elasticsearch、logstash、kibana)

修改參數請按yml格式

可以輸入多個位址

輸入配置:

參數type , enabled, paths, fields(這個參數傳入Logstash字段,用于判斷)

輸出配置:

output.logstash:

hosts: ["13.1.18.135:5022"] #表示傳輸到主機的5022端口負責接送資料

開啟filebeat  注意-e -c順序

./filebeat -e -c filebeat.yml

#可自行使用

#output.redis:  

# hosts: ["13.1.18.135:6379"]

#  password: '123456'  #到redis.conf的 requirepass 123456 密碼必須配置

#  key: "log_file" #傳輸的鍵值

#  db: 0   #0庫

#  timeout: 5  #逾時時間

輸出配置可以有Elasticsearch,中間件緩存 redis,rabbitmq,kafka等

此時需要修改之前的Logstash中配置檔案的test.conf的input

input {

       beats {

       port => 5022  #開啟5022端口接收資料

      #Filebeat傳來資料

}

}   

#同上的redis配置

#input {

#        redis{

#        port => '6379'

#        host => '13.1.18.135'

#        data_type => "list"

#        type => "log"

#        key => "log_file"

#        db => '0'

#        password => '123456'

#}

重新開機啟動logstash

./bin/logstash  -f config/test.conf

目前的傳輸過程如下圖

ELK搭建(filebeat、elasticsearch、logstash、kibana)

後期需要可以為多個filebeat用于多台伺服器的日志同時采集,elastcsearch也可以設定為多個節點

下篇文章關于logstash的檢索配置

轉載于:https://www.cnblogs.com/Liang-jc/p/9584807.html