Flume环境搭建_五种案例

http://flume.apache.org/FlumeUserGuide.html

A simple example

Here, we give an example configuration file, describing a single-node Flume deployment. This configuration lets a user generate events and subsequently logs them to the console.

# example.conf: A single-node Flume configuration

# 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

This configuration defines a single agent named a1. a1 has a source that listens for data on port 44444, a channel that buffers event data in memory, and a sink that logs event data to the console. The configuration file names the various components, then describes their types and configuration parameters. A given configuration file might define several named agents; when a given Flume process is launched a flag is passed telling it which named agent to manifest.

Given this configuration file, we can start Flume as follows:

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

Note that in a full deployment we would typically include one more option: --conf=<conf-dir>. The <conf-dir> directory would include a shell script flume-env.sh and potentially a log4j properties file. In this example, we pass a Java option to force Flume to log to the console and we go without a custom environment script.

From a separate terminal, we can then telnet port 44444 and send Flume an event:

$ telnet localhost 44444
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
Hello world! <ENTER>
OK

The original Flume terminal will output the event in a log message.

12/06/19 15:32:19 INFO source.NetcatSource: Source starting
12/06/19 15:32:19 INFO source.NetcatSource: Created serverSocket:sun.nio.ch.ServerSocketChannelImpl[/127.0.0.1:44444]
12/06/19 15:32:34 INFO sink.LoggerSink: Event: { headers:{} body: 48 65 6C 6C 6F 20 77 6F 72 6C 64 21 0D Hello world!. }

Congratulations - you’ve successfully configured and deployed a Flume agent! Subsequent sections cover agent configuration in much more detail.

以下为具体搭建流程

Flume搭建_案例一:单个Flume

 

安装node2上

1.   上传到/home/tools,解压,解压后移动到/home下

2.   重命名,并修改flume-env.sh

vi flume-env.sh

 
3.   配置Flume的环境变量
vi /etc/profile

source /etc/profile
查看Flume的版本,看Flume的环境变量是否配置成功

 
4.    在/home下创建tests_flume, 并创建flume配置文件

cd test_flume
vi flume1
 
5.    命令测试Flume是否安装成功
flume-ng agent --conf /home/test_flume --conf-file /home/test_flume/flume1 --name a1 -Dflume.root.logger=INFO,console

 
安装telnet
随意输入 
hi flume

切换窗口查看

 
退出 ctrl+]  quit
 

Flume搭建_案例二:两个Flume做集群

安装node1,node2上
  1. MemoryChanel配置
  2. capacity:默认该通道中最大的可以存储的event数量是100,
  3. trasactionCapacity:每次最大可以从source中拿到或者送到sink中的event数量也是100
  4. keep-alive:event添加到通道中或者移出的允许时间
  5. byte**:即event的字节量的限制,只包括eventbody
1.   node1,node2,上传压缩包到/home/tools下,解压,
2.

修改conf下的flume-env.sh中的java环境变量,
3.

在/etc/profile下

配置Flume的环境变量
4.

node1,node2下创建测试目录test_flume,并分别在node1,node2下创建配置文件——flume21,flume22

node1下创建flume21

 
node2下创建flume22

 
5.   node1,node2分别启动flume(注意因为node2在后面,所以先启动node2中flume,再启动node1中flume)
  1. 先启动node02的Flume
  2. flume-ng agent -n a1 -c conf -f avro.conf -Dflume.root.logger=INFO,console
  3. flume-ng agent -n a1 -c conf -f /home/test_flume/flume22 -Dflume.root.logger=INFO,console
  4. 再启动node01的Flume
  5. flume-ng agent -n a1 -c conf -f simple.conf2 -Dflume.root.logger=INFO,console
  6. flume-ng agent -n a1 -c conf -f /home/test_flume/flume21 -Dflume.root.logger=INFO,console
node2:

node1:

 
6.   打开telnet测试,node2输出结果

 

Flume搭建_案例三:如何监控一个文件的变化?

安装node2上
1.   node2,上传压缩包到/home/tools下,解压,
2.

修改conf下的flume-env.sh中的java环境变量,
3.

在/etc/profile下

