编写

编写步骤:

  1. 给Agent三个组件起别名
  2. 指定Agent.sources的源
  3. 指定Agent.sinks的源
  4. 指定Agent.channel的源
  5. 配置关系:r1 —> k1 —> c1

官方案例代码:

  1. # example.conf: A single-node Flume configuration
  2. # Name the components on this agent
  3. # 给Agent三个组件起别名
  4. a1.sources = r1
  5. a1.sinks = k1
  6. a1.channels = c1
  7. # Describe/configure the source
  8. # 选择源
  9. a1.sources.r1.type = netcat
  10. a1.sources.r1.bind = localhost
  11. a1.sources.r1.port = 44444
  12. # Describe the sink
  13. # 选择输出路径
  14. a1.sinks.k1.type = logger
  15. # Use a channel which buffers events in memory
  16. # 选择缓冲区
  17. a1.channels.c1.type = memory
  18. # 当前缓冲区最多能缓冲多少条数据
  19. a1.channels.c1.capacity = 1000
  20. # 数据源一次最多能写多少数据到缓冲区
  21. a1.channels.c1.transactionCapacity = 100
  22. # Bind the source and sink to the channel
  23. # 指定Agent组件关系
  24. a1.sources.r1.channels = c1
  25. a1.sinks.k1.channel = c1

启动程序

flume-ng agent --conf conf --conf-file /home/hadoop/kylin/a.conf --name a1 -Dflume.root.logger=INFO,console

flume-ng:启动
—conf conf —conf-file example.conf:指定配置文件的方式运行
—name a1:Agent名字
-Dflume.root.logger=INFO,console:打印到控制台

telnet:模拟数据源,向端口发送数据
telnet localhost 44444
(安装telnet:sudo yum install -y telnet)