目录
Flume安装
- 官网下载Flume:http://flume.apache.org/download.html
- 解压:tar -zxvf apache-flume-1.9.0-bin.tar.gz
- 重命名目录:mv apache-flume-1.9.0-bin flume-1.9.0
- 重命名conf目录下的flume-env.sh.template:mv flume-env.sh.template flume-env.sh
- 修改flume-env.sh:
- 修改/etc/profile:
- source /etc/profile
案例一:监听端口
配置文件所需要的参数可以去官网查看,黑体为必选项。
案例分析
- 通过netcat工具向本机的44444端口发送数据
- Flume监听本机的44444端口,通过source端读取数据
- Flume将获取的数据通过sink端写出到控制台
案例步骤
-
每台主机安装netcat:yum install -y nc
-
查看端口44444是否被占用:netstat -tunlp | grep 44444
-
netcat用法:输入 nc -lk 44444 作为服务端,nc host 44444 作为客户端,相互可以通信
-
创建Flume Agent配置文件netcat-flume-logger.conf:
# example.conf: A single-node Flume configuration # Name the components on this agent a1.sources = r1 a1.channels = c1 a1.sinks = k1 # Describe/configure the source a1.sources.r1.type = netcat a1.sources.r1.bind = localhost a1.sources.r1.port = 44444 # Describe the sink a1.sinks.k1.type = logger # 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
配置文件有5个部分,之间用空行隔开
- 给Agent的组件命名。a1是Agent名,r1是sources名,c1是channels名,k1是sinks名。注意单词是有复数的,说明可以有多个组件。
- 配置source。r1这个source的类型是netcat,监听的主机是localhost,监听的端口号是44444。
- 配置sink。k1的类型是logger,输出到控制台。
- 配置channel。c1这个channel的类型是内存,缓存容量是1000个事件(Flume以事件Event为传输单元