Flume 总结(三)sources类型-1.9.0新版

本文详细介绍了Apache Flume的多种数据源类型,包括avro、thrift、exec、JMS、Spooling Directory、Taildir等,讨论了它们的特点、应用场景及安全策略,强调了拦截器和选择器在数据处理中的作用,并提到了自定义Source的实现方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Flume 总结(三)sources类型

1. 官网

  1. http://flume.apache.org/releases/content/1.9.0/FlumeUserGuide.html
  2. 注意区分flume版本在这里插入图片描述
    在这里插入图片描述

2. sources

在这里插入图片描述

  1. avro sources
    在这里插入图片描述
    在这里插入图片描述

这里可以看出,这里使用的avro通用序列化协议,可以组成agent之间的级联
参数最重要就是黑色的, 端口和ip地址
注意这里涉及到拦截器和选择器
拦截器可以对数据做清洗,筛选,打标记
选择器可以根据event的标记,对数据做分发处理,可以有各种分发逻辑,如replicating和multiplexing等策略

  1. thrift source
    在这里插入图片描述
    在这里插入图片描述

顾名思义,这里可以采集来自thrift通用服务器的数据,可以组成agent之间的级联
这里最重要也是端口和ip
注意,这里也有拦截器和选择器,具体看1中解释
这里涉及到kerberos,这是大数据企业开发中,比较严格的权限管理时,使用的一种权限管理协议或者工具软件(它也是一个软件)
在这里插入图片描述

  1. exec source
    在这里插入图片描述
    在这里插入图片描述

注意,这里就是监视一个unix或者linux shell命令产生的数据
这里最重要就是执行的shell 指令
注意,因为这个source是无法进行事务保证的,一旦出错,数据会丢失,所以官方推荐了另外2个source,taildir source和spooling directory source

  1. JMS Source
    这是和activeMQ消息队列组件结合使用的,顾名思义。
    在这里插入图片描述
  2. JMS message converter在这里插入图片描述
  3. SSL and JMS Source在这里插入图片描述
  1. JMS在这里插入图片描述
    注意,这里涉及到安全加密协议,SSL,实际企业大数据开发中,如果涉及到保险,银行等金融领域,很多时候如果数据不是内网传输,而是公网传输,一般都会采用加密协议来保证数据安全性。虽然这些数据主要是日志数据,但还是会进行加密处理。
  1. Spooling Directory Source在这里插入图片描述
    在这里插入图片描述

这是一个可靠的source,可以保证数据不丢失,但可能重复
重点是文件夹的监视,文件夹中文件不能再放进去之后再改动或者修改名字,或者同名文件。所以适合已经产生的固定一批日志文件的采集。
注意这里也有拦截器和选择处理
这里还有采集后文件的处理策略,还有递归查找,还有batchSize,也就是一批读取采集数量,一般这类文件采集框架,很少会一条一条处理,一般都是一批一批处理,这样更加高效。具体可以类比java的缓冲流进行读写,包括linux文件流中的缓冲区机制,都是一样的道理。通过批处理来降低磁盘IO。这一点只要硬盘达不到内存的读写速度,就会一直存在。

  1. Taildir Source在这里插入图片描述
    在这里插入图片描述

不能读取二进制文件
数据读取是可靠的,对文件的偏移量会进行记录来保证失败后可以重试‘
这里可以监视文件组,也就是可以监视文件夹以及其中多个文件
可以设置batchSize,可以根据文件对event中设置header标记,这里很适合一些公司中只有一个日志集群,日志文件并没有很好进行划分的场景,这时候只要不同业务日志放在不同文件夹或者文件中,就可以通过这里设置header中key,然后使用selector选择器进行数据区分分发

  1. Twitter 1% firehose Source (experimental)
    在这里插入图片描述

这是一个实验性质特性,了解即可,不要企业生产中使用

  1. Kafka Source
    在这里插入图片描述

