[root@hadoop01 src]# mkdir flume

[root@hadoop01 src]# ll

总用量 0

drwxr-xr-x. 2 root root  6 4月   7 2017 docker

drwxr-xr-x. 2 root root  6 3月   2 03:04 flume

drwxr-xr-x. 3 root root 51 3月   1 16:52 hadoop

drwxr-xr-x. 3 root root 56 3月   1 00:51 java

drwxr-xr-x. 3 root root 57 3月   1 01:51 zk

[root@hadoop01 src]#

[root@hadoop01 src]# cd flume/

[root@hadoop01 flume]# ll

总用量 51320

-rw-r--r--. 1 root root 52550402 2月   1 2016 apache-flume-1.6.0-bin.tar.gz

上传tar包,解压

[root@hadoop01 flume]# tar -xvf apache-flume-1.6.0-bin.tar.gz

[root@hadoop01 flume]# ll

总用量 51324

drwxr-xr-x. 7 root root     4096 3月   2 03:06 apache-flume-1.6.0-bin

-rw-r--r--. 1 root root 52550402 2月   1 2016 apache-flume-1.6.0-bin.tar.gz

[root@hadoop01 flume]# cd apache-flume-1.6.0-bin

[root@hadoop01 apache-flume-1.6.0-bin]# ll

总用量 136

drwxr-xr-x.  2  501 games    59 3月   2 03:06 bin

-rw-r--r--.  1  501 games 69856 5月   9 2015 CHANGELOG

drwxr-xr-x.  2  501 games  4096 3月   2 03:06 conf

-rw-r--r--.  1  501 games  6172 5月   9 2015 DEVNOTES

drwxr-xr-x. 10  501 games  4096 5月  12 2015 docs

drwxr-xr-x.  2 root root   4096 3月   2 03:06 lib

-rw-r--r--.  1  501 games 25903 5月   9 2015 LICENSE

-rw-r--r--.  1  501 games   249 5月   9 2015 NOTICE

-rw-r--r--.  1  501 games  1779 5月   9 2015 README

-rw-r--r--.  1  501 games  1585 5月   9 2015 RELEASE-NOTES

drwxr-xr-x.  2 root root     67 3月   2 03:06 tools

[root@hadoop01 apache-flume-1.6.0-bin]#

[root@hadoop01 apache-flume-1.6.0-bin]# cd lib

[root@hadoop01 lib]# ll

[root@hadoop01 lib]# cd ../

[root@hadoop01 apache-flume-1.6.0-bin]# ll

总用量 136

drwxr-xr-x.  2  501 games    59 3月   2 03:06 bin

-rw-r--r--.  1  501 games 69856 5月   9 2015 CHANGELOG

drwxr-xr-x.  2  501 games  4096 3月   2 03:06 conf

-rw-r--r--.  1  501 games  6172 5月   9 2015 DEVNOTES

drwxr-xr-x. 10  501 games  4096 5月  12 2015 docs

drwxr-xr-x.  2 root root   4096 3月   2 03:06 lib

-rw-r--r--.  1  501 games 25903 5月   9 2015 LICENSE

-rw-r--r--.  1  501 games   249 5月   9 2015 NOTICE

-rw-r--r--.  1  501 games  1779 5月   9 2015 README

-rw-r--r--.  1  501 games  1585 5月   9 2015 RELEASE-NOTES

drwxr-xr-x.  2 root root     67 3月   2 03:06 tools

[root@hadoop01 apache-flume-1.6.0-bin]# cd conf

[root@hadoop01 conf]# ll

总用量 16

-rw-r--r--. 1 501 games 1661 5月   9 2015 flume-conf.properties.template

-rw-r--r--. 1 501 games 1110 5月   9 2015 flume-env.ps1.template

-rw-r--r--. 1 501 games 1214 5月   9 2015 flume-env.sh.template

-rw-r--r--. 1 501 games 3107 5月   9 2015 log4j.properties

[root@hadoop01 conf]#

