Ubuntu中flume的安装配置及基本使用

注意flume需要以jdk环境为基础,如果没有安装jdk,请参考https://blog.csdn.net/ybk233/article/details/81263945里面的说明进行安装配置


安装配置


1.首先从官网下载flume压缩包,网址:http://flume.apache.org/download.html
本文以apache-flume-1.8.0-bin.tar.gz为例

2.下载完成后,在Ubuntu的软件安装目录中解压缩
tar -zxvf apache-flume-1.8.0-bin.tar.gz
3.配置环境变量
在/etc/profile中配置全局的环境变量
打开编辑命令:sudo vim /etc/profile
export FLUME_HOME=/home/xxx/software/flume-1.8.0
export PATH=$PATH:$FLUME_HOME/bin
加载环境变量:source /etc/profile
4.修改配置文件
将conf目录下的flume-env.sh.template模板文件复制一份并重命名flume-env.sh,修改其中的内容,及添加jdk的路径:export JAVA_HOME=/home/xxx/software/jdk1.8.0_171
5.验证是否安装成功


基本使用


案例一:netcat

在conf文件夹下,新建netcat_source.conf文件,添加内容如下
# example.conf: A single-node Flume configuration

# 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 = 44445

# 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
在控制台中flume目录下使用命令启动
flume-ng agent –conf /home/ybk/software/flume-1.8.0/conf –conf-file /home/ybk/software/flume-1.8.0/conf/netcat_source.conf –name a1 -Dflume.root.logger=INFO,console
#–conf:配置目录
#–conf-file:配置文件
#–name:代理名称
#-Dflume:额外的参数
使用netcat进行发送信息验证:telnet localhost 44445
如果没有安装telnet,请使用命令安装:sudo apt-get install xinetd telnetd

案例二:avro
avro可以发送一个给定的文件给flume,avro源使用avro rpc机制。
在conf文件夹下,新建avro_source.conf文件,添加内容如下
# example.conf: A single-node Flume configuration

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = avro
a1.sources.r1.bind = 0.0.0.0
a1.sources.r1.port = 44443

# 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
启动agent a1:
flume-ng agent -c /home/ybk/software/flume-1.8.0/conf/ -f /home/ybk/software/flume-1.8.0/conf/avro_source.conf -n a1 -Dflume.root.logger=INFO,console
在flume目录下新建log1.txt文件,并添加hello world
使用avro-client发送文件:
flume-ng avro-client –conf /home/ybk/software/flume-1.8.0/conf –host 0.0.0.0 –port 44443 –filename /home/ybk/software/flume-1.8.0/log1.txt
如图所示,发送成功:

猜你喜欢

转载自blog.csdn.net/YBK233/article/details/81274310