可以读取kafaka中数据,一般按照topic进行读取
注意还有过期的特性
如果是kafaka集群,集群地址加端口,多个地址使用逗号隔开
注意kafaka中数据也可以使用偏移量,或者叫编号进行读取。
在这里插入图片描述
kafaka中数据读取的安全策略,可以使用kerberos或者ssl两种安全协议
注意,在大数据企业开发中,如果涉及到金钱如保险,支付,银行等领域,如果日志数据采用公网传输采集,这时候一般都会使用安全协议来保证日志数据传输安全性。
在这里插入图片描述
在这里插入图片描述

  1. NetCat TCP Source在这里插入图片描述

简单的网络数据来源采集,TCP形式数据

  1. NetCat UDP Source在这里插入图片描述

简单的网络数据来源采集,TCP形式数据

  1. Sequence Generator Source在这里插入图片描述
  2. Syslog Sources在这里插入图片描述
  • Syslog TCP Source
    在这里插入图片描述
  • Multiport Syslog TCP Source
    在这里插入图片描述
  • Syslog UDP Source
    在这里插入图片描述
  1. HTTP Source在这里插入图片描述
    在这里插入图片描述
  2. Stress Source在这里插入图片描述

适合做压力测试

  1. Legacy Sources在这里插入图片描述
  • Avro Legacy Source
    在这里插入图片描述
  • Thrift Legacy Source
    在这里插入图片描述
  1. Custom Source
    在这里插入图片描述

自定义source,当日志数据flume自己提供的source无法解析时,就需要使用自定义source,当然还可以选择其他分布式日志采集框架
实现思路:
1,找到自定义source所要实现或继承的父类/接口
2,重写方法(插入自己的需求逻辑)
3,将代码打成jar包,传入flume的lib目录
4,写配置文件调用自定义的source
在这里插入图片描述
source调用顺序:
1, source是由 SourceRunner—>EventDrivenSourceRunner来调用
2, sourceRunner 拿到 source实例对象
3, 然后调 source的start方法
source读数据,然后将数据转成event
4, 然后将event传给channelprocessor.processEvent(event)
processEvent中第一个动作就是调用拦截器拦截这个event,然后再往channel中写入

  • 多线程实现版本
