使用Flume監(jiān)聽日志變化
進(jìn)入到flume的conf目錄下返奉,創(chuàng)建文件船万,進(jìn)行配置
[root@mini1 ~]# cd apps/apache-flume-1.6.0-bin/conf/
[root@mini1 conf]# ll
總用量 28
-rw-r--r--. 1 501 games 1661 5月 9 2015 flume-conf.properties.template
-rw-r--r--. 1 501 games 1110 5月 9 2015 flume-env.ps1.template
-rw-r--r--. 1 501 games 1214 5月 9 2015 flume-env.sh.template
-rw-r--r--. 1 501 games 3107 5月 9 2015 log4j.properties
-rw-r--r--. 1 root root 487 10月 19 14:34 netcat-logger.conf
-rw-r--r--. 1 root root 507 10月 19 01:57 spool-logger.conf
-rw-r--r--. 1 root root 1271 10月 19 15:11 tail-hdfs.conf
[root@mini1 conf]# vi netcat-logger.conf
# example.conf: A single-node Flume configuration
# Name the components on this agent
#給那三個(gè)組件取個(gè)名字
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
## exec表示flume回去調(diào)用給的命令酸役,然后從給的命令的結(jié)果中去拿數(shù)據(jù)
a1.sources.r1.type = exec
## 使用tail這個(gè)命令來讀數(shù)據(jù)
a1.sources.r1.command = tail -F /opt/test.log
a1.sources.r1.channels = c1
# Describe the sink 日志下沉到log4j,打印在屏幕上
a1.sinks.k1.type = logger
# Use a channel which buffers events in memory
#下沉的時(shí)候是一批一批的, 下沉的時(shí)候是一個(gè)個(gè)event
Channel參數(shù)解釋:
#capacity:默認(rèn)該通道中最大的可以存儲(chǔ)的event數(shù)量 1000條數(shù)據(jù)(1000個(gè)event,source拿到的數(shù)據(jù)是封裝成event事件的)
#trasactionCapacity:每次最大可以從source中拿到或者送到sink中的event數(shù)量
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
配置好了就可以啟動(dòng)了
[root@mini1 apache-flume-1.6.0-bin]# bin/flume-ng agent --conf conf --conf-file conf/netcat-logger.conf --name a1 -Dflume.root.logger=INFO,console
Warning: JAVA_HOME is not set!
...
2017-10-20 05:00:13,317 (conf-file-poller-0) [INFO - org.apache.flume.node.Application.startAllComponents(Application.java:173)] Starting Sink k1
2017-10-20 05:00:13,318 (conf-file-poller-0) [INFO - org.apache.flume.node.Application.startAllComponents(Application.java:184)] Starting Source r1
2017-10-20 05:00:13,320 (lifecycleSupervisor-1-3) [INFO - org.apache.flume.source.NetcatSource.start(NetcatSource.java:150)] Source starting
2017-10-20 05:00:13,350 (lifecycleSupervisor-1-3) [INFO - org.apache.flume.source.NetcatSource.start(NetcatSource.java:164)] Created serverSocket:sun.nio.ch.ServerSocketChannelImpl[/192.168.25.127:44444]
通過寫一個(gè)死循環(huán)往test.log中寫數(shù)據(jù)的方式模式日志文件增長
編寫shell腳本栗竖,模擬日志增長變化癣漆。
[root@hadoop1 flumedata]# cd /home/tuzq/software/flumedata
[root@hadoop1 flumedata]# while true
>do
> date >> test.log
> sleep 2
> done
查看日志變化
[root@hadoop1 ~]# cd /home/tuzq/software/flumedata/
[root@hadoop1 flumedata]# ls
access.log error.log test.log
[root@hadoop1 flumedata]# tail -f test.log
2017年 06月 13日 星期二 22:02:22 CST
2017年 06月 13日 星期二 22:02:24 CST
2017年 06月 13日 星期二 22:02:26 CST
2017年 06月 13日 星期二 22:02:28 CST
2017年 06月 13日 星期二 22:02:30 CST
2017年 06月 13日 星期二 22:02:32 CST
通過上面的文件维咸,可以看到test.log在不停的追加數(shù)據(jù)。
Flume的使用(三)
采集數(shù)據(jù)到hdfs
這里要添加的配置文件里面的采集源和下沉地就都有變化了惠爽。
[root@mini1 conf]# vi tail-hdfs.conf
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
#exec 指的是命令
# Describe/configure the source
a1.sources.r1.type = exec
#F根據(jù)文件名追中, f根據(jù)文件的nodeid追中
a1.sources.r1.command = tail -F /opt/test.log
a1.sources.r1.channels = c1
# Describe the sink
#下沉目標(biāo)
a1.sinks.k1.type=hdfs
a1.sinks.k1.channel=c1
a1.sinks.k1.hdfs.useLocalTimeStamp=true
a1.sinks.k1.hdfs.path=/flume/testout9/
a1.sinks.k1.hdfs.filePrefix=cmcc
a1.sinks.k1.hdfs.minBlockReplicas=1
a1.sinks.k1.hdfs.fileType=DataStream
a1.sinks.k1.hdfs.writeFormat=Text
a1.sinks.k1.hdfs.rollInterval=0
a1.sinks.k1.hdfs.rollSize=10240
a1.sinks.k1.hdfs.rollCount=0
a1.sinks.k1.hdfs.idleTimeout=0
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
flume+kafka
spooldir.sources= eventDir
spooldir.channels= memoryChannel
spooldir.sinks= eventHDFS
spooldir.channels.memoryChannel.type= memory
spooldir.channels.memoryChannel.capacity= 10000
spooldir.channels.memoryChannel.transactioncapacity= 1000000
spooldir.sources.eventDir.type=exec
spooldir.sources.eventDir.command=tail -F /opt/log.txt
spooldir.sinks.eventHDFS.type = org.apache.flume.sink.kafka.KafkaSink
spooldir.sinks.eventHDFS.topic = orderMq
spooldir.sinks.eventHDFS.brokerList = hadoop01:9092,hadoop02:9092,hadoop03:9092
spooldir.sources.eventDir.channels= memoryChannel
spooldir.sinks.eventHDFS.channel= memoryChannel
參考
https://blog.csdn.net/zengmingen/article/details/65444823