首页 技术 正文
技术 2022年11月7日
0 收藏 651 点赞 208 浏览 2524 个字

Flume知识点:

Event 是一行一行的数据

1.flume是分布式的日志收集系统,把收集来的数据传送到目的地去。

2.flume里面有个核心概念,叫做agent。agent是一个java进程,运行在日志收集节点。

3.agent里面包含3个核心组件:source、channel、sink。

3.1 source组件是专用于收集日志的,可以处理各种类型各种格式的日志数据,包括avro、thrift、exec、jms、spooling directory、netcat、sequence generator、syslog、http、legacy、自定义。

source组件把数据收集来以后,临时存放在channel中。

3.2 channel组件是在agent中专用于临时存储数据的,可以存放在memory、jdbc、file、自定义。

channel中的数据只有在sink发送成功之后才会被删除。

3.3 sink组件是用于把数据发送到目的地的组件,目的地包括hdfs、logger、avro、thrift、ipc、file、null、hbase、solr、自定义。

4.在整个数据传输过程中,流动的是event。事务保证是在event级别。

5.flume可以支持多级flume的agent,支持扇入(fan-in)、扇出(fan-out)。

扇入指的是:source 可以接收多个输入

扇出指的是:sink可以输出多个目的地


Flume安装:

1.分别解压这两个文件在节点里:

2.把src内容 复制到bin下:

cp -ri apache-flume-1.4.0-src/* apache-flume-1.4.0-bin/

3.src没用可以删掉了:

rm -rf apache-flume-1.4.0-src

4.重命名apache-flume-1.4.0-bin 为flume:

mv apache-flume-1.4.0-bin/ flume

注意:flume安装的 前提是你已经安装了hadoop ,因为它要用到hadoop的jar

5 . 书写配置文件example

agent1表示代理名称:

agent1.sources=source1

agent1.sinks=sink1

agent1.channels=channel1

Spooling Directory是监控指定文件夹中新文件的变化,一旦新文件出现,就解析该文件内容,然后写入到channle。写入完成后,标记该文件已完成或者删除该文件。

配置source1

agent1.sources.source1.type=spooldir

agent1.sources.source1.spoolDir=/root/hmbbs

agent1.sources.source1.channels=channel1

agent1.sources.source1.fileHeader = false

agent1.sources.source1.interceptors = i1

agent1.sources.source1.interceptors.i1.type = timestamp

配置sink1

agent1.sinks.sink1.type=hdfs

agent1.sinks.sink1.hdfs.path=hdfs://hadoop0:9000/hmbbs

agent1.sinks.sink1.hdfs.fileType=DataStream

agent1.sinks.sink1.hdfs.writeFormat=TEXT

agent1.sinks.sink1.hdfs.rollInterval=1 //指定时间文件被关闭

agent1.sinks.sink1.channel=channel1

agent1.sinks.sink1.hdfs.filePrefix=%Y-%m-%d //生成文件的前缀

配置channel1

agent1.channels.channel1.type=file

//备份目录

agent1.channels.channel1.checkpointDir=/root/hmbbs_tmp/123

agent1.channels.channel1.dataDirs=/root/hmbbs_tmp/

把该文件写入flume 的conf文件夹下,并命名为example

6.在root目录下创建文件夹hmbbs

[root@hadoop /]# cd /root

[root@hadoop ~]# ls

anaconda-ks.cfg Documents install.log Music Public Videos

Desktop Downloads install.log.syslog Pictures Templates

[root@hadoop ~]# mkdir hmbbs

7.在hadoop下创建文件夹

hadoop fs -mkdir /hmbbs

8.执行flume

进入flume执行命令

bin/flume-ng agent -n agent1 -c conf -f conf/example -Dflume.root.logger=DEBUG,console

9.创建

[root@hadoop ~]# vi hello

[root@hadoop ~]# cp hello hmbbs

在hdfs里会看到文件传输了进去

10 .

[root@hadoop ~]# cd hmbbs

[root@hadoop hmbbs]# ls

hello.COMPLETED

红色部分表示任务完成,已经传输到channel中,后缀.COMPLETED是重新命名后的结果。

[root@hadoop ~]# cd hmbbs_tmp

[root@hadoop hmbbs_tmp]# ls

hmbbs_tmp表示的是channel使用的目录。

[root@hadoop hmbbs_tmp]# cd 123

[root@hadoop 123]# ls

checkpoint checkpoint.meta inflightputs inflighttakes

这里的数据是备份数据,如果datadir里数据丢失可以从这里恢复。

在实际生产中是多节点配置,比较复杂,可以参考官方文档:

http://flume.apache.org

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,491
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,906
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,739
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,492
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,131
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,293