socket中接收数据打印到控制台
基本框架图
配置文件
在flume所在的文件夹下创建一个文件夹用来放相关的配置文件
例:vim /opt/flume/conf/myconf/netcat_logger.conf
具体配置内容如下:
# Name the components on this agent
# a1是我们自定义的agent的名字
# a1.sources a1这个agent包含的多个source的名字
# 包含几个组件就写几个名字,名字间用空格隔开
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
# 配置source
a1.sources.r1.type = netcat
#需要去绑定的主机名或IP地址
a1.sources.r1.bind = bd0201
#要绑定的端口号
a1.sources.r1.port = 6666
# Describe the sink
# 配置sink
a1.sinks.k1.type = logger
# Use a channel which buffers events in memory
# 配置channel
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-env.sh.template需要对其进行配置,配置:
export JAVA_HOME=/opt/jdk1.8(自己安装jdk的路径)
进行完以上配置便可进行测试了
启动agent测试
在flume安装目录下执行命令
# flume安装目录下的命令
bin/flume-ng agent \
# flume安装目录下的conf目录,为了让flume找到环境变量胡总和log4j之类的配置
--conf /opt/flume/conf \
# 指定我们自己编写的agent的配置文件
--conf-file /opt/flume/conf/myconf/netcat_logger.conf \
# 指定agent的名字
--name a1 \
# 设置日志级别和输出方式
-Dflume.root.logger=INFO,console
用另外一台主机bd0202去连接bd0201的6666端口,来模拟发送数据
执行命令:
[root@bd0202 ~ ]# nc bd0201 6666