[root@hadoop01 conf]# vi flume-conf.properties.template

# Licensed to the Apache Software Foundation (ASF) under one

# or more contributor license agreements.  See the NOTICE file

# distributed with this work for additional information

# regarding copyright ownership.  The ASF licenses this file

# to you under the Apache License, Version 2.0 (the

# "License"); you may not use this file except in compliance

[root@hadoop01 conf]# rm .flume-conf.properties.template.swp

1.1.1    启动Agent

[root@localhost conf]# ../bin/flume-ng agent -c ./ -f ./flume-jt.properties -n a1 -Dflume.root.logger=INFO,console &

#注意在conf配置文件目录下运行

../bin/flume-ng agent -c ./ -f ./flume-avro.properties -n a1 -Dflume.root.logger=INFO,console

../bin/flume-ng       flume有两个版本0.9x flume-og,1.0xflume-ng  Apache把底层代码重构

-c config配置,指定配置文件

在一个固定路径下运行,./ 当前目录,都是在conf,方便加载属性配置文件

-f 配置属性文件,自由指定,flume-avro.properties

-n 给flume设定agent的名称 a1配置文件中agent名称,要和属性文件中的定义的名称一致

-Dflume.root.logger 日志级别log4j INFO/console

上传配置文件

a1.sources  =  r1

a1.sinks  =  k1

a1.channels  =  c1

a1.sources.r1.type  =  avro

a1.sources.r1.bind  =  0.0.0.0

a1.sources.r1.port  =  22222

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

1.1.1.1      启动Agent

flume-avro.properties

[root@localhost conf]#vi flume-avro.properties

[root@localhost conf]# ../bin/flume-ng agent -c ./ -f ./flume-avro.properties -n a1 -Dflume.root.logger=INFO,console

../bin/flume-ng agent -c ./ -f ./flume-avro.properties -n a1 -Dflume.root.logger=INFO,console

flume有两个版本,0.9xflume

-c config配置,指定配置文件

在一个固定路径下运行,./当前目录。都是在conf,方便加载属性配置文件

-f配置属性文件,自由指定,flume-avro.properties

-n指定agent的名称

-Dflume.root.logger日志级别log4j

启动结果:

2017-11-07 19:58:03,708 (lifecycleSupervisor-1-2) [INFO - org.apache.flume.source.AvroSource.start(AvroSource.java:253)] Avro source r1 started.

复制一个连接

[root@hadoop01 bin]# jps

4944 DataNode

2462 QuorumPeerMain

5102 SecondaryNameNode

8201 Application

8479 Jps

4822 NameNode

[root@hadoop01 bin]# ./flume-ng avro-client -c ../conf -H 0.0.0.0 -p 44444 -F ../../log.txt

1.1.1.1      准备数据

cd /usr/local/src/flume           #进入目录

vi log.txt                                    #创建数据文件,内容如下

hi flume.

you are good tools.

[root@hadoop01 ~]# . go

[root@hadoop01 src]# cd flume/apache-flume-1.6.0-bin

[root@hadoop01 apache-flume-1.6.0-bin]# ll

总用量 136

drwxr-xr-x.  2  501 games    59 3月   2 03:06 bin

-rw-r--r--.  1  501 games 69856 5月   9 2015 CHANGELOG

drwxr-xr-x.  2  501 games  4096 3月   2 03:32 conf

-rw-r--r--.  1  501 games  6172 5月   9 2015 DEVNOTES

drwxr-xr-x. 10  501 games  4096 5月  12 2015 docs

drwxr-xr-x.  2 root root   4096 3月   2 03:06 lib

-rw-r--r--.  1  501 games 25903 5月   9 2015 LICENSE

-rw-r--r--.  1  501 games   249 5月   9 2015 NOTICE

-rw-r--r--.  1  501 games  1779 5月   9 2015 README

-rw-r--r--.  1  501 games  1585 5月   9 2015 RELEASE-NOTES

