flume--安装 及5种 采集 sources

本文详细介绍Flume的各种数据采集方式,包括Avro、Exec、Spool、Syslogtcp及HTTPSource等,通过具体配置和实例演示如何从不同来源收集数据。

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

 

flume常用命令

//复制 文件  cp exec.conf tcp.conf

flume-ng agent -c . -f avro.conf -n a1 -Dflume.root.logger=info,console
flume-ng avro-client -c . -H linux05 -p 8888 -F /project/age.txt

flume-ng version

---------------------------------------------------------------------------------------------
linux里面不存在扩展名
1.两台机器都安装
2. 上传 解压tar -zxvf apache-flume-1.6.0-bin.tar.gz
3.vim /etc/profile
source /etc/profile
//配置环境变量

export FLUME_HOME=/root/Downloads/apache-flume-1.6.0-bin
export PATH=$PATH:$FLUME_HOME/bin

4.flume-ng version 检查是否安装成功

 

5.04机器 监控机器 :

[root@linux05 conf]#
----------------------------
//配置文件 在/root/Downloads/apache-flume-1.6.0-bin/conf
1.Avro可以发送一个给定的文件给Flume,Avro 源使用AVRO RPC机制。
创建agent配置文件  

vim avro.txt 不同的机器上
a1.sources=r1 #a1是我们要启动的Agent名字
a1.channels=c1 #sources为r1 sinks为k1 channels 为c1
a1.sinks=k1

a1.sources.r1.type=avro #指定r1的类型为AVRO
a1.sources.r1.bind=linux05 #将Source与IP地址绑定(这里指本机)
a1.sources.r1.port=8888 #指定通讯端口为4141

a1.channels.c1.type=memory #指定Channel的类型为Memory
a1.channels.c1.capacity=1000 #设置Channel的最大存储event数量为1000
a1.channels.transactionCapacity=100 #每次最大可以source中拿到或者送到sink中的event数量也是100

a1.sinks.k1.type=logger #指定k1的类型为Logger(不产生实体文件,只在控制台显示)

a1.sources.r1.channels=c1
a1.sinks.k1.channel=c1
----------------------------------------------
6. //启动flume 并且 打印在控制台
flume-ng agent -c . -f avro.conf -n a1 -Dflume.root.logger=info,console

-c:使用配置文件所在目录(这里指默认路径,即$FLUME_HOME/conf)
-f:flume定义组件的配置文件?
-n:启动Agent的名称,该名称在组件配置文件中定义?
-Dflume.root.logger:flume自身运行状态的日志,按需配置,详细信息,控制台打印

 


--------------------------------------------------------------------------------------------------------------
7.[root@linux06 conf]# flume-ng avro-client -c . -H linux05 -p 8888 -F /project/age.txt //启动客户端

=======================================================
2) Exec--- 监听本地文件 aa.txt
tomcat日志会打印在catalina.out 每天生成一个 tail -f catalina.out 监控 同一台机器上
1.vim exec.conf
----------------
a1.sources = r1
a1.sinks = k1
a1.channels = c1

a1.sources.r1.type = exec
a1.sources.r1.command = tail -f /aa.txt

a1.sinks.k1.type = logger

a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
----------------------
2. 命令:flume-ng agent -c . -f exec.conf -n a1 -Dflume.root.logger=info,console
3.[root@linux05 /]# vim aa.txt
[root@linux05 /]# echo "1111">>aa.txt


4.

3.Spool 本地模式 监听本地文件夹 同一台机器
Spool监测配置的目录下新增的文件,并将文件中的数据读取出来。需要注意两点:
拷贝到spool目录下的文件不可以再打开编辑。
spool目录下不可包含相应的子目录
创建agent配置文件
缺点:指定文件下不能有重名(如:kk.log 和 kk.log. COMPLETED),会报错 是的flume死掉

vim  spool.conf
a1.sources=r1
a1.channels=c1
a1.sinks=k1

a1.sources.r1.type=spooldir
a1.sources.r1.spoolDir=/flume

a1.channels.c1.type=memory
a1.channels.c1.capacity=1000
a1.channels.c1.transactionCapacity=100

a1.sinks.k1.type=logger

a1.sinks.k1.channel=c1
a1.sources.r1.channels=c1
---------------------------------------------------------------
[root@linux05 conf]# flume-ng agent -c . -f spool.conf -n a1 -Dflume.root.logger=info,console

[root@linux05 flume]# echo 123222 >> /flume/mm.txt

 

vim spool.conf  //在flume的conf下面编辑         加自定义标示

a1.sources=r1
a1.channels=c1
a1.sinks=k1


a1.sources.r1.type=spooldir
a1.sources.r1.spoolDir=/flume
a1.sources.r1.fileSuffix=.fuck


a1.channels.c1.type=memory
a1.channels.c1.capacity=1000
a1.channels.c1.transactionCapacity=100


