数据采集工具Flume的安装和使用

一.定义

数据采集是大数据分析全流程的重要环节,典型的数据采集工具包括ETL工具、日志采集工具、数据迁移工具等。
Flume是一个高可用的、高可靠的、分布式的海量日志采集、聚合和传输的系统。

二.Flume 的安装配置

  • 1.下载flume
wget http://mirror.bit.edu.cn/apache/flume/1.8.0/apache-flume-1.8.0-bin.tar.gz
  • 2.创建flume目录
cd /opt/module
mkdir flume
  • 3 把压缩文件解压到flume中
tar -zxvf apache-flume-1.8.0-bin.tar.gz -C /opt/module/flume 
  • 4 配置环境变量
vi /etc/profile

写入

export FLUME_HOME=/opt/module/flume/apache-flume-1.8.0-bin
export FLUME_CONF_DIR=$FLUME_HOME/conf
export PATH=$FLUME_HOME/bin:$PATH

在这里插入图片描述
使环境变量生效

source /etc/profile
  • 5 配置flume的JAVA_HOME
cd /opt/module/flume/apache-flume-1.8.0-bin
cd conf
cp flume-env.sh.template  flume-env.sh
vi flume-env.sh

写入

export JAVA_HOME=/opt/module/jdk1.8.0_121

在这里插入图片描述

  • 6 查看flume的版本
cd /opt/module/flume/apache-flume-1.8.0-bin

./bin/flume-ng version

在这里插入图片描述

三.常见问题解决

  • 1.Error: Could not find or load main class org.apache.flume.tools.GetJavaProperty
    错误: 找不到或无法加载主类 org.apache.flume.tools.GetJavaProperty
    这个问题是因为之前安装hbase导致的
    解决方法
cd /opt/module/hbase-1.4.9/conf
vi hbase-env.sh

注释掉以下语句

# export HBASE_CLASSPATH=/opt/module/hbase/conf

在这里插入图片描述
重新执行查看版本那几条命令
问题解决在这里插入图片描述

四. Flume的使用实例

示列1

  • 1 创建avro.conf文件
cd /opt/module/flume/apache-flume-1.8.0-bin/conf
vi avro.conf
  • 2 写入配置信息
a1.sources= r1

a1.sinks= k1

a1.channels= c1

#Describe/configure the source

a1.sources.r1.type=avro

a1.sources.r1.channels= c1

a1.sources.r1.bind= 0.0.0.0

a1.sources.r1.port= 4141

#Describe the sink

a1.sinks.k1.type=logger

# Use achannel which buffers events in memory

a1.channels.c1.type=memory

a1.channels.c1.capacity= 1000

a1.channels.c1.transactionCapacity= 100

# Bindthe source and sink to the channel

a1.sources.r1.channels= c1

a1.sinks.k1.channel= c1
  • 3 执行命令
./bin/flume-ng agent -c . -f /opt/module/flume/apache-flume-1.8.0-bin/conf/avro.conf -n a1 -Dflume.root.logger=INFO,console

屏幕信息显示如下
在这里插入图片描述

  • 4 打开另一个Linux终端
cd /opt/module/flume/apache-flume-1.8.0-bin/
touch log.00
sh -c 'echo “hello world” > /opt/module/flume/apache-flume-1.8.0-bin/log.00'

  • 5 执行命令
 ./bin/flume-ng avro-client --conf conf -H localhost -p 4141 -F /opt/module/flume/apache-flume-1.8.0-bin/log.00

示列2

  • 1 创建文件
cd /opt/module/flume/apache-flume-1.8.0-bin/
touch example.conf
  • 2 写入
# 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

*3 执行下面命令

 ./bin/flume-ng agent --conf ./conf --conf-file ./example.conf --name a1 -Dflume.root.logger=INFO,console

在这里插入图片描述

  • 4 打开另一个终端
    输入
telnet localhost 44444

输入helloworld
在这里插入图片描述
查看原来终端
在这里插入图片描述
执行成功。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值