drwxr-xr-x.  2 root root     67 3月   2 03:06 tools

[root@hadoop01 apache-flume-1.6.0-bin]# cd ../

[root@hadoop01 flume]# ll

总用量 51324

drwxr-xr-x. 7 root root     4096 3月   2 03:06 apache-flume-1.6.0-bin

-rw-r--r--. 1 root root 52550402 2月   1 2016 apache-flume-1.6.0-bin.tar.gz

[root@hadoop01 flume]# vi log.txt

[root@hadoop01 flume]#

1.1.1.1      发送avro消息

通过flume提供的avro客户端向指定机器指定端口发送日志信息:

./flume-ng –h               #帮助可以看命令格式及参数用法

./flume-ng avro-client -c ../conf -H 0.0.0.0 -p 44444 -F ../../log.txt

控制台收到消息:

Event:{headers:{}body:68 69 20 55 h1flume}

Flume 将数据封装成一个event,实质json.两个部分。Headers body

[root@hadoop01 src]# cd flume/apache-flume-1.6.0-bin

[root@hadoop01 apache-flume-1.6.0-bin]# ll

总用量 136

drwxr-xr-x.  2  501 games    59 3月   2 03:06 bin

-rw-r--r--.  1  501 games 69856 5月   9 2015 CHANGELOG

drwxr-xr-x.  2  501 games  4096 3月   2 03:32 conf

-rw-r--r--.  1  501 games  6172 5月   9 2015 DEVNOTES

drwxr-xr-x. 10  501 games  4096 5月  12 2015 docs

drwxr-xr-x.  2 root root   4096 3月   2 03:06 lib

-rw-r--r--.  1  501 games 25903 5月   9 2015 LICENSE

-rw-r--r--.  1  501 games   249 5月   9 2015 NOTICE

-rw-r--r--.  1  501 games  1779 5月   9 2015 README

-rw-r--r--.  1  501 games  1585 5月   9 2015 RELEASE-NOTES

drwxr-xr-x.  2 root root     67 3月   2 03:06 tools

[root@hadoop01 apache-flume-1.6.0-bin]# cd bin

root@hadoop01 bin]# ./flume-ng avro-client -c ../conf -H 0.0.0.0 -p 44444 -F ../../log.txt

[root@hadoop01 src]# scp -r flume root@192.168.163.156:/usr/local/src

[root@hadoop01 src]# scp -r flume root@192.168.163.157:/usr/local/src

步骤:

1)  flume,129,130,131(拷贝flume到其他节点上)

scp -r flume root@192.168.163.130:/usr/local/src

scp -r flume root@192.168.163.131:/usr/local/src

2)  配置3个flume.properties,分别配置

3)  各自启动flume-ng

4)  在129上模拟http请求,curl

注意,多个agent,它们如果互相关联,应该从最后一个启动。

启动是有顺序的。

3个节点互相访问,等待所有节点都启动在看是否报错、!!!

[root@hadoop03 src]# cd flume/

[root@hadoop03 flume]# vi cd apache-flume-1.6.0-bin/conf

2 files to edit

[root@hadoop01 src]# cd flume/apache-flume-1.6.0-bin/conf/

[root@hadoop01 conf]# vi flume-avro-sink.properties

[root@hadoop02 src]# cd flume/apache-flume-1.6.0-bin/conf/

[root@hadoop02 conf]#  vi flume-avro-sink.properties

 

[root@hadoop03 flume]# cd apache-flume-1.6.0-bin/conf

[root@hadoop03 conf]# vi flume-avro-sink.properties

1.1.1.1      启动Agent

[root@hadoop03 conf]# ../bin/flume-ng agent -c ./ -f ./flume-avro-sink.properties -n a1 -Dflume.root.logger=INFO,console

[root@hadoop02 conf]# ../bin/flume-ng agent -c ./ -f ./flume-avro-sink.properties -n a1 -Dflume.root.logger=INFO,console

