上篇:第1章 Flume概述
1、Flume安装地址
(1)Flume官网地址
http://flume.apache.org/
(2)文档查看地址
http://flume.apache.org/FlumeUserGuide.html
(3)下载地址
http://archive.apache.org/dist/flume/
2、安装部署
(1)1)将apache-flume-1.7.0-bin.tar.gz上传到linux的/usr/local/hadoop目录下
(2)解压apache-flume-1.7.0-bin.tar.gz到/usr/local/hadoop/module目录下
[root@hadoop101 hadoop]# tar -zxvf apache-flume-1.7.0-bin.tar.gz -C /usr/local/hadoop/module/
(3)修改apache-flume-1.7.0-bin的名称为flum-1.7.0
[root@hadoop101 module]# mv apache-flume-1.7.0-bin/ flume-1.7.0/
(4)将flum-1.7.0/conf下的flume-env.sh.template文件修改为flume-env.sh,并配置flume-env.sh文件
[root@hadoop101 module]# cd flume-1.7.0/conf/
[root@hadoop101 conf]# ll
total 16
-rw-r--r-- 1 root root 1661 Sep 26 2016 flume-conf.properties.template
-rw-r--r-- 1 root root 1455 Sep 26 2016 flume-env.ps1.template
-rw-r--r-- 1 root root 1565 Sep 26 2016 flume-env.sh.template
-rw-r--r-- 1 root root 3107 Sep 26 2016 log4j.properties
[root@hadoop101 conf]# mv flume-env.sh.template flume-env.sh
[root@hadoop101 conf]# vim flume-env.sh
#配置jdk路径
export JAVA_HOME=/usr/local/java/jdk/jdk1.8.0_221
(5)准备nc环境
[root@flink102 flume-1.7.0]# yum install -y nc
(6)进入job文件目录编辑创建flume-netcat-logger.conf文件配置
//进入job文件目录
[root@flink102 flume-1.7.0]# cd job/
//job文件目录有
[root@flink102 job]# ll
total 8
-rw-r--r--. 1 root root 1365 Jan 12 05:04 flume-file-hdfs.conf
-rw-r--r-- 1 root root 495 Mar 25 13:10 flume-telnet-logger.conf
//编辑创建flume-telnet-logger.conf
[root@flink102 job]# vim 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
配置文件解析
(7) 启动flume服务
//配置flume环境永久生效
[root@flink102 ~]# vim /etc/profile
//添加参数据
#FLUME_HOME
export FLUME_HOME=/usr/hadoop/module/flume/flume-1.7.0
export PATH=$PATH:$FLUME_HOME/bin
[root@flink102 ~]# source /etc/profile
[root@flink102 flume-1.7.0]# bin/flume-ng agent --conf conf/ --name a1 --conf-file job/flume-netcat-logger.conf -Dflume.root.logger=INFO,console
执行过程
(8) 命令查看是否真有监控44444
[root@flink102 ~]# netstat -nltp|grep 44444
tcp6 0 0 127.0.0.1:44444 :::* LISTEN 9674/java
[root@flink102 ~]#
(9)发送数据与打印数据
//发送数据
[root@flink102 ~]# nc localhost 44444
122
OK
//打印数据
2020-03-28 10:55:11,850 (SinkRunner-PollingRunner-DefaultSinkProcessor) [INFO - org.apache.flume.sink.LoggerSink.process(LoggerSink.java:95)] Event: { headers:{} body: 31 32 32 122 }