package cn.doit.flume.custom;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.flume.Context;
import org.apache.flume.Event;
import org
Python Machine Learning By Example by Yuxi (Hayden) Liu English | 31 May 2017 | ASIN: B01MT7ATL5 | 254 Pages | AZW3 | 3.86 MB Key Features Learn the fundamentals of machine learning and build your own intelligent applications Master the art of building your own machine learning systems with this example-based practical guide Work with important classification and regression algorithms and other machine learning techniques Book Description Data science and machine learning are some of the top buzzwords in the technical world today. A resurging interest in machine learning is due to the same factors that have made data mining and Bayesian analysis more popular than ever. This book is your entry point to machine learning. This book starts with an introduction to machine learning and the Python language and shows you how to complete the setup. Moving ahead, you will learn all the important concepts such as, exploratory data analysis, data preprocessing, feature extraction, data visualization and clustering, classification, regression and model performance evaluation. With the help of various projects included, you will find it intriguing to acquire the mechanics of several important machine learning algorithms – they are no more obscure as they thought. Also, you will be guided step by step to build your own models from scratch. Toward the end, you will gather a broad picture of the machine learning ecosystem and best practices of applying machine learning techniques. Through this book, you will learn to tackle data-driven problems and implement your solutions with the powerful yet simple language, Python. Interesting and easy-to-follow examples, to name some, news topic classification, spam email detection, online ad click-through prediction, stock prices forecast, will keep you glued till you reach your goal. What you will learn Exploit the power of Python to handle data extraction, manipulation, and exploration techniques Use Python to visualize data spread across multiple dimensions and extract useful features Dive deep into the world of analytics to predict situations correctly Implement machine learning classification and regression algorithms from scratch in Python Be amazed to see the algorithms in action Evaluate the performance of a machine learning model and optimize it Solve interesting real-world problems using machine learning and Python as the journey unfolds About the Author Yuxi (Hayden) Liu is currently a data scientist working on messaging app optimization at a multinational online media corporation in Toronto, Canada. He is focusing on social graph mining, social personalization, user demographics and interests prediction, spam detection, and recommendation systems. He has worked for a few years as a data scientist at several programmatic advertising companies, where he applied his machine learning expertise in ad optimization, click-through rate and conversion rate prediction, and click fraud detection. Yuxi earned his degree from the University of Toronto, and published five IEEE transactions and conference papers during his master's research. He finds it enjoyable to crawl data from websites and derive valuable insights. He is also an investment enthusiast. Table of Contents Getting Started with Python and Machine Learning Exploring the 20 newsgroups data set Spam email detection with Naive Bayes News topic classification with Support Vector Machine Click-through prediction with tree-based algorithms Click-through rate prediction with logistic regression Stock prices prediction with regression algorithms Best practices
### 创建 Apache Flume 的 `example.conf` 配置文件 要在 Apache Flume 1.9.0 的 `conf` 目录下创建名为 `example.conf` 的配置文件,可以按照以下方法操作: #### 方法一:通过 Linux 命令行创建 如果操作系统为 Linux 或 macOS,可以通过终端执行以下命令来创建并编辑该文件。 1. 使用 `touch` 命令创建一个新的空文件: ```bash touch /opt/soft/flume-1.9.0/conf/example.conf ``` 2. 编辑新创建的文件,可使用任何文本编辑器(如 `vi`、`nano` 等)。以下是使用 `vi` 进行编辑的例子: ```bash vi /opt/soft/flume-1.9.0/conf/example.conf ``` 3. 在打开的文件中输入所需的 Flume 配置内容。例如,假设要定义一个简单的 Agent 配置如下: ```properties # 定义 agent 组件 a1.sources = r1 a1.sinks = k1 a1.channels = c1 # 描述 source 配置 a1.sources.r1.type = netcat a1.sources.r1.bind = localhost a1.sources.r1.port = 44444 # 描述 sink 配置 a1.sinks.k1.type = logger # 描述 channel 配置 a1.channels.c1.type = memory a1.channels.c1.capacity = 1000 a1.channels.c1.transactionCapacity = 100 # 将 source 和 sink 关联到 channel 上 a1.sources.r1.channels = c1 a1.sinks.k1.channel = c1 ``` 4. 保存并退出编辑器。 --- #### 方法二:通过图形界面工具创建 如果在 Windows 系统上解压了 Flume 并希望手动创建文件,则可以按以下步骤操作: 1. 找到 Flume 解压缩后的路径 `/opt/soft/flume-1.9.0/conf` 对应的位置。 2. 右键点击空白区域,选择 **新建 -> 文本文件**,命名为 `example.conf`。注意去掉扩展名 `.txt`,确保最终文件名称为纯 `example.conf`。 3. 使用记事本或其他文本编辑器打开此文件,并粘贴上述示例中的配置内容。 4. 保存文件后关闭编辑器。 --- #### 启动 Flume 测试配置文件 完成以上步骤后,可通过以下命令验证 `example.conf` 是否正常工作: ```bash flume-ng agent --conf ../conf --conf-file ../conf/example.conf --name a1 -Dflume.root.logger=INFO,console ``` 这会加载刚刚创建的 `example.conf` 文件,并启动指定的 Agent 名称为 `a1` 的服务[^2]。 --- ### 注意事项 - 如果未找到 `flume-ng` 脚本,请确认已正确安装 Flume 并将其 bin 目录加入 PATH 中[^4]。 - 若遇到权限问题,在 Linux 下可能需要以管理员身份运行命令,比如加上 `sudo` 前缀。 ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值