logstash_forward+flume+elasticsearch+kibana日誌收集框架

    最開始架構定的是採用elk來作日誌的收集,可是測試一段時間後,因爲logstash的性能不好,對cpu和內存消耗很大,放棄了logstash。爲何沒有直接使用flume的agent來收集日誌,這主要是根據實際的需求,衆所周知,flume對目錄的收集沒法針對文件的動態變化,在傳完文件以後,將會修改文件的後綴,變爲.COMPLETED,不管是收集應用日誌仍是系統日誌,咱們都不但願改變原有的日誌文件,最終收集日誌使用了用go開發的更輕量級的logstash_forward,logstash_forward功能比較單一,目前只能用來收集文件。linux

1.安裝logstash-forwarder。git

https://github.com/elasticsearch/logstash-forwarder github

2.flume安裝很簡單,解壓包便可。shell

3.安裝elasticsearch,測試只安裝es單節點apache

下載https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.3.2.tar.gz tomcat

tar zxf elasticsearch-1.3.2.tar.gz

cd elasticsearch-1.3.2/

cd config 
能夠看到elasticsearch.yml,logging.yml兩個文件,若沒有請建立。

vi elasticsearch.yml,修改集羣名稱

cluster.name: elasticsearch

啓動elasticsearch,bin/elasticsearch

安裝elasticsearch head
bin/plugin -install mobz/elasticsearch-head

http://master:9200/_plugin/head/架構

4. 安裝kibana
elasticsearch

下載地址 : https://www.elastic.co/products/kibana oop

將kibana-4.1.1-linux-x64.tar.gz解壓到apache或tomcat下,修改elasticsearch_url,性能

cd kibana-4.1.1-linux-x64
vi config/kibana.yml

elasticsearch_url: "http://master:9200"

啓動kibana,bin/kibana

頁面:http://master:5601

5. 架構圖

經測試,單臺agent,入庫速率能夠達到約1.5w條/s。

在壓測的過程當中,agent批量發送的數據量大的時候,會致使flume OOM,調整flume JVM 啓動參數

vi bin/flume-ng

JAVA_OPTS="-Xms2048m -Xmx2048m"

flume中心節點的配置:

# The configuration file needs to define the sources,
# the channels and the sinks.
# Sources, channels and sinks are defined per agent,
# in this case called 'agent'


a1.sources = r1
a1.sinks = k1 k2
a1.channels = c1
#sinks group
a1.sinkgroups = g1

# For each one of the sources, the type is defined
a1.sources.r1.type = http
a1.sources.r1.bind = 192.168.137.118
a1.sources.r1.port = 5858

# The channel can be defined as follows.
a1.channels.c1.type = SPILLABLEMEMORY
a1.channels.c1.checkpointDir=/home/hadoop/.flume/channel1/file-channel/checkpoint
a1.channels.c1.dataDirs=/home/hadoop/.flume/channel1/file-channel/data
a1.channels.c1.keep-alive = 30

# Each sink's type must be defined
# k1 sink
a1.sinks.k1.channel = c1
a1.sinks.k1.type = avro
# connect to CollectorMainAgent
a1.sinks.k1.hostname = 192.168.137.119
a1.sinks.k1.port = 5858
# k2 sink
a1.sinks.k2.channel = c1
a1.sinks.k2.type = avro
# connect to CollectorBackupAgent
a1.sinks.k2.hostname = 192.168.137.120
a1.sinks.k2.port = 5858

a1.sinkgroups.g1.sinks = k1 k2
# load_balance type
a1.sinkgroups.g1.processor.type = load_balance
a1.sinkgroups.g1.processor.backoff   = true
a1.sinkgroups.g1.processor.selector  = ROUND_ROBIN

a1.sources.r1.channels = c1

參考文檔:

http://blog.qiniu.com/archives/3928

http://mp.weixin.qq.com/s?__biz=MzA5OTAyNzQ2OA==&mid=207036526&idx=1&sn=b0de410e0d1026cd100ac2658e093160&scene=23&srcid=10228P1jGvZC20dC2FGAdoqh#rd

相關文章
相關標籤/搜索