前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用flume完成数据的接收

使用flume完成数据的接收

作者头像
ZONGLYN
发布2019-08-08 14:21:28
6310
发布2019-08-08 14:21:28
举报

使用flume完成数据的接收 场景:source是通过tcp发送,chnnel处理过滤字段,sink存在集群中

适合①[注意,syslog需要特定环境,也可用telnet发送数据]

source[syslogtcp],sink[hdfs]
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = syslogtcp
a1.sources.r1.port = 12345
a1.sources.r1.host =hadoop01
a1.sources.r1.channels = c1
# Describe the sink
a1.sinks.k1.type = hdfs
a1.sinks.k1.channel = c1
###HDFS的数目路径
a1.sinks.k1.hdfs.path = hdfs://hadoop01:9000/flume
a1.sinks.k1.hdfs.filePrefix = Syslog
a1.sinks.k1.hdfs.round = true
a1.sinks.k1.hdfs.roundValue = 1
a1.sinks.k1.hdfs.roundUnit = minute
# 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
[hadoop@hadoop01 flume]$ start-all.sh
[hadoop@hadoop01 flume]$ hadoop fs -mkdir flume
[hadoop@hadoop01 flume]$ hadoop fs -ls
drwxr-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]$

适合②[使用telnet来发送数据]

source[netcat],sink[hdfs]
# Describe/configure the source
a1.sources.r1.type = netcat
a1.sources.r1.port = 12321
a1.sources.r1.bind = hadoop01
a1.sources.r1.channels = c1
# Describe the sink
a1.sinks.k1.type = hdfs
a1.sinks.k1.channel = c1
###HDFS的数目路径
a1.sinks.k1.hdfs.path = hdfs://hadoop01:9000/flume
a1.sinks.k1.hdfs.filePrefix = My_netcat_log
a1.sinks.k1.hdfs.round = true
a1.sinks.k1.hdfs.roundValue = 1
a1.sinks.k1.hdfs.roundUnit = minute
# 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
接收端: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 /flume
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
[hadoop@hadoop01 flume]$ hadoop fs -ls flume
[hadoop@hadoop01 flume]$ 
[hadoop@hadoop01 flume]$

适合③[使用curl来发送数据]

source[http],sink[hdfs]
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = http
a1.sources.r1.port = 50000
a1.sources.r1.bind = hadoop01
a1.sources.r1.channels = c1
# Describe the sink
a1.sinks.k1.type = hdfs
a1.sinks.k1.channel = c1
###HDFS
a1.sinks.k1.hdfs.path = hdfs://hadoop01:9000/flume
a1.sinks.k1.hdfs.filePrefix = Http_log
a1.sinks.k1.hdfs.round = true
a1.sinks.k1.hdfs.roundValue = 1
a1.sinks.k1.hdfs.roundUnit = minute
# 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
 
接收端: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 /flume
Found 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
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-03-16,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 适合①[注意,syslog需要特定环境,也可用telnet发送数据]
  • 适合②[使用telnet来发送数据]
  • 适合③[使用curl来发送数据]
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档