配置Flume的环境变量
4.
node2下创建测试目录test_flume,node2下创建配置文件——flume3
mkdir test_flume
vi flume3

 
5.    node2启动flume
  1. 启动Flume
  2. flume-ng agent -n a1 -c conf -f exec.conf -Dflume.root.logger=INFO,console
  3. flume-ng agent -n a1 -c conf -f /home/test_flume/flume3 -Dflume.root.logger=INFO,console
6.    测试
在/home/test_flume下创建空文件演示 touch flume.exec.log
循环添加数据
for i in {1..50}; do echo "$i hi flume" >> flume.exec.log ; sleep 0.1; done

 
 

Flume搭建_案例四: 如何监控一个文件:目录的变化?

安装node2上
1.   node2,上传压缩包到/home/tools下,解压,
2.

修改conf下的flume-env.sh中的java环境变量,
3.

在/etc/profile下

配置Flume的环境变量
4.
node2下创建测试目录test_flume,node2下创建配置文件——flume4
mkdir test_flume
vi flume4

 
5.    node2启动flume

6.    测试

 
 

Flume搭建_案例五: 如何定义一个HDFS类型的Sink?

安装node2上

Flume搭建_案例五_配置项解读

1.   Flume中日期的格式
   什么时候会用?
       Flume收集的时候根据时间来创建,比如今天的产生的数据就创建20170216,昨天的就放在20170215下
!注意

 
2.   Flume是如何找到HDFS?
    Flume如果配置的是hdfs,它会根据系统中配置的环境变量去找
 
3.   Flume什么时候滚动生成新文件?
滚动的间隔,大小,数量
hdfs.rollInterval 30 Number of seconds to wait before rolling current file (0 = never roll based on time interval)
hdfs.rollSize 1024 File size to trigger roll, in bytes (0: never roll based on file size)
hdfs.rollCount 10 Number of events written to file before it rolled (0 = never roll based on number of events)

4.   多长时间没有操作,Flume将一个临时文件生成新文件?

hdfs.idleTimeout 0 Timeout after which inactive files get closed (0 = disable automatic closing of idle files)

5.   多长时间生成一个新的目录?(比如每10s生成一个新的目录)

四舍五入,没有五入,只有四舍

(比如57分划分为55分,5,6,7,8,9在一个目录,10,11,12,13,14在一个目录)

hdfs.round false Should the timestamp be rounded down (if true, affects all time based escape sequences except %t)
hdfs.roundValue 1 Rounded down to the highest multiple of this (in the unit configured using hdfs.roundUnit), less than current time.
hdfs.roundUnit second The unit of the round down value - secondminute or hour.
1.   node2,上传压缩包到/home/tools下,解压,
2.

修改conf下的flume-env.sh中的java环境变量,
3.

    在/etc/profile下

配置Flume的环境变量
4.
node2下创建测试目录test_flume,node2下创建配置文件——flume5
mkdir test_flume
vi flume5

 
5.    node2启动flume

 
6.    测试
查看hdfs文件
hadoop fs -ls /flume/...
hadoop fs -get /flume/...

 