a1.sinks.k1.type=logger


a1.sinks.k1.channel=c1
a1.sources.r1.channels=c1


*********************************************************
//多加一句话 Spool2—自定义后缀 a1.sources.r1.fileSuffix
= .fuck

 4.Syslogtcp

Syslogtcp监听TCP的端口做为数据源

创建agent配置文件

tcp.conf   本地 监控

1. vim tcp.conf
a1.sources = r1 a1.sinks = k1 a1.channels = c1 a1.sources.r1.type = syslogtcp a1.sources.r1.host=linux05 a1.sources.r1.port=8888 a1.sinks.k1.type = logger a1.channels.c1.type = memory a1.channels.c1.capacity = 1000 a1.channels.c1.transactionCapacity = 100 a1.sources.r1.channels = c1 a1.sinks.k1.channel = c1
***********************************************************

2.[root@linux05 conf]# flume-ng agent -c . -f tcp.conf -n a1 -Dflume.root.logger=info,console

3.上传nc tar  =============

[root@linux05 Downloads]# rpm -ivh nc-1.84-22.el6.x86_64.rpm 

4.[root@linux05 Downloads]# nc linux05 8888

//输入内容

5.看监控 ===如图

 //用java代码

1. vim tcp.conf
a1.sources = r1
a1.sinks = k1
a1.channels = c1

a1.sources.r1.type = syslogtcp
a1.sources.r1.host=linux05
a1.sources.r1.port=8888

a1.sinks.k1.type = logger

a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
***********************************************************
2.[root@linux05 conf]# flume-ng agent -c . -f tcp.conf -n a1 -Dflume.root.logger=info,console

在eclipse

package com.bw.tcp;

import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;

public class TcpTest{
    public static void main(String[] args) throws Exception {
        Socket socket=new Socket();
        SocketAddress address=new InetSocketAddress("linux05",8888);//连接
        socket.connect(address);
        OutputStream outputStream = socket.getOutputStream();//写入
        PrintWriter pw = new PrintWriter(outputStream);
        pw.write("fuck u \n");
        pw.flush();
        outputStream.flush();
        pw.close();
        outputStream.close();
    }
}

 

5...JSONHandler

  • 创建agent配置文件

vim http.conf //本地监控

 

a1.sources = r1
a1.sinks = k1
a1.channels = c1

a1.sources.r1.type = org.apache.flume.source.http.HTTPSource
a1.sources.r1.port=8888

a1.sinks.k1.type = logger

a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
****************************************************************************************************

[root@linux05 conf]# flume-ng agent -c . -f http.conf -n a1 -Dflume.root.logger=info,console

//生成JSON 格式的POST request

//客户端命令发送的

[root@linux05 Downloads]# curl -X POST -d '[{ "headers" :{"a" : "a1","b" : "b1"},"body" : "idoall.org_body"}]' http://linux05:8888

//master监控 看见如图:

 

 用java代码实现 http协议     一个用户等陆  可以显示天猫跳转淘宝  浏览器

 Post方法发送json数据
----------------------------------
a1.sources = r1
a1.sinks = k1
a1.channels = c1

a1.sources.r1.type = org.apache.flume.source.http.HTTPSource
a1.sources.r1.port=8888

a1.sinks.k1.type = logger

a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
----------
[root@linux05 conf]# flume-ng agent -c . -f http.conf -n a1 -Dflume.root.logger=info,console

java代码
package com.bw.tcp;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.URL;
import java.util.Date;

public class TcpTest {
    public static void main(String[] args) throws Exception {
        sendData();
    }