[root@hadoop01 conf]# ../bin/flume-ng agent -c ./ -f ./flume-avro-sink.properties -n a1 -Dflume.root.logger=INFO,console

1.1.1.1      测试

flume01上

curl -X POST -d '[{"headers":{"tester":"tony"},"body":"01 hello more avro flume"}]' http://0.0.0.0:22222

[root@hadoop01 ~]# curl -X POST -d '[{"headers":{"tester":"tony"},"body":"01 hello more avro flume"}]' http://0.0.0.0:22222

flume02上

curl -X POST -d '[{"headers":{"tester":"tony"},"body":"02 hello more avro flume"}]' http://0.0.0.0:22222

注意:信息标识在不同的点上标识在前面,因为标识后面,控制台打印信息时,信息会被截取只显示前面的摘要,就无法看出效果。

1.1.1.1      配置文件flume-hdfs.properties

#命名Agent a1的组件

a1.sources  =  r1

a1.sinks  =  k1

a1.channels  =  c1

#描述/配置Source

a1.sources.r1.type  =  http

a1.sources.r1.port  =  22222

#描述Sink

a1.sinks.k1.type  =  hdfs

a1.sinks.k1.hdfs.path = hdfs://hadoop01:9000/flume/data

#描述内存Channel

a1.channels.c1.type  =  memory

a1.channels.c1.capacity  =  1000

a1.channels.c1.transactionCapacity  =  100

#为Channle绑定Source和Sink

a1.sources.r1.channels  =  c1

a1.sinks.k1.channel  =  c1

[root@hadoop01 conf]# ll

总用量 36

-rw-r--r--. 1 root root   351 2月  28 14:18 flume-avro.properties

-rw-r--r--. 1 root root   419 3月   2 04:26 flume-avro-sink.properties

-rw-r--r--. 1  501 games 1661 3月   2 03:15 flume-conf.properties.templat

-rw-r--r--. 1 root root   345 2月  28 14:52 flume-dir.properties

-rw-r--r--. 1  501 games 1110 5月   9 2015 flume-env.ps1.template

-rw-r--r--. 1  501 games 1214 5月   9 2015 flume-env.sh.template

-rw-r--r--. 1 root root   351 2月  28 14:56 flume-http.properties

-rw-r--r--. 1 root root   353 2月  28 00:37 flume.properties

-rw-r--r--. 1  501 games 3107 5月   9 2015 log4j.properties

[root@hadoop01 conf]# cp flume-http.properties flume-hdfs.properties

[root@hadoop01 conf]# vi flume-hdfs.properties

a1.sources  =  r1

a1.sinks  =  k1

a1.channels  =  c1

a1.sources.r1.type  =  http

a1.sources.r1.bind  =  0.0.0.0

a1.sources.r1.port  =  22222

a1.sinks.k1.type  =  hdfs

a1.sinks.k1.hdfs.path = hdfs://hadoop01:9000/flume/data

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

1.1.1.2      复制依赖jar文件

进入共享目录

cd /usr/local/src/hadoop/hadoop-2.7.1/share/hadoop/common

复制文件

cp *.jar /usr/local/src/flume/apache-flume-1.6.0-bin/lib

cd /usr/local/src/hadoop/hadoop-2.7.1/share/hadoop/hdfs

cp hadoop-hdfs-2.7.1.jar /usr/local/src/flume/apache-flume-1.6.0-bin/lib

/usr/local/src/flume/apache-flume-1.6.0-bin/lib

/usr/local/src/flume/apache-flume-1.6.0-bin/lib

否则启动和运行时会报错:

java.lang.NoClassDefFoundError: org/apache/hadoop/io/SequenceFile$CompressionType

java.io.IOException: No FileSystem for scheme: hdfs

[root@hadoop01 ~]# cd /usr/local/src/hadoop/

[root@hadoop01 hadoop]#

[root@hadoop01 hadoop]# cd /usr/local/src/hadoop/hadoop-2.7.1/share/hadoop/common

[root@hadoop01 common]#

[root@hadoop01 common]# ll

