image.png

    1. 安装netcat工具
    2. yum install -y nc
    3. 查看4444端口是否被占用
    4. netstat -tunlp | grep 44444
    5. mkdir apache-flume-1.7.0/job
    6. vim flume-netcat-logger.conf
    7. # Name the components on this agent
    8. a1.sources = r1
    9. a1.channels = c1
    10. a1.sinks = k1
    11. # Describe/configure the source
    12. #source类型
    13. a1.sources.r1.type = netcat
    14. #netcat监听的主机
    15. a1.sources.r1.bind = localhost
    16. #netcat监听的端口号
    17. a1.sources.r1.port = 44444
    18. # Use a channel which buffers events in memory
    19. #channel的类型
    20. a1.channels.c1.type = memory
    21. #channel的总容量为1000个event
    22. a1.channels.c1.capacity = 1000
    23. #参数决定每次Source往channel里面写、每次Sink从channel里面读的最大event条数,需要大于source、sink的batchSize
    24. a1.channels.c1.transactionCapacity = 100
    25. # Describe the sink
    26. #sink类型为logger:输出到控制台
    27. a1.sinks.k1.type = logger
    28. # Bind the source and sink to the channel
    29. a1.sources.r1.channels = c1
    30. a1.sinks.k1.channel = c1
    31. 页面1:开启flume监听端口(--conf/-c:表示配置文件存储在conf/目录
    32. --name/-n:表示给agent起名为a1
    33. --conf-file/-fflume本次启动读取的配置文件是在job文件夹下的flume-telnet.conf文件。
    34. -Dflume.root.logger=INFO,console :-D表示flume运行时动态修改flume.root.logger参数属性值,并将控制台日志打印级别设置为INFO级别。日志级别包括:loginfowarnerror。)
    35. bin/flume-ng agent --conf conf/ --name a1 --conf-file job/flume-netcat-logger.conf -Dflume.root.logger=INFO,console
    36. 或者
    37. bin/flume-ng agent -c conf/ -n a1 -f job/flume-netcat-logger.conf -Dflume.root.logger=INFO,console
    38. 页面2:使用netcat工具向本机的44444端口发送内容:然后可以输入字符串 ctrl+c退出
    39. nc localhost 44444
    40. 之前开启的flume页面1会接受到netcat的输入内容
    41. 2019-09-01 15:41:21,969 (SinkRunner-PollingRunner-DefaultSinkProcessor) [INFO - org.apache.flume.sink.LoggerSink.process(LoggerSink.java:95)] Event: { headers:{} body: 68 61 68 hah }
    42. 2019-09-01 15:42:17,500 (SinkRunner-PollingRunner-DefaultSinkProcessor) [INFO - org.apache.flume.sink.LoggerSink.process(LoggerSink.java:95)] Event: { headers:{} body: 6D 61 7A 68 69 62 69 6E mazhibin }