flume安装及入门

一、 Flume安装地址

可以选择自己想要安装的版本进行下载

1) Flume官网地址

http://flume.apache.org/

2)文档查看地址

http://flume.apache.org/FlumeUserGuide.html

3)下载地址

http://archive.apache.org/dist/flume/

二、安装部署

用rz命令上传安装包apache-flume-1.9.0-bin.tar.gz到指定文件夹下,我的安装位置是/opt/module/Flume
在这里插入图片描述
解压apache-flume-1.9.0-bin.tar.gz到当前目录下

 tar -zxvf apache-flume-1.9.0-bin.tar.gz

在当前目录下修改apache-flume-1.9.0-bin的名称为flume-1.9.0

 mv apache-flume-1.9.0-bin flume-1.9.0

将flume/conf下的flume-env.sh.template文件拷贝到flume-env.sh,并配置flume-env.sh文件(在/opt/module/Flume/flume-1.9.0/conf目录下)

 cp flume-env.sh.template flume-env.sh
 #使用vi或者vim编辑
 vim flume-env.sh
 # 修改JAVA_HOME为自己的JDK安装目录
 export JAVA_HOME=/opt/module/Java/jdk1.8.0_212

**添加Flum环境变量到 /etc/profile **

 vim /etc/profile 
 #配置Flume环境变量,添加以下内容
 export FLUME_HOME=/opt/module/Flume/flume-1.9.0
 export PATH=$PATH:$FLUME_HOME/bin

使配置的环境变量立即生效

 source /etc/profile 

检查 Flume 是否配置成功

 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

如果出现:找不到或无法加载主类 org.apache.flume.tools.GetJavaProperty
注释掉hbase-env.sh 中的export HBASE_CLASSPATH

三、入门案例

在/opt/module/Flume/flume-1.9.0下创建job文件夹

#创建job文件夹
mkdir job

#进到job文件
cd job/

#创建文件flume-telnet-logger.conf
vim flume-telnet-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

配置文件来源于官方手册:http://flume.apache.org/FlumeUserGuide.html
配置文件解析

# Name the components on this agent  a1 :表示agent的名称 
a1. sources = r1  r1:表示a1的输入源
a1.sinks = k1     k1:表示a1的输出目的地
a1.channels = c1  c1 :表示a1的缓冲区
# Describe/ configure the source
a1. sources.r1 . type = netcat       表示a1的输入源类型为netcat端口类型
a1. sources. r1.bind = loc alhost    表示a1的监听的主机
a1. sources.r1.port = 44444          表示a1的监听的端口号
# Describe the sink
a1. sinks. k1. type = logger         表示a1的输出目的地是控制台logger类型
# Use a channel which buffers events in memory
a1. channels.c1. type = memo ry      表示a1的channel类型是memory内存型
a1. channels .c1.capacity = 1000     表示a1的channel总容量1000个event
al . channels.c1. trans acti onCapacity = 100   表示a1的channel传输时收集到了100条event以后再去提交事务
# Bind the source and sink to the ch annel
a1. sources. r1.channels = c1    表示将r1和c1连接起来
a1. sinks. k1. channel = c1      表示将k1和c1连接起来

启动Flume监控端口

#在/opt/module/Flume/flume-1.9.0/job目录下执行

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

安装netcat网络工具

netcat 是网络工具中的瑞士军刀,它能通过TCP和UDP在网络中读写数据。netcat 所做的就是在两台电脑之间建立链接并返回两个数据流,在这之后所能做的事就看你的想像力了。你能建立一个服务器,传输文件,与朋友聊天,传输流媒体或者用它作为其它协议的独立客户端。

yum -y install nmap-ncat

模拟 TCP 服务端,启动 8888 端口,然后就可以向端口中写入数据


# 可以先判断端口有没有被占用 :netstat -tunlp | grep 端口号

netstat -tunlp | grep 6666

# 功能描述:netstat命令是一个监控TCP/IP网络的非常有用的工具,它可以显示路由表、实际的网络连接以及每一个网络接口设备的状态信息。 
# 基本语法:netstat [选项]
# 选项参数:
# 	-t或--tcp:显示TCP传输协议的连线状况; 
#   -u或--udp:显示UDP传输协议的连线状况;
#	-n或--numeric:直接使用ip地址,而不通过域名服务器; 
#	-l或--listening:显示监控中的服务器的Socket; 
#	-p或--programs:显示正在使用Socket的程序识别码和程序名称

如果被占用,如下图
在这里插入图片描述
可以杀死该进程

kill -9 18638
#如果没有被占用 则执行下面的

nc -lk node01 6666

# -l:表示 netcat 将以监听模式运行
# -k:表示接收完请求不立即退出

在这里插入图片描述
此时就可以发送消息了。

实时读取本地文件到HDFS案例

1.Flume要想将数据输出到HDFS,必须持有Hadoop相关jar包

将下列jar包拷贝到flume的lib中
commons-configuration-1.6.jar、
hadoop-auth-2.7.2.jar、
hadoop-common-2.7.2.jar、
hadoop-hdfs-2.7.2.jar、
commons-io-2.4.jar、
htrace-core-3.1.0-incubating.jar

2.创建flume-file-hdfs.conf文件

# 创建文件flume-file-hdfs.conf
vim flume-file-hdfs.conf
# 添加以下内容到文件flume-file-hdfs.conf中
# Name the components on this agent
a2.sources = r2
a2.sinks = k2
a2.channels = c2

# Describe/configure the source
# 定义source类型为exec可执行命令
a2.sources.r2.type = exec
a2.sources.r2.command = tail -F /opt/module/hive/logs/hive.log
# 执行shell脚本的绝对路径
a2.sources.r2.shell = /bin/bash -c

# Describe the sink
a2.sinks.k2.type = hdfs
a2.sinks.k2.hdfs.path = hdfs://node01:9000/flume/%Y%m%d/%H
#上传文件的前缀
a2.sinks.k2.hdfs.filePrefix = logs-
#是否按照时间滚动文件夹
a2.sinks.k2.hdfs.round = true
#多少时间单位创建一个新的文件夹
a2.sinks.k2.hdfs.roundValue = 1
#重新定义时间单位
a2.sinks.k2.hdfs.roundUnit = hour
#是否使用本地时间戳
a2.sinks.k2.hdfs.useLocalTimeStamp = true
#积攒多少个Event才flush到HDFS一次
a2.sinks.k2.hdfs.batchSize = 1000
#设置文件类型,可支持压缩
a2.sinks.k2.hdfs.fileType = DataStream
#多久生成一个新的文件
a2.sinks.k2.hdfs.rollInterval = 600
#设置每个文件的滚动大小
a2.sinks.k2.hdfs.rollSize = 134217700
#文件的滚动与Event数量无关
a2.sinks.k2.hdfs.rollCount = 0
#最小冗余数
a2.sinks.k2.hdfs.minBlockReplicas = 1

# Use a channel which buffers events in memory
a2.channels.c2.type = memory
a2.channels.c2.capacity = 1000
a2.channels.c2.transactionCapacity = 100

# Bind the source and sink to the channel
a2.sources.r2.channels = c2
a2.sinks.k2.channel = c2

执行监控配置

#在/opt/module/Flume/flume-1.9.0/job目录下执行
flume-ng agent --conf ../conf/ --name a2 --conf-file ./flume-file-hdfs.conf

开启Hadoop和Hive并操作Hive产生日志

# 启动hadoop集群
start-all.sh

# 启动hive
hive

发布了59 篇原创文章 · 获赞 4 · 访问量 4511

猜你喜欢

转载自blog.csdn.net/weixin_45102492/article/details/103140253
今日推荐