filebeat+kafka+ELK5.4安裝與部署

用ELK打造強大的日誌分析平臺,具體拓撲結構如下:


wKioL1k5A2ejCCqMAAJRKsxLl6M625.png-wh_50


在這裏我們將進行kafka+filebeat+ELK5.4的部署

各軟件版本

jdk-8u131-linux-i586.tar.gz
filebeat-5.4.0-linux-x86_64.tar.gz
elasticsearch-5.4.0.tar.gz
kibana-5.4.0-linux-x86_64.tar.gz
logstash-5.4.0.tar.gz
kafka_2.11-0.10.0.0.tgz

1、JDK安裝配置(略過)


2、ELK安裝與配置

創建ELK用戶,並進行文件解壓

1.elasticsearch配置

[elk@localhost elasticsearch-5.4.0]$ vi config/elasticsearch.yml 
.....
network.host: 192.168.12.109
#
# Set a custom port for HTTP:
#
http.port: 9200

..........

保存,啓動
[elk@localhost elasticsearch-5.4.0]$ nohup bin/elasticsearch &
驗證
#
[elk@localhost elasticsearch-5.4.0]$ curl http://192.168.12.109:9200
{
  "name" : "aCA2ApK",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "Ea4_9kXZSaeDL1fYt4lUUQ",
  "version" : {
    "number" : "5.4.0",
    "build_hash" : "780f8c4",
    "build_date" : "2017-04-28T17:43:27.229Z",
    "build_snapshot" : false,
    "lucene_version" : "6.5.0"
  },
  "tagline" : "You Know, for Search"
}

2、kibana安裝與配置

[elk@localhost kibana-5.4.0-linux-x86_64]$ vi config/kibana.yml 
## Kibana is served by a back end server. This setting specifies the port to use.
server.port: 5601

# Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values.
# The default is 'localhost', which usually means remote machines will not be able to connect.
# To allow connections from remote users, set this parameter to a non-loopback address.
server.host: "192.168.12.109"
..........
# The URL of the Elasticsearch instance to use for all your queries.
elasticsearch.url: "http://192.168.12.109:9200"
..........
[elk@localhost kibana-5.4.0-linux-x86_64]$ nohup bin/kibana &

在瀏覽器訪問  能訪問即可


3、kafka安裝與配置

這裏我們只做單機192.168.12.105部署單節點centos kafka單包單機部署


4、logstah安裝與配置

[elk@localhost logstash-5.4.0]$ vi nginx.conf    這裏新生成一個配置文件

input {
       kafka  {
       codec => "json"
     topics_pattern => "logstash-.*"
     bootstrap_servers => "192.168.12.105:9092"
     auto_offset_reset => "latest"
     group_id => "logstash-g1"
  }


}

filter {
    if "nginx-accesslog" in [tags] {
        grok {
                match => { "message" => "%{IPORHOST:http_host} %{IPORHOST:clientip} - %{USERNAME:remote_user} \[%{HTTPDATE:timestamp}\] \"(?:%{WORD:http_verb} %{NOTSPACE:http_request}(?: HTTP/%{NUMBER:http_version})?|%{DATA:raw_http_request})\" %{NUMBER:response} (?:%{NUMBER:bytes_read}|-) %{QS:referrer} %{QS:agent} %{QS:xforwardedfor} %{NUMBER:request_time:float} %{GREEDYDATA:traceID}"}
        }
        mutate {
                convert => ["status","integer"]
                convert => ["body_bytes_sent","integer"]
                convert => ["request_time","float"]
        }
        geoip {
                source=>"remote_addr"
        }
        date {
                match => [ "timestamp","dd/MMM/YYYY:HH:mm:ss Z"]
        }
        useragent {
                source=>"http_user_agent"
        }
}



    if "tomcat-accesslog"  in [tags] {
        grok {
           match => { "message" => "%{IPORHOST:clientip} \[%{HTTPDATE:timestamp}\] \"(?:%{WORD:http_verb} %{NOTSPACE:http_request}(?: HTTP/%{NUMBER:http_version})?|%{DATA:raw_http_request})\" %{NUMBER:response} (?:%{NUMBER:bytes_read}|-) %{QS:referrer} %{NUMBER:request_time:float} %{GREEDYDATA:traceID}"}
            }
        date {
               match => [ "timestamp","dd/MMM/YYYY:HH:mm:ss Z"]
        }
}
}

output {

    elasticsearch {
      hosts => ["192.168.12.109:9200"]
        index => "logstash-%{type}-%{+YYYY.MM.dd}"
        document_type => "%{type}"
    }

#stdout { codec => rubydebug }
}

保存,並啓動
[elk@localhost logstash-5.4.0]$ nohup bin/logstash -f nginx.conf &

5、filebeat安裝與配置

將filebeat分別拷貝到需要採集的服務器,進行解壓,在這裏我們分別採集Nginx,tomcat日誌

Nginx服務器

[user@localhost filebeat-5.4.0-linux-x86_64]$ vi filebeat.yml 
filebeat.prospectors:
- input_type: log
  paths:
    - /data/programs/nginx/logs/access.log
  tags: ["nginx-accesslog"]
  document_type: nginxaccess
tags: ["nginx-test-194"]
output.kafka:
  enabled: true
  hosts: ["192.168.12.105:9092"]
  topic: logstash-%{[type]}


[user@localhost filebeat-5.4.0-linux-x86_64]$nohup filebeat -c filebeat.yml &

tomcat服務器

[user@localhost filebeat-5.4.0-linux-x86_64]$ vi filebeat.yml
 filebeat.yml 
filebeat.prospectors:
- input_type: log
  paths:
    - /data/tomcat/logs/localhost_access_log*
  tags: ["tomcat-accesslog"]
  document_type: tomcataccess
tags: ["tomcat103"]
output.kafka:
  enabled: true
  hosts: ["192.168.12.105:9092"]
  topic: logstash-%{[type]}
  
[user@localhost filebeat-5.4.0-linux-x86_64]$nohup filebeat -c filebeat.yml &


完成以上,我們的平臺就搭建好了,接下來我們創建索引

輸入:logstash-nginxaccess*

wKiom1k5DQzBatopAAF9YLhIDj0687.png-wh_50

輸入logstash-tomcataccess*

wKioL1k5DQewY4_AAAF4zcmmpqA379.png-wh_50


數據通過filebeat到kafka、ELK成功展示出來

wKioL1k5DgugFwsJAAIU3Bs2DJ0622.png-wh_50


來張炫圖

wKioL1k5DonwjOEZAATWnNWcVFI152.png-wh_50



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