標籤:blog http io os ar 使用 for strong sp
http://blog.csdn.net/hijk139/article/details/8308224
業務系統需要收集監控系統日誌,想到了hadoop的flume。經過實驗,雖說功能不算足夠強大,但基本上能夠滿足功能需求。Flume 是一個分布式、可靠和高可用的服務日誌收集工具,能夠和hadoop,hive等配置完成日誌收集,儲存,分析處理等工作,更詳細的介紹可以參見apache網站。下面介紹下簡單的安裝配置方法
1,網上下載flume-ng安裝包,分別部署在收集和接收記錄檔的伺服器上,伺服器上需安裝jdk 1.6以上,
http://flume.apache.org/download.html
tar -zxvf apache-flume-1.3.0-bin.tar.gz
2, 記錄檔接收端端建立conf/flume-conf.properties server端的具體配置如下
從avro source端接收資料,然後寫入到HDFS檔案系統中
[html] view plaincopy
- [[email protected] conf]$ cat flume-conf.properties
- agent.sources = avrosrc
- agent.channels = memoryChanne3
- agent.sinks = hdfsSink
-
- # For each one of the sources, the type is defined
- agent.sources.avrosrc.type = avro
- agent.sources.avrosrc.bind = 172.16.251.1
- agent.sources.avrosrc.port = 44444
-
- # The channel can be defined as follows.
- agent.sources.avrosrc.channels = memoryChanne3
-
- # Each channel‘s type is defined.
- agent.channels.memoryChanne3.type = memory
- agent.channels.memoryChanne3.keep-alive = 10
- agent.channels.memoryChanne3.capacity = 100000
- agent.channels.memoryChanne3.transactionCapacity =100000
-
- # Each sink‘s type must be defined
- agent.sinks.hdfsSink.type = hdfs
- agent.sinks.hdfsSink.channel = memoryChanne3
- agent.sinks.hdfsSink.hdfs.path = /logdata/%{hostname}_linux/%Y%m%d_date
- agent.sinks.hdfsSink.hdfs.filePrefix = %{datacenter}_
- agent.sinks.hdfsSink.hdfs.rollInterval = 0
- agent.sinks.hdfsSink.hdfs.rollSize = 4000000
- agent.sinks.hdfsSink.hdfs.rollCount = 0
- agent.sinks.hdfsSink.hdfs.writeFormat = Text
- agent.sinks.hdfsSink.hdfs.fileType = DataStream
- agent.sinks.hdfsSink.hdfs.batchSize = 10
如果flume和hadoop不是同一使用者,需要注意相關許可權問題
3,日誌收集端的conf/flume-conf.properties server檔案配置,這裡收集二個記錄檔到收集端
[html] view plaincopy
- agent.sources = tailsource-1 tailsource-2
- agent.channels = memoryChannel-1 memoryChannel-2
- agent.sinks = remotesink remotesink-2
-
- agent.sources.tailsource-1.type = exec
- agent.sources.tailsource-1.command = tail -F /tmp/linux2.log
- agent.sources.tailsource-1.channels = memoryChannel-1
-
- agent.sources.tailsource-2.type = exec
- agent.sources.tailsource-2.command = tail -F /tmp/linux2_2.log
- agent.sources.tailsource-2.channels = memoryChannel-2
-
- agent.sources.tailsource-1.interceptors = host_int timestamp_int inter1
- agent.sources.tailsource-1.interceptors.host_int.type = host
- agent.sources.tailsource-1.interceptors.host_int.hostHeader = hostname
-
- agent.sources.tailsource-1.interceptors.timestamp_int.type = org.apache.flume.interceptor.TimestampInterceptor$Builder
-
- #agent.sources.tailsource-1.interceptors = inter1
- agent.sources.tailsource-1.interceptors.inter1.type = static
- agent.sources.tailsource-1.interceptors.inter1.key = datacenter
- agent.sources.tailsource-1.interceptors.inter1.value = BEIJING
-
- agent.sources.tailsource-2.interceptors = host_int timestamp_int inter1
- agent.sources.tailsource-2.interceptors.host_int.type = host
- agent.sources.tailsource-2.interceptors.host_int.hostHeader = hostname
-
- agent.sources.tailsource-2.interceptors.timestamp_int.type = org.apache.flume.interceptor.TimestampInterceptor$Builder
-
- #agent.sources.tailsource-1.interceptors = inter1
- agent.sources.tailsource-2.interceptors.inter1.type = static
- agent.sources.tailsource-2.interceptors.inter1.key = datacenter
- agent.sources.tailsource-2.interceptors.inter1.value = linux2_2
-
- agent.channels.memoryChannel-1.type = memory
- agent.channels.memoryChannel-1.keep-alive = 10
- agent.channels.memoryChannel-1.capacity = 100000
- agent.channels.memoryChannel-1.transactionCapacity =100000
-
- agent.channels.memoryChannel-2.type = memory
- agent.channels.memoryChannel-2.keep-alive = 10
- agent.channels.memoryChannel-2.capacity = 100000
- agent.channels.memoryChannel-2.transactionCapacity =100000
-
- agent.sinks.remotesink.type = avro
- agent.sinks.remotesink.hostname = 172.16.251.1
- agent.sinks.remotesink.port = 44444
- agent.sinks.remotesink.channel = memoryChannel-1
-
- agent.sinks.remotesink-2.type = avro
- agent.sinks.remotesink-2.hostname = 172.16.251.1
- agent.sinks.remotesink-2.port = 44444
- agent.sinks.remotesink-2.channel = memoryChannel-2
4,後台運行
nohup bin/flume-ng agent -n agent -c conf -f conf/flume-conf.properties >1.log &
查看日誌vi flume.log
連接埠串連情況 netstat -an|grep 44444
[[email protected] flume-1.4]$ netstat -an|grep 44444
tcp 0 0 ::ffff:172.16.251.1:44444 :::* LISTEN
5,測試方法
可以使用如下類似的指令碼,定期向記錄檔寫入來進行測試
for i in {1..1000000}; do echo "LINUX2 PRESS ************* Flume log rotation $i" >> /tmp/linux3.log; sleep 0.0001; done
參考資料:
http://flume.apache.org/FlumeUserGuide.html
flume ng 1.3 安裝(轉)