`
fengfangfang
  • 浏览: 25974 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

flume使用入门

 
阅读更多

1.下载apache-flume-1.4.0-bin.tar.gz并解压

tar -xzvf apache-flume-1.4.0-bin.tar.gz
cd apache-flume-1.4.0-bin

 


2.创建一个简单的flume配置文件,内容如下:

   vi a1.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

 

3.启动flumeng

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

 

 

4.在另一个控制台,启用telnet

 telnet localhost 44444
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
hello world
OK


将会在步骤3中的控制台中看到flume接收到的消息。

在步骤3中的控制台按ctrl+C,中止测试。

 

5.修改a1的来源为从日志文件中获取数据

修改后的内容如下:

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /var/log/secure

# 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

 

6.再次启动flumeng

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

 


打开新的ssh客户端,输入用户名密码登录本服务器,将会看到flume有日志产生

但看到的日志不完整

/var/log/secure中的内容为:

Mar 12 14:50:21 web5 sshd[9856]: Accepted password for root from 10.0.2.11 port 1135 ssh2
Mar 12 14:50:21 web5 sshd[9856]: pam_unix(sshd:session): session opened for user root by (uid=0)

flume控制台内容为:
2014-03-12 06:50:21,571 (SinkRunner-PollingRunner-DefaultSinkProcessor) [INFO - org.apache.flume.sink.LoggerSink.process(LoggerSink.java:70)] Event: { headers:{} body: 4D 61 72 20 31 32 20 31 34 3A 35 30 3A 32 31 20 Mar 12 14:50:21  }
2014-03-12 06:50:25,575 (SinkRunner-PollingRunner-DefaultSinkProcessor) [INFO - org.apache.flume.sink.LoggerSink.process(LoggerSink.java:70)] Event: { headers:{} body: 4D 61 72 20 31 32 20 31 34 3A 35 30 3A 32 31 20 Mar 12 14:50:21  }

 

7.为flume添加个文件sink

修改后的a1.conf文件为:

# Name the components on this agent
a1.sources = r1
a1.sinks = k1 k2
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /var/log/secure

# Describe the sink
a1.sinks.k1.type = logger
a1.sinks.k2.type = file_roll
a1.sinks.k2.sink.directory = /tmp/flume
# 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
a1.sinks.k2.channel = c1

 

重新启动flume后,会在/tmp/flume下生成数据

查看/tmp/flume下的文件,和flume控制台的数据,感觉二者把日志的数据分开了,
一部分日志数据显示在控制台,一部分数据保存到了/tmp/flume下的文件里


/var/log/secure中内容为:

Mar 12 14:50:21 web5 sshd[9856]: Accepted password for root from 10.0.2.11 port 1135 ssh2
Mar 12 14:50:21 web5 sshd[9856]: pam_unix(sshd:session): session opened for user root by (uid=0)
Mar 12 14:59:36 web5 sshd[10350]: Accepted password for root from 10.0.2.11 port 1193 ssh2
Mar 12 14:59:36 web5 sshd[10350]: pam_unix(sshd:session): session opened for user root by (uid=0)
Mar 12 15:00:56 web5 sshd[10350]: Received disconnect from 10.0.2.11: 11: Disconnect requested by Windows SSH Client.
Mar 12 15:00:56 web5 sshd[10350]: pam_unix(sshd:session): session closed for user root


/tmp/flume下的文件约30秒产生一个。


8.为flume添加个文件channel

修改后的a1.conf文件为:

# Name the components on this agent

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

# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /var/log/secure

# Describe the sink
a1.sinks.k1.type = logger
a1.sinks.k2.type = file_roll
a1.sinks.k2.sink.directory = /tmp/flume
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
a1.channels.c2.type = memory
a1.channels.c2.capacity = 1000
a1.channels.c2.transactionCapacity = 100

# Bind the source and sink to the channel
a1.sources.r1.channels = c1 c2
a1.sources.r1.selector.type = replicating
a1.sinks.k1.channel = c1
a1.sinks.k2.channel = c2

 
 修改后,控制台和/tmp/flume中的内容,与日志就对应上了。

分享到:
评论

相关推荐

    Flume1.6.0入门:安装、部署、及flume的案例

    ### Flume 1.6.0 入门详解:安装、部署及案例分析 #### 一、Flume 概述 Flume 是 Cloudera 开发的一款高效、可靠且易于扩展的日志收集系统,适用于大数据环境下的日志采集任务。Flume 的初始版本被称为 FlumeOG...

    Flume1.5.0入门:安装、部署、及flume的案例

    Apache Flume 是一个强大的、分布式的日志聚合工具,特别适用于大数据环境中的日志收集。Flume 1.5.0 版本是其发展历程中的一个重要里程碑,提供了更稳定、高效和可扩展的功能。以下是对 Flume 的详细介绍: **...

    Flume入门使用.pdf

    以下是对Flume入门使用的详细说明: 1. **Flume 组件配置**: 在`netcat-logger.conf`配置文件中,我们看到Flume的配置主要由三部分组成:Sources、Sinks 和 Channels。 - **Sources**:在这里是`r1`,类型设置为...

    最全Flume视频教程,大数据入门必学

    章节四:入门使用案例 章节五:数据持久化 章节六:日志文件监控 章节七:多个Agent模型 章节八:拦截器 章节九:Channel选择器 章节十:Sink处理器 章节十一:导入数据到HDFS 章节十二:Flume SDK 章节十三:Flume...

    大数据Flume学习视频-免费

    ### 大数据Flume学习视频知识点详解 #### 一、Flume简介与应用场景 Flume是一种高可靠、高性能的服务,用于收集、聚合和移动大量日志数据。它具有灵活的架构,可以根据不同的需求进行配置,并支持多种数据源类型。...

    尚硅谷大数据技术之Flume

    如果需要关心数据丢失,那么 Memory Channel 就不应该使用,因为程序死亡、机器宕机或者重启都会导致数据丢失。File Channel 将所有事件写到磁盘。因此在程序关闭或机器宕机的情况下不会丢失数据。 1.2.4 Sink ...

    入门简介教程-大数据组件flume

    flume入门介绍,简单介绍flume的背景和应用场景,flume的实现原理以及案例分享

    尚硅谷大数据技术之Flume笔记1

    监控端口数据也可以通过Flume进行收集,如案例需求所示,使用Flume来实现实时的数据捕获和传输。 总结来说,Flume是大数据领域的重要工具,它提供了简单而强大的方式来处理和传输日志数据,是构建大数据基础设施不...

    Flume 构建高可用、可扩展的海量日志采集系统

    Flume 快速入门教程,文本数据采集

    java大数据内容_7Flume、Kafka、Sqoop、Lucene

    #### 一、Flume 入门 ##### 1.1 Flume 概述 Flume 是一个分布式的、可靠的、高可用的日志采集系统,主要用于收集、汇总和移动大量的日志数据。它由 Cloudera 公司开发并开源,现已成为了 Hadoop 生态系统中的一个...

    Flume简介及基本使用.md

    Flume简介及基本使用,入门篇

    hadoop集群配置之————flume安装配置(详细版)

    2. 通道是一个被动存储,保存事件直到它们被Flume接收器使用。 3. 接收器(Sink)从通道中移除事件,并将其放入外部存储库,如HDFS,或将其转发到流中的下一个Flume代理。 Flume的组件包括: - Agent:是一个JVM进程...

    Flume基本理论与实践.docx

    Flume的入门案例包括监控端口数据官方案例,使用Flume监听一个端口,收集该端口数据,并打印到控制台。 Flume的应用场景非常广泛,包括大数据采集、日志采集、数据传输等。Flume的优点包括高可用性、灵活性、可靠...

    flime安装+配置+测试+案例(采集日志至HDFS)

    例如,Hadoop 和 Flume 可能会使用不同版本的 Guava 库。为了解决这个问题,我们需要找到高版本的 Guava JAR 文件,并复制到低版本的目录下,重命名低版本以禁用它,确保 Flume 正确运行。 在确保所有组件都已准备...

    flume-appenders:Flume appender 从一系列日志库(log4j、logback)推送日志事件

    - 日志分析:将日志事件推送到 Flume,然后可以使用诸如 Hadoop、Elasticsearch 或 Splunk 进行分析。 - 故障排查:通过 Flume 收集的日志可以帮助快速定位系统中的问题。 - 安全监控:分析日志数据以检测潜在的...

    大数据技术之Flume.docx

    #### 四、Flume快速入门 **2.1 Flume安装地址** - **官方地址**:[http://flume.apache.org/](http://flume.apache.org/) - **文档地址**:[http://flume.apache.org/FlumeUserGuide.html]...

    大数据技术之Flume教程

    #### 二、Flume入门 **2.1 Flume安装部署** 安装Flume前需确保已具备Java运行环境。Flume的下载与安装步骤如下: 1. **2.1.1 安装地址** - **Flume官网地址**: [http://flume.apache.org/]...

Global site tag (gtag.js) - Google Analytics