总用量 5336

-rw-r--r--. 1 10021 10021 3429485 6月  29 2015 hadoop-common-2.7.1.jar

-rw-r--r--. 1 10021 10021 1862002 6月  29 2015 hadoop-common-2.7.1-tests.jar

-rw-r--r--. 1 10021 10021  159466 6月  29 2015 hadoop-nfs-2.7.1.jar

drwxr-xr-x. 2 10021 10021    4096 6月  29 2015 jdiff

drwxr-xr-x. 2 10021 10021    4096 6月  29 2015 lib

drwxr-xr-x. 2 10021 10021      87 6月  29 2015 sources

drwxr-xr-x. 2 10021 10021      26 6月  29 2015 templates

[root@hadoop01 common]#

[root@hadoop01 common]# cp *.jar /usr/local/src/flume/apache-flume-1.6.0-bin/lib

[root@hadoop01 common]# cd ..

[root@hadoop01 hadoop]# cd hdfs

[root@hadoop01 hdfs]#

[root@hadoop01 hdfs]# ll

总用量 11332

-rw-r--r--. 1 10021 10021 8240823 6月  29 2015 hadoop-hdfs-2.7.1.jar

-rw-r--r--. 1 10021 10021 3244566 6月  29 2015 hadoop-hdfs-2.7.1-tests.jar

-rw-r--r--. 1 10021 10021  102458 6月  29 2015 hadoop-hdfs-nfs-2.7.1.jar

drwxr-xr-x. 2 10021 10021    4096 6月  29 2015 jdiff

drwxr-xr-x. 2 10021 10021    4096 6月  29 2015 lib

drwxr-xr-x. 2 10021 10021      83 6月  29 2015 sources

drwxr-xr-x. 2 10021 10021      26 6月  29 2015 templates

drwxr-xr-x. 8 10021 10021      86 6月  29 2015 webapps

[root@hadoop01 hdfs]#

[root@hadoop01 hdfs]# cp hadoop-hdfs-2.7.1.jar /usr/local/src/flume/apache-flume-1.6.0-bin/lib

1.1.1.3      启动Agent

[root@localhost conf]# ../bin/flume-ng agent -c ./ -f ./flume-hdfs.properties -n a1 -Dflume.root.logger=INFO,console

执行结果,飞速打印结果

[root@hadoop01 conf]# ../bin/flume-ng agent -c ./ -f ./flume-hdfs.properties -n a1 -Dflume.root.logger=INFO,console

1.1.1.4      模拟发HTTP请求

在flume01节点上发送消息

curl -X POST -d '[{"headers":{"tester":"tony"},"body":"hello http flume"}]' http://0.0.0.0:22222

执行结果:

[root@hadoop01 hdfs]# curl -X POST -d '[{"headers":{"tester":"tony"},"body":"hello 5555 http flume"}]' http://0.0.0.0:22222

org.apache.flume.sink.hdfs.BucketWriter.open(BucketWriter.java:234)] Creating hdfs://hadoop01:9000/flume/data/FlumeData.1510560200492.tmp

在控制台打印信息只取局部,截串。不是传递时信息缺失。

a1.sources  =  r1

a1.sinks  =  k1

a1.channels  =  c1

a1.sources.r1.type  =  netcat

a1.sources.r1.bind  =  0.0.0.0

a1.sources.r1.port  =  22222

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

