@EVA001
2017-11-03T09:48:12.000000Z
字数 3941
阅读 356
有道云笔记
使用flume完成数据的接收
场景:source是通过tcp发送,chnnel处理过滤字段,sink存在集群中
source[syslogtcp],sink[hdfs]a1.sources = r1a1.sinks = k1a1.channels = c1# Describe/configure the sourcea1.sources.r1.type = syslogtcpa1.sources.r1.port = 12345a1.sources.r1.host =hadoop01a1.sources.r1.channels = c1# Describe the sinka1.sinks.k1.type = hdfsa1.sinks.k1.channel = c1###HDFS的数目路径a1.sinks.k1.hdfs.path = hdfs://hadoop01:9000/flumea1.sinks.k1.hdfs.filePrefix = Sysloga1.sinks.k1.hdfs.round = truea1.sinks.k1.hdfs.roundValue = 1a1.sinks.k1.hdfs.roundUnit = minute# Use a channel which buffers events in memorya1.channels.c1.type = memorya1.channels.c1.capacity = 1000a1.channels.c1.transactionCapacity = 100# Bind the source and sink to the channela1.sources.r1.channels = c1a1.sinks.k1.channel = c1
[hadoop@hadoop01 flume]$ start-all.sh[hadoop@hadoop01 flume]$ hadoop fs -mkdir flume[hadoop@hadoop01 flume]$ hadoop fs -lsdrwxr-xr-x - hadoop supergroup 0 2017-03-12 17:14 flume接收端:bin/flume-ng agent --conf conf --conf-file conf/syslog.conf --name a1 -Dflume.root.logger=INFO,console发送端:telnet hadoop01 12345,,,结果:[hadoop@hadoop01 flume]$ hadoop fs -ls /flume //注意在hadoop下面写文件查看时,文件夹要加“/”Found 13 items-rw-r--r-- 3 hadoop supergroup 177 2017-03-12 18:09 /flume/My_netcat_log.1489313346930-rw-r--r-- 3 hadoop supergroup 224 2017-03-12 18:16 /flume/My_netcat_log.1489313794747-rw-r--r-- 3 hadoop supergroup 185 2017-03-12 17:21 /flume/Syslog.1489310474526-rw-r--r-- 3 hadoop supergroup 149 2017-03-12 17:21 /flume/Syslog.1489310474527[hadoop@hadoop01 flume]$ hadoop fs -ls flume //没有“/”会看不到!!!![hadoop@hadoop01 flume]$[hadoop@hadoop01 flume]$
source[netcat],sink[hdfs]# Describe/configure the sourcea1.sources.r1.type = netcata1.sources.r1.port = 12321a1.sources.r1.bind = hadoop01a1.sources.r1.channels = c1# Describe the sinka1.sinks.k1.type = hdfsa1.sinks.k1.channel = c1###HDFS的数目路径a1.sinks.k1.hdfs.path = hdfs://hadoop01:9000/flumea1.sinks.k1.hdfs.filePrefix = My_netcat_loga1.sinks.k1.hdfs.round = truea1.sinks.k1.hdfs.roundValue = 1a1.sinks.k1.hdfs.roundUnit = minute# Use a channel which buffers events in memorya1.channels.c1.type = memorya1.channels.c1.capacity = 1000a1.channels.c1.transactionCapacity = 100# Bind the source and sink to the channela1.sources.r1.channels = c1a1.sinks.k1.channel = c1接收端:bin/flume-ng agent --conf conf --conf-file conf/netcat.conf --name a1 -Dflume.root.logger=INFO,console发送端:telnet hadoop01 12345,,,结果:[hadoop@hadoop01 flume]$ hadoop fs -ls /flumeFound 13 items-rw-r--r-- 3 hadoop supergroup 177 2017-03-12 18:09 /flume/My_netcat_log.1489313346930-rw-r--r-- 3 hadoop supergroup 224 2017-03-12 18:16 /flume/My_netcat_log.1489313794747[hadoop@hadoop01 flume]$ hadoop fs -ls flume[hadoop@hadoop01 flume]$[hadoop@hadoop01 flume]$
source[http],sink[hdfs]a1.sources = r1a1.sinks = k1a1.channels = c1# Describe/configure the sourcea1.sources.r1.type = httpa1.sources.r1.port = 50000a1.sources.r1.bind = hadoop01a1.sources.r1.channels = c1# Describe the sinka1.sinks.k1.type = hdfsa1.sinks.k1.channel = c1###HDFSa1.sinks.k1.hdfs.path = hdfs://hadoop01:9000/flumea1.sinks.k1.hdfs.filePrefix = Http_loga1.sinks.k1.hdfs.round = truea1.sinks.k1.hdfs.roundValue = 1a1.sinks.k1.hdfs.roundUnit = minute# Use a channel which buffers events in memorya1.channels.c1.type = memorya1.channels.c1.capacity = 1000a1.channels.c1.transactionCapacity = 100# Bind the source and sink to the channela1.sources.r1.channels = c1a1.sinks.k1.channel = c1接收端:bin/flume-ng agent -c conf -f conf/http.conf -n a1 -Dflume.root.logger=INFO,console发送端:[hadoop@hadoop01 flume]$ curl -X POST -d'[{"headers":{"h1":"v1","h2":"v2"},"body":"hello body"}]' http://hadoop01:50000[hadoop@hadoop01 flume]$ curl -X POST -d'[{"headers":{"h1":"v1","h2":"v2"},"body":"asdascfascas"}]' http://hadoop01:50000[hadoop@hadoop01 flume]$ curl -X POST -d'[{"headers":{"h1":"v1","h2":"v2"},"body":"xxxxxxxxxxx"}]' http://hadoop01:50000结果:[hadoop@hadoop01 flume]$ hadoop fs -ls /flumeFound 16 items-rw-r--r-- 3 hadoop supergroup 145 2017-03-12 18:49 /flume/Http_log.1489315734229-rw-r--r-- 3 hadoop supergroup 147 2017-03-12 18:49 /flume/Http_log.1489315785602-rw-r--r-- 3 hadoop supergroup 161 2017-03-12 18:49 /flume/Http_log.1489315785603