    public static void sendData() {
        try {
            URL url = new URL("http://linux05:8888");
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();

            connection.setDoInput(true); // 设置可输入
            connection.setDoOutput(true); // 设置该连接是可以输出的
            connection.setRequestMethod("POST"); // 设置请求方式
            connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");

            PrintWriter pw = new PrintWriter(new BufferedOutputStream(connection.getOutputStream()));
            pw.write("[{ \"headers\" :{\"a\" : \"a1\",\"b\" : \"b1\"},\"body\" : \"test java http\"}]");
            pw.flush();
            pw.close();

            BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
            String line = null;
            StringBuilder result = new StringBuilder();
            while ((line = br.readLine()) != null) { // 读取数据
                result.append(line + "\n");
            }
            connection.disconnect();

            System.out.println(result.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}

 

 

转载于:https://www.cnblogs.com/JBLi/p/10864788.html

<think>嗯,用户明确要求了解Flume 1.9.0版本的下载、使用指南和新特性。从对话历史看,用户之前接触过Flume的基本概念,现在需要具体版本的操作指导。用户可能是大数据工程师或运维人员,正在评估版本升级的可能性。 关于下载部分,需要强调官方渠道的重要性。Apache官网的下载页面有多个镜像源,用户可能遇到下载速度问题,可以建议选择国内镜像。另外注意到1.9.0是较新版本(2021年发布),要提醒用户检查系统环境是否满足要求,特别是Java版本。 使用指南方面,用户提供的引用[2]里有基础命令示例,可以在此基础上补充1.9.0特有的配置项。考虑到用户可能从旧版本迁移,需要对比说明配置文件的变化。比如1.9.0优化了Kafka Sink的配置逻辑,这个在引用[3]的集成案例中提到过。 新特性要重点展开三个维度:首先是安全增强,TLS和Kerberos的支持在企业级场景很关键;其次是监控改进,Prometheus集成对运维友好;最后是核心优化如内存通道改进,这对高吞吐场景很重要。用户如果关注性能,可以结合引用[5]的Event结构说明序列化优化。 突然想到用户没问但可能需要的点:1.9.0是否兼容Hadoop 3.x?从发行说明看是全面支持的,这点应该明确。另外升级注意事项比如配置文件的向后兼容性,虽然用户没问,但在回答里提及会更实用。 生成的问题要引导用户深入:性能调优和监控是实际部署的痛点,故障排查则针对常见问题。用户提供的引用[4]提到多模态数据场景,可以关联新特性的多源支持。</think>以下是关于Apache Flume 1.9.0版本的**下载方式、使用指南及核心新特性**的详细说明: --- ### **一、Flume 1.9.0 下载** #### **官方渠道** 1. **Apache官网下载** 访问 [Apache Flume 官方下载页](https://flume.apache.org/download.html) 选择 `flume-1.9.0-bin.tar.gz`(二进制发行版) ```bash # 示例下载命令(推荐使用国内镜像加速) wget https://archive.apache.org/dist/flume/1.9.0/apache-flume-1.9.0-bin.tar.gz ``` 2. **验证文件完整性** 下载后需校验SHA-512哈希值(官方提供校验文件 `apache-flume-1.9.0-bin.tar.gz.sha512`): ```bash sha512sum -c apache-flume-1.9.0-bin.tar.gz.sha512 ``` --- ### **二、使用指南** #### **1. 安装与配置** - **依赖环境**:Java 8+(需配置`JAVA_HOME`) - **解压安装**: ```bash tar -zxvf apache-flume-1.9.0-bin.tar.gz cd apache-flume-1.9.0-bin ``` - **配置Agent**: 编辑 `conf/flume.conf`,定义Source、Channel、Sink(示例:监听目录新增文件): ```properties # 定义Agent组件 a1.sources = r1 a1.channels = c1 a1.sinks = k1 # 配置Spooling Directory Source a1.sources.r1.type = spooldir a1.sources.r1.spoolDir = /path/to/logs # 使用内存Channel a1.channels.c1.type = memory a1.channels.c1.capacity = 10000 # 配置Logger Sink(输出到控制台) a1.sinks.k1.type = logger # 绑定组件 a1.sources.r1.channels = c1 a1.sinks.k1.channel = c1 ``` #### **2. 启动Agent** ```bash bin/flume-ng agent -n a1 -c conf -f conf/flume.conf -Dflume.root.logger=INFO,console ``` > **参数说明**: > `-n` Agent名称,`-c` 配置目录,`-f` 配置文件[^2] --- ### **三、1.9.0 核心新特性** #### **1. 安全增强** - **TLS加密支持**:新增对HTTP Source/Sink的TLS/SSL加密传输,防止数据窃听。 - **Kerberos身份验证**:完善Kafka Sink的Kerberos认证集成,提升企业级安全性[^5]。 #### **2. 监控与管理优化** - **Prometheus Metrics**:原生集成Prometheus监控指标,替代已弃用的Ganglia支持。 - **JSON格式化输出**:`logger` Sink支持JSON格式日志,便于ELK等系统采集分析。 #### **3. 性能与稳定性** - **内存通道改进**:优化`Memory Channel`的队列管理策略,降低OOM风险。 - **Kafka Sink重试机制**:增强对Kafka集群故障的自动重试能力,提升可靠性[^3]。 #### **4. 新组件支持** - **gRPC Source**:新增基于gRPC协议的Source,支持跨语言数据接入。 - **Elasticsearch 7 Sink**:兼容Elasticsearch 7.x版本的REST API,适配最新ES生态。 --- ### **四、与其他工具的集成** - **Kafka集成**:通过`Kafka Source/Sink`实现高吞吐缓冲(参考引用[3])。 - **Spark/Flink联动**:Flume采集的数据可直接推送至Spark Streaming或Flink实时处理[^4]。 --- ### **注意事项** - **配置兼容性**:1.9.0的配置文件语法与旧版兼容,但需验证自定义插件兼容性。 - **资源限制**:内存通道(`Memory Channel`)需根据数据量调整`capacity`和`transactionCapacity`,避免溢出。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值