一、下载
//wget 下载,安装在 /usr/loca/下面
cd /data1
wget http://mirror.bit.edu.cn/apache/flume/1.9.0/apache-flume-1.9.0-bin.tar.gz
tar -zxcf apache-flume-1.9.0-bin.tar.gz
cp apache-flume-1.9.0-bin /usr/local/
mv apache-flume-1.9.0-bin flume-1.9
二、配置
2.1 配置环境变量
vim /etc/profile
//加入FLUME_HOME 变量
export FLUME_HOME=/usr/local/flume-1.9
export PATH=$PATH:$JAVA_HOME/bin:$HIVE_HOME/bin:$HADOOP_HOME/bin:$ANT_HOME/bin:$FLUME/bin
2.2 配置flume-env.sh 文件 ,在 /usr/local/flume-1.9/conf 目录下面:
export JAVA_HOME=/usr/local/jdk1.8
2.3 进入/usr/local/flume-1.9/bin 目录下:
[root@xx bin]# flume-ng version
Flume 1.9.0
Source code repository: https://git-wip-us.apache.org/repos/asf/flume.git
Revision: d4fcab4f501d41597bc616921329a4339f73585e
Compiled by fszabo on Mon Dec 17 20:45:25 CET 2018
From source with checksum 35db629a3bda49d23e9b3690c80737f9
这样就可以了,下面配一个实例。
三、实例
3.1 在 /usr/local/flume-1.9/conf 目录下面 创建一个配置文件 netcat.conf
vim netcat.conf
//下面加入数据:
#那么我们也给这个三个组件分别取名字
a2.sources = r1
a2.channels = c1
a2.sinks = k1
#定义具体的source内容
#这里是执行命令以及下面对应的具体命令
#这个命令执行后的数据返回给这个source
a2.sources.r1.type = netcat
a2.sources.r1.bind = localhost
a2.sources.r1.port = 44444
#定义具体的channel信息
#我们source定义好了,就要来定义我们的channel
a2.channels.c1.type = memory
a2.channels.c1.capacity = 10000
a2.channels.c1.transactionCapacity = 100
#定义具体的sink信息
#这个logger sink,就是将信息直接打印到控制台
#就是打印日志
a2.sinks.k1.type = logger
#最后来组装我们之前定义的channel和sink
a2.sources.r1.channels = c1
a2.sinks.k1.channel = c1
运行命令:
flume-ng agent -n a2 -c conf -f ../conf/netcat.conf
出现下面 44444的时候 才是成功
这里 解释一下 各个参数的作用,首先看一下 help 里面有哪些参数:
flume-ng help
Usage: /usr/local/flume-1.9/bin/flume-ng <command> [options]...
commands:
help display this help text
agent run a Flume agent
avro-client run an avro Flume client
version show Flume version info
global options:
--conf,-c <conf> use configs in <conf> directory
--classpath,-C <cp> append to the classpath
--dryrun,-d do not actually start Flume, just print the command
--plugins-path <dirs> colon-separated list of plugins.d directories. See the
plugins.d section in the user guide for more details.
Default: $FLUME_HOME/plugins.d
-Dproperty=value sets a Java system property value
-Xproperty=value sets a Java -X option
agent options:
--name,-n <name> the name of this agent (required)
--conf-file,-f <file> specify a config file (required if -z missing)
--zkConnString,-z <str> specify the ZooKeeper connection to use (required if -f missing)
--zkBasePath,-p <path> specify the base path in ZooKeeper for agent configs
--no-reload-conf do not reload config file if changed
--help,-h display help text
avro-client options:
--rpcProps,-P <file> RPC client properties file with server connection params
--host,-H <host> hostname to which events will be sent
--port,-p <port> port of the avro source
--dirname <dir> directory to stream to avro source
--filename,-F <file> text file to stream to avro source (default: std input)
--headerFile,-R <file> File containing event headers as key/value pairs on each new line
--help,-h display help text
Either --rpcProps or both --host and --port must be specified.
Note that if <conf> directory is specified, then it is always included first
in the classpath.
我们的命令是: flume-ng agent -n a2 -c conf -f …/conf/netcat.conf
agent : 是运行一个 Flume agent
-n(也可以输入–name) : 这个参数是必填的,就是指定一个 agent 的名字,我们在 netcat.conf 配置文件里面,用的是 a2
-c(也可以输入–conf) : 意思是使用 conf 目录下面的配置文件,conf 目录下面还有log4j.properties 和 flume-env.sh 配置文件
-f(也可以输入–conf-file) : 指定相应的配置,就是 netcat.conf文件
四、调试
重新启动一个 终端:
输入 :
telnet localhost 44444
//然后输入数据
hello,world
另外一端可以实时看的接到数据:
4.2 长字符串:
接受端拦截了一部分,这个是由于我们的 slink配置的是logger ,logger sink 将 体内容限制为16字节,从而避免屏幕充斥着过多的内容。如果想要查看调试的完整内容,那么可以使用其他的sink ,如: file_roll sink 可以将日志写入本地文件系统。