Flume搭建的更多相关文章

  1. Flume搭建及学习(基础篇)

    转载请注明原文出处:http://www.cnblogs.com/lighten/p/6830439.html 1.简介 该文主要是翻译官方的相关文档,源地址点击这里.介绍一下Flume的一些基本知识 ...

  2. flume搭建新手测试环境

    硬件环境: 腾讯云,两台服务器8G 双核 软件环境: flume1.8.jdk1.8,centos6 第一次搭建也是各种找文件,只知道flume是日志抓取服务,也听说了非常稳定强大的服务,正好公司需要 ...

  3. flume 搭建

    Flume使用 1安装及修改初始环境 安装见:http://blog.csdn.net/qianshangding0708/article/details/48088611 配置在conf目录下配置如 ...

  4. 新手入门Flume搭建部署

    在root的用户下 1):• 前提 安装JDK环境 2):• 在官网下载Flume,http://mirror.bit.edu.cn/apache/flume 既是:wget  http://mirr ...

  5. Flume环境搭建_五种案例

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

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

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

  7. flume learning---Flume 集群搭建

    在flume搭建集群模式时,首先需要进入conf目录, 1.cp flume-env.sh.template flume-env.sh 2.cp flume-conf.properties.templ ...

  8. Flume NG Getting Started(Flume NG 新手入门指南)

    Flume NG Getting Started(Flume NG 新手入门指南)翻译 新手入门 Flume NG是什么? 有什么改变? 获得Flume NG 从源码构建 配置 flume-ng全局选 ...

  9. flume 前世今生

    Cloudera 开发的分布式日志收集系统 Flume,是 hadoop 周边组件之一.其可以实时的将分布在不同节点.机器上的日志收集到不同的存储系统.Flume 初始的发行版本目前被统称为 Flum ...

随机推荐

  1. mysql 学习心得3

    1 /0和 %0 都会显示null 2比较运算符大部分和c一样 ==在mysql是=  <>代表不等于 between 指定范围内 in指定几何 isnull 判断是否为null :is ...

  2. FineUIPro控件库深度解析

    FineUIPro控件库 FineUIPro是一套基于jQuery的专业ASP.NET控件库,始于2008年的开源版FineUI控件库. 当年为了提升项目的开发效率,降低代码复杂度,减少对CSS和Ja ...

  3. JVM笔记4-对象的创建

    1.对象的创建过程: 1.new 类名 2.根据new的参数在常量池中定位一个类的符号的引用. 3.如果没找到这个符号的引用,说明类还没有被加载.则进行类的加载,解析和初始化 4.虚拟机为对象分配内存 ...

  4. zTree实现获取一级节点数据

    zTree实现获取一级节点数据 1.实现源码 <!DOCTYPE html> <html> <head> <title>zTree实现基本树</t ...

  5. DOS批处理命令递归删除给定的文件(夹),兼VC工程清理小工具

    使用dos批处理命令递归删除指定的文件(夹): (下面内容针对清理VC工程!自己按说明任意修改) 2014-06-10修改:删除前增加了[y,n]询问: echo off rem 递归删除当前文件下指 ...

  6. WDF驱动的编译、调试、安装

    编译和调试使用WDK编译,源代码应包括wdf.h,ntddk.h以及KMDF_VERSION=1,编译使用/GS.KMDF包括以下库:1). WdfDriverEntry.lib(编译时绑定):驱动入 ...

  7. flask中jinjia2模板引擎使用详解5

    接上文 宏 可以理解为函数,即把一些常用的模板片段做好封装,以便于重用,减少工作量和维护难度. 宏的定义很简单: {%macro xxx()%} ##这里写内容 {%endmacro%}   下面引用 ...

  8. Educational Codeforces Round37 E - Connected Components?

    #include <algorithm> #include <cstdio> #include <iostream> #include <queue> ...

  9. Good Bye 2017 E. New Year and Entity Enumeration

    先按照绿点进行分块 第一个绿点和最后一个绿点之后很好处理不说了 两个绿点之间的讨论: 有两种方案 1:红(蓝)点和绿点顺序连接,距离为相邻绿点距离(也就是双倍绿点距离) 2:红(蓝)点和绿点的点阵中寻 ...

  10. 觉得OpenStack的网络复杂?其实你家里就有同样一个网络

    当你想了解OpenStack的Neutron网络,打开下面这张图的时候,心里一定是崩溃的,看起来这些模块连在一起很复杂,但其实和你家里的网络很像,看不出来?看我来慢慢解析. 其实这个网络的样子更像是我 ...