一、Flume 安装部署
1.1 安装地址
1、Flume 官网地址
http://flume.apache.org/
2、下载地址
http://archive.apache.org/dist/flume/
3、文档地址
http://flume.apache.org/FlumeUserGuide.html
1.2 安装部署
1、将 apache-flume-1.7.0-bin.tar.gz 上传到服务器的/opt/software 目录下
2、解压 apache-flume-1.7.0-bin.tar.gz 到/opt/module/目录下
[test@hadoop151 software]$ tar -zxvf apache-flume-1.7.0-bin.tar.gz -C /opt/module/
3、修改 apache-flume-1.7.0-bin 的名称为 flume
[test@hadoop151 module]$ mv apache-flume-1.7.0-bin/ flume
4、将 flume/conf 下的 flume-env.sh.template 文件修改为 flume-env.sh,并配置 flume-env.sh 文件
export JAVA_HOME=/opt/module/jdk1.8.0_144
二、入门案例 – 监控端口数据官方案例
2.1 案例介绍
1、案例需求
使用 Flume 监听一个端口,收集该端口数据,并打印到控制台。
2、需求分析
2.2 案例步骤
1、安装 netcat 工具
[test@hadoop151 conf]$ sudo yum install -y nc
2、判断 44444 端口是否被占用
[test@hadoop151 conf]$ sudo netstat -tunlp | grep 44444
3、创建 Flume Agent 配置文件 flume-netcat-logger.conf
(1) 在 flume 目录下创建 job 文件夹并进入 job 文件夹
[test@hadoop151 flume]$ mkdir job
[test@hadoop151 flume]$ cd job/
(2) 在 job 文件夹下创建 Flume Agent 配置文件 flume-netcat-logger.conf
[test@hadoop151 job]$ vim flume-netcat-logger.conf
(3) 在 flume-netcat-logger.conf 文件中添加如下内容
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# 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
4、配置文件解析
注:配置文件来源于官方手册 http://flume.apache.org/FlumeUserGuide.html
5、开启 flume 监听端口
第一种写法:
bin/flume-ng agent --conf conf/ --name a1 --conf-file job/flume-netcat-logger