Flume的四个使用案例
一、Flume监听端口
1,在linux机器上下载telnet工具
yum search telnet
yumm install telnet.x86_64
2.编写flume的配置文件,并将文件复制到flume/conf文件夹下
#.agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1 #.source netcat表示监视端口、localhost监视本机(也可以写本机名如hd1-)
#44444端口号(随便写,注意不要与常用的端口号重复即可)
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = #.sinks Describe the sink 输出日志文件
a1.sinks.k1.type = logger #. 使用内存、总容量1000、每次传输100
a1.channels.c1.type = memory
a1.channels.c1.capacity =
a1.channels.c1.transactionCapacity = #.Bind the source and sink to the channel 一个source可以绑定多个channel
# 一个sinks可以只能绑定一个channel 使用的是图二的模型
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
3.启动配置文件
bin/flume-ng agent --conf conf/ --name a1 --conf-file conf/flumejob_telnet.conf -Dflume.root.logger==INFO,console
4.新建一个Linux本机,输入下面命令连接本机
telnet localhost 44444
5.发送数据查看
二、实施采集数据到hdfs(监控文件)
这里有一个无限产生数据的jar包,其产生的数据存放在/opt/jars/calllog.csv下
1.写配置文件 flumejob_hdfs.conf
# .agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1 # .sources
# exec 执行一个命令的方式去查看文件 tail -F 实时查看
a1.sources.r1.type = exec
# 要执行的脚本command tail -F 默认10行 man tail 查看帮助
a1.sources.r1.command = tail -F /opt/jars/calllog.csv
# 执行这个command使用的是哪个脚本 -c 指定使用什么命令
# bash: /usr/bin/bash /usr/share/man/man1/bash..gz
a1.sources.r1.shell = /usr/bin/bash -c # .sinks
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = hdfs://hd1-1:9000/flume/calllog
#上传文件的前缀
a1.sinks.k1.hdfs.filePrefix = logs-
#是否按照时间滚动文件夹
a1.sinks.k1.hdfs.round = true
#多少时间单位创建一个新的文件夹 秒 (默认30s)
a1.sinks.k1.hdfs.roundValue =
#重新定义时间单位(每小时滚动一个文件夹)
a1.sinks.k1.hdfs.roundUnit = minute
#是否使用本地时间戳
a1.sinks.k1.hdfs.useLocalTimeStamp = true
#积攒多少个 Event 才 flush 到 HDFS 一次
a1.sinks.k1.hdfs.batchSize =
#设置文件类型,可支持压缩
a1.sinks.k1.hdfs.fileType = DataStream
#多久生成一个新的文件 秒
a1.sinks.k1.hdfs.rollInterval =
#设置每个文件的滚动大小 字节(最好128M)
a1.sinks.k1.hdfs.rollSize =
#文件的滚动与 Event 数量无关
a1.sinks.k1.hdfs.rollCount =
#最小冗余数(备份数 生成滚动功能则生效roll hadoop本身有此功能 无需配置) 1份 不冗余
a1.sinks.k1.hdfs.minBlockReplicas = # Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity =
a1.channels.c1.transactionCapacity = # Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
2.启动hdfs、yarn,并在hdfs上建立文件中的生成文件目录
hdfs dfs -mkdir -p /flume/calllog
3.启动命令
bin/flume-ng agent --conf conf/ --name a1 --conf-file conf/flumejob_hdfs.conf
4.启动jar包,然后查看hdfs上calllog文件夹下的变化
三、监控文件目录
1.写配置文件 flumejob_dir.conf
# .agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1 # .sources
a1.sources.r1.type = spooldir
# 监控的文件夹
a1.sources.r1.spoolDir = /root/spooldir
# 上传成功后显示后缀名
a1.sources.r1.fileSuffix = .COMPLETED
# 如论如何 加绝对路径的文件名 默认false
a1.sources.r1.fileHeader = true #忽略所有以.tmp 结尾的文件(正在被写入),不上传
# ^以任何开头 出现无限次 以.tmp结尾的
a1.sources.r1.ignorePattern = ([^ ]*\.tmp) # .sinks
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = hdfs://hd09-01:9000/flume/spooldir/%Y%m%d/%H
#上传文件的前缀
a1.sinks.k1.hdfs.filePrefix = spooldir-
#是否按照时间滚动文件夹
a1.sinks.k1.hdfs.round = true
#多少时间单位创建一个新的文件夹
a1.sinks.k1.hdfs.roundValue =
#重新定义时间单位
a1.sinks.k1.hdfs.roundUnit = hour
#是否使用本地时间戳
a1.sinks.k1.hdfs.useLocalTimeStamp = true
#积攒多少个 Event 才 flush 到 HDFS 一次
a1.sinks.k1.hdfs.batchSize = #设置文件类型,可支持压缩
a1.sinks.k1.hdfs.fileType = DataStream
#多久生成一个新的文件
a1.sinks.k1.hdfs.rollInterval =
#设置每个文件的滚动大小大概是 128M
a1.sinks.k1.hdfs.rollSize =
#文件的滚动与 Event 数量无关
a1.sinks.k1.hdfs.rollCount =
#最小副本数
a1.sinks.k1.hdfs.minBlockReplicas = # .channels
a1.channels.c1.type = memory
a1.channels.c1.capacity =
a1.channels.c1.transactionCapacity = # .bink
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
2.启动hdfs、yarn,注意,不需要在hdfs上创建
3.启动命令
bin/flume-ng agent --conf conf\ --name a1 --conf-file conf/flumejob_dir.conf
4.将任意文件复制到spool文件目录中,在hdfs中可看到生成日志文件
四、Flume监听一个文件,然后使用两个channel,一个channle对应的sink存储到hdfs,另一个channel对应的sink存储到本地。
思路:这时应需要三个agent,
第一个agent用来监听文件并将数据源复制为两份发送到其他两个agent,
第二个agent将数据传输到hdfs存储,第三个agent将数据存储在本地。
1.编写三个conf文件(flumejob1.conf、flumejob2.conf、flumejob3.conf)
# name the components on this agent
a1.sources = r1
a1.sinks = k1 k2
a1.channels = c1 c2
# 将数据流复制给多个 channel
a1.sources.r1.selector.type = replicating # Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /tmp/root/hive.log
a1.sources.r1.shell = /bin/bash -c # Describe the sink
# 分两个端口发送数据
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = hd09-
a1.sinks.k1.port = a1.sinks.k2.type = avro
a1.sinks.k2.hostname = hd09-
a1.sinks.k2.port = # Describe the channel
a1.channels.c1.type = memory
a1.channels.c1.capacity =
a1.channels.c1.transactionCapacity = a1.channels.c2.type = memory
a1.channels.c2.capacity =
a1.channels.c2.transactionCapacity = # Bind the source and sink to the channel
a1.sources.r1.channels = c1 c2
a1.sinks.k1.channel = c1
a1.sinks.k2.channel = c2
# Name the components on this agent
a2.sources = r1
a2.sinks = k1
a2.channels = c1 # Describe/configure the source
a2.sources.r1.type = avro
# 端口抓取数据
a2.sources.r1.bind = hd09-
a2.sources.r1.port = # Describe the sink
a2.sinks.k1.type = hdfs
a2.sinks.k1.hdfs.path = hdfs://hd09-01:9000/flume2/%Y%m%d/%H #上传文件的前缀
a2.sinks.k1.hdfs.filePrefix = flume2-
#是否按照时间滚动文件夹
a2.sinks.k1.hdfs.round = true
#多少时间单位创建一个新的文件夹
a2.sinks.k1.hdfs.roundValue =
#重新定义时间单位
a2.sinks.k1.hdfs.roundUnit = hour
#是否使用本地时间戳
a2.sinks.k1.hdfs.useLocalTimeStamp = true
#积攒多少个 Event 才 flush 到 HDFS 一次
a2.sinks.k1.hdfs.batchSize = #设置文件类型,可支持压缩
a2.sinks.k1.hdfs.fileType = DataStream
#多久生成一个新的文件
a2.sinks.k1.hdfs.rollInterval =
#设置每个文件的滚动大小大概是 128M
a2.sinks.k1.hdfs.rollSize =
#文件的滚动与 Event 数量无关
a2.sinks.k1.hdfs.rollCount =
#最小副本数 # Describe the channel
a2.channels.c1.type = memory
a2.channels.c1.capacity =
a2.channels.c1.transactionCapacity = # Bind the source and sink to the channel
a2.sources.r1.channels = c1
a2.sinks.k1.channel = c1
# Name the components on this agent
a3.sources = r1
a3.sinks = k1
a3.channels = c1 # Describe/configure the source
a3.sources.r1.type = avro
a3.sources.r1.bind = hd09-
a3.sources.r1.port = # Describe the sink
a3.sinks.k1.type = file_roll
a3.sinks.k1.sink.directory = /root/flume2 # Describe the channel
a3.channels.c1.type = memory
a3.channels.c1.capacity =
a3.channels.c1.transactionCapacity = # Bind the source and sink to the channel
a3.sources.r1.channels = c1
a3.sinks.k1.channel = c1
2.在本地创建文件中本地存放的文件夹,本地不会自动创建,而hdfs会
mkdir /root/flume2
3.打开jar包测试。
Flume的四个使用案例的更多相关文章
- Pandas系列(十四)- 实战案例
一.series import pandas as pd import string #创建Series的两种方式 #方式一 t = pd.Series([1,2,3,4,43],index=list ...
- Flume原理分析与使用案例
1.flume的特点: flume是一个分布式.可靠.和高可用的海量日志采集.聚合和传输的系统.支持在日志系统中定制各类数据发送方,用于收集数据:同时,Flume提供对数据进行简单处理,并写到各种数据 ...
- java基础之多线程四:简单案例
多线程案例: 有一个包包的数量为100个,分别从实体店和官网进行售卖.使用多线程的方式,分别打印实体店和官网卖出包包的信息.分别统计官网和实体店各卖出了多少个包包 第一种方法 继承Thread类: p ...
- 05_ Flume多级Agent之间串联案例
多级agent之间串联: 从tail命令获取数据发送到avro端口,另一个节点可配置一个avro源来获取数据,发送外部存储 启动两个Agent节点: 使用scp命令拷贝flume安装包到另一台虚拟机; ...
- 04_ Flume采集文件到HDFS案例
采集需求:比如业务系统使用log4j生成的日志,日志内容不断增加,需要把追加到日志文件中的数据实时采集到hdfs 根据需求,首先定义以下3大要素 采集源,即source——监控文件内容更新 : ex ...
- maven第四章背景案例
4.3简要设计 4.3.1接口设计 4.3.2模块结构 思想 先定义出核心接口,一个接口可以认为是一个功能,根据接口划分功能 设计模式就是一种思想,外观模式和代理模式,适配者模式三者的区别 http: ...
- 《数据结构与算法(C语言版)》严蔚敏 | 第四章课本案例
//二叉树的顺序存储表示 #define MAXTSIZE 100 typedef TElemtype SqBiTree[MAXTSIZE]; SqBiTree bt; //二叉树的二叉链表存储表示 ...
- Flume具体应用(多案例)
日志采集 对于flume的原理其实很容易理解,我们更应该掌握flume的具体使用方法,flume提供了大量内置的Source.Channel和Sink类型.而且不同类型的Source.Channel和 ...
- (升级版)Spark从入门到精通(Scala编程、案例实战、高级特性、Spark内核源码剖析、Hadoop高端)
本课程主要讲解目前大数据领域最热门.最火爆.最有前景的技术——Spark.在本课程中,会从浅入深,基于大量案例实战,深度剖析和讲解Spark,并且会包含完全从企业真实复杂业务需求中抽取出的案例实战.课 ...
随机推荐
- 开发了5年android,我开始了go学习之旅
前言 做了近5年的android开发,最近项目也是不怎么忙,空闲的时候总会思考一些事情,不过作为移动开发,我个人觉得很有必要学习后台开发,由于公司是Go语言开发的,了解go语言一段时间后,我发现go语 ...
- swift 实践- 05 -- UITextField
import UIKit class ViewController: UIViewController ,UITextFieldDelegate{ // 文本框的创建, 有如下几个样式: // UIT ...
- PID控制器开发笔记之十一:专家PID控制器的实现
前面我们讨论了经典的数字PID控制算法及其常见的改进与补偿算法,基本已经覆盖了无模型和简单模型PID控制经典算法的大部.再接下来的我们将讨论智能PID控制,智能PID控制不同于常规意义下的智能控制,是 ...
- Confluence 6 管理你的 Confluence 许可证
你的许可证能够让你在运行 Confluence 的时候在指定的时间段获得特定的支持.同时这个许可证也定义了在你 Confluence 中可以使用的用户数量. 希望快速的查看当前的许可证信息,你可以进入 ...
- Confluence 6 自定义配色方案
Confluence 的管理员可以修改 Confluence 的色彩配色方案.站点的默认配色方案将会在站点的默认空间上同时生效. 希望修改站点的配色方案: 在屏幕的右上角单击 控制台按钮 ,然后选择 ...
- 实用的sublime插件集合 – sublime推荐必备插件
Package Control 功能:安装包管理 简介:sublime插件控制台,提供添加.删除.禁用.查找插件等功能 使用:https://sublime.wbond.net/installatio ...
- ERROR 1044 (42000): Access denied for user 'root'@'%' to database 'mysql'
原因:修改数据库账号时删除了默认的localhost root, 新建了% root 但没有赋予全部权限; 解决方法: 1.关闭数据库# mysqld stop 2.在my.cnf里加入skip-g ...
- python字符编码和文件处理
一.了解字符编码的知识储备 1.文本编辑器存取文件的原理(nodepad++,python,word) 打开编辑器就打开了启动了一个进程,是在内存中的,所以,用编辑器编写的内容也都是存放于内存中的,断 ...
- dump增加的表数据
备份mysql数据库表中,增加的部分 前提条件: 备份库和正式库表结构一样: 表名不一样可以改: 备份库:192.168.1.10 正式库:192.168.1.11 获取当前"备份" ...
- 社会单位消防安全户籍化管理系统——半自动提交V1.0版本
社会单位消防安全户籍化管理系统——半自动提交V1.0版本 首先先上代码,开发这个小程序其实是用来帮助同事完成一项每天都做的繁琐事件,以往需要花费十分钟做这件事情,现在就是傻瓜式,点几下鼠标就好了.本来 ...