Flume环境搭建_五种案例的更多相关文章

  1. Flume环境搭建_五种案例(转)

    Flume环境搭建_五种案例 http://flume.apache.org/FlumeUserGuide.html A simple example Here, we give an example ...

  2. Hadoop Hive概念学习系列之hive三种方式区别和搭建、HiveServer2环境搭建、HWI环境搭建和beeline环境搭建(五)

     说在前面的话 以下三种情况,最好是在3台集群里做,比如,master.slave1.slave2的master和slave1都安装了hive,将master作为服务端,将slave1作为服务端. 以 ...

  3. 从环境搭建到回归神经网络案例,带你掌握Keras

    摘要:Keras作为神经网络的高级包,能够快速搭建神经网络,它的兼容性非常广,兼容了TensorFlow和Theano. 本文分享自华为云社区<[Python人工智能] 十六.Keras环境搭建 ...

  4. 03 Mybatis:01.Mybatis课程介绍及环境搭建&&02.Mybatis入门案例

    mybatis框架共四天第一天:mybatis入门 mybatis的概述 mybatis的环境搭建 mybatis入门案例 -------------------------------------- ...

  5. Kafka开发环境搭建(五)

    如果你要利用代码来跑kafka的应用,那你最好先把官网给出的example先在单机环境和分布式环境下跑通,然后再逐步将原有的consumer.producer和broker替换成自己写的代码.所以在阅 ...

  6. [刘阳Java]_EasyUI环境搭建_第2讲

    在EasyUI的第1讲中我们介绍了学习EasyUI能够做什么,这次我们得快速搭建一个EasyUI环境,来测试一下它的运行效果 1.jQuery EasyUI环境搭建 <script type=& ...

  7. 第3章 文件I/O(5)_五种I/O模型

    6. I/O处理方式(5种I/O模型) 6.1 几个概念的辨析 (1)同步和异步 ①是访问数据的方式,主要是针对IO(资源.数据)而言的.关键在于I/O操作完成后,有没有提供通知机制. ②同步的IO, ...

  8. Linux 下LAMP环境搭建_【all】

    LAMP = Linux + Apache + Mysql + PHP 0. Linux环境搭建 Linux 系统安装[Redhat] 1.http服务软件分类及企业实战用途介绍 静态程序: Apac ...

  9. Linux 下LNMP环境搭建_【all】

    LNMP = Linux + Nginx + Mysql + PHP 1.0 Linux环境搭建 Linux 系统安装[Redhat] 1.1. FastCGI介绍 1.什么是CGI(common g ...

随机推荐

  1. WebSocket协议:5分钟从入门到精通

    一.内容概览 WebSocket的出现,使得浏览器具备了实时双向通信的能力.本文由浅入深,介绍了WebSocket如何建立连接.交换数据的细节,以及数据帧的格式.此外,还简要介绍了针对WebSocke ...

  2. python_第2课

    前言 回顾一下python+selenium基础,并整理相关知识点,分享给有需要,在前进道路上的朋友. 由于不是在python中敲的代码,有可能有缩进等相关错误,请自行检查 数据类型 #python中 ...

  3. php mysql语句预编译(preparestatement)

    预处理语句用于执行多个相同的 SQL 语句,并且执行效率更高. 预处理语句的工作原理如下: 预处理:创建 SQL 语句模板并发送到数据库.预留的值使用参数 "?" 标记 .例如: ...

  4. TSLint提示错误

    要成为优秀的TS开发人员,必须直接禁用TS的不良特性. 为此,道爷亲自操刀编写了TSLint工具,用来分析我们的TS代码,把潜在的Bug和不良代码全部找出来. 目的是为了保证TS的质量,但是存在的问题 ...

  5. Winform跨窗体操作控件(使用委托)

    Winform跨窗体操作控件是winform开发中很常见的形式,最常见且简单有效的方式便是使用委托的方式来进行操作,下面我将通过一个小实例来说明如何使用委托跨窗体实现控件操作. 实例介绍:两个窗体,F ...

  6. 记一次电信反射xss的挖掘与利用

    0X0.前言 早上起床,打开手机习惯性刷刷新闻,却发现网络无法连接,本以为是光猫出现了问题,后来发现是忘记续费,欠费了. 在网上充值完之后,等了有将近十分钟,网依旧没恢复.随打了个电话给客服,客服在后 ...

  7. TPFrame框架之robot模块的基本使用

    经过几天的努力,基本功能版已经完成,有待大家验证... robot插件主要的功能是帮助我们写部分代码的基本,目前阶段已经实现后台curd数据管理的基本操作,更多功能待续... 1.首先下载robot插 ...

  8. Unity3d 协程

    参考文章: http://blog.csdn.net/onafioo/article/details/48979939 http://www.cnblogs.com/zhaoqingqing/p/37 ...

  9. Android Studio C/C++开发环境配置

    Android Studio C/C++开发环境配置  我的开发环境 : Win 10 + android studio 1.5   一, 安装NDK 开发环境: 1.  Settings -> ...

  10. iOS 应用全部添加滑动返回

    if ([self  class] == [HomeViewController class]||[self  class] == [ComprehensivefinanceViewControlle ...