企业中的日志存放_1

201611/20161112.log.tmp
  第二天文件变为20161112.log与20161113.log.tmp
拷贝一份flume-conf.properties.template改名为dir-mem-hdfs.properties
实现监控某一目录,如有新文件产生则上传至hdfs,另外过滤掉新文件中tmp文件
dir-mem-hdfs.properties
  a1.sources = s1
  a1.channels = c1
  a1.sinks = k1
  # defined the source
  a1.sources.s1.type = spooldir
  a1.sources.s1.spoolDir = /opt/data/log_hive/20161109
  a1.sources.s1.includePattern = ([^ ]*\.log$) # 包含某些字段
  a1.sources.s1.ignorePattern = ([^ ]*\.tmp$) # 忽略某些字段
  # defined the channel
  a1.channels.c1.type = memory
  a1.channels.c1.capacity = 1000
  a1.channels.c1.transactionCapacity = 1000
  # defined the sink
  a1.sinks.k1.type = hdfs
  a1.sinks.k1.hdfs.useLocalTimeStamp = true
  a1.sinks.k1.hdfs.path = /flume/spdir
  a1.sinks.k1.hdfs.fileType = DataStream
  a1.sinks.k1.hdfs.rollInterval = 0
  a1.sinks.k1.hdfs.rollSize = 20480
  a1.sinks.k1.hdfs.rollCount = 0
  # The channel can be defined as follows.
  a1.sources.s1.channels = c1
  a1.sinks.k1.channel = c1
flmue目录下执行
  bin/flume-ng agent -c conf/ -n a1 -f conf/dir-mem-hdfs.properties -Dflume.root.logger=INFO,console
  这里使用了memory channel,可以使用file channel更加安全

企业中的日志存放_2

201611/20161112.log
  第二天文件继续往20161112.log写
这样,既要使用exec和spoolingdir,如何处理
编译flume1.7版tail dir source,并集成到我们已有的flume环境
  1. window上下载安装git
  2. 在某个目录下加一个空的文件夹(文件夹路径尽量不要有中文),例GitHub
  3. 使用github常用命令
    $ pwd
    $ ls
    $ cd /C/Users/Administrator/Desktop/GitHub
    $ git clone (https|git)://github.com/apache/flume.git
    $ cd flume
    $ git branch -r # 查看有哪些分支
    $ git branch -r # 查看当前属于哪个分支
    $ git checkout origin/flume-1.7 #别换分支
  拷贝flume\flume-ng-sources\flume-taildir-source
  使用eclipse导入flume-taildir-source项目
  修改pom.xml
  <repositories>
    <repository>
      <id>cloudera</id>
      <url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
    </repository>
  </repositories>
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.apache.flume.flume-ng-sources</groupId>
  <artifactId>flume-taildir-source</artifactId>
  <version>1.5.0-cdh5.3.6</version>
  <name>Flume Taildir Source</name>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>org.apache.flume</groupId>
      <artifactId>flume-ng-core</artifactId>
      <version>1.5.0-cdh5.3.6</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.10</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  4. MAVEN_BULID项目,获取jar包并放到当前flume的环境中(lib目录)
  5. 创建文件夹和文件
    $ mkdir -p /opt/cdh-5.6.3/apache-flume-1.5.0-cdh5.3.6-bin/position
    $ mkdir -p /opt/data/tail/hadoop-dir/
    $ echo "" > /opt/data/tail/hadoop.log
    拷贝一份flume-conf.properties.template改名为tail-mem-hdfs.properties
    可从源码看出需要的参数
      a1.sources = s1
      a1.channels = c1
      a1.sinks = k1
      # defined the source
      a1.sources.s1.type = org.apache.flume.source.taildir.TaildirSource
      a1.sources.s1.positionFile = /opt/cdh-5.6.3/apache-flume-1.5.0-cdh5.3.6-bin/position/taildir_position.json
      a1.sources.s1.filegroups = f1 f2
      a1.sources.s1.filegroups.f1 = /opt/data/tail/hadoop.log
      a1.sources.s1.filegroups.f2 = /opt/data/tail/hadoop-dir/.*
      a1.sources.s1.headers.f1.headerKey1 = value1
      a1.sources.s1.headers.f2.headerKey1 = value2-1
      a1.sources.s1.headers.f2.headerKey2 = value2-2
      a1.sources.s1.fileHeader = true
      # defined the channel
      a1.channels.c1.type = memory
      a1.channels.c1.capacity = 1000
      a1.channels.c1.transactionCapacity = 1000
      # defined the sink
      a1.sinks.k1.type = hdfs
      a1.sinks.k1.hdfs.useLocalTimeStamp = true
      a1.sinks.k1.hdfs.path = /flume/spdir
      a1.sinks.k1.hdfs.fileType = DataStream
      a1.sinks.k1.hdfs.rollInterval = 0
      a1.sinks.k1.hdfs.rollSize = 20480
      a1.sinks.k1.hdfs.rollCount = 0
      # The channel can be defined as follows.
      a1.sources.s1.channels = c1
      a1.sinks.k1.channel = c1
  flmue目录下执行
    bin/flume-ng agent -c conf/ -n a1 -f conf/tail-mem-hdfs.properties -Dflume.root.logger=INFO,console
    测试文件或新数据

企业中常用架构 Flume多sink

同一份数据采集到不同框架处理
采集source: 一份数据
管道channel: 多个
目标sink: 多个
如果多个sink从一个channel取数据将取不完整,而source会针对channel分别发送
设计: source--hive.log channel--file sink--hdfs(不同路径)
拷贝一份flume-conf.properties.template改名为hive-file-sinks.properties
hive-file-sinks.properties
  a1.sources = s1
  a1.channels = c1 c2
  a1.sinks = k1 k2
  # defined the source
  a1.sources.s1.type = exec
  a1.sources.s1.command = tail -F /opt/cdh-5.6.3/hive-0.13.1-cdh5.3.6/logs/hive.log
  a1.sources.s1.shell = /bin/sh -c
  # defined the channel 1
  a1.channels.c1.type = file
  a1.channels.c1.checkpointDir = /opt/cdh-5.6.3/apache-flume-1.5.0-cdh5.3.6-bin/datas/checkp1
  a1.channels.c1.dataDirs = /opt/cdh-5.6.3/apache-flume-1.5.0-cdh5.3.6-bin/datas/data1
  # defined the channel 2
  a1.channels.c2.type = file
  a1.channels.c2.checkpointDir = /opt/cdh-5.6.3/apache-flume-1.5.0-cdh5.3.6-bin/datas/checkp2
  a1.channels.c2.dataDirs = /opt/cdh-5.6.3/apache-flume-1.5.0-cdh5.3.6-bin/datas/data2
  # defined the sink 1
  a1.sinks.k1.type = hdfs
  a1.sinks.k1.hdfs.path = /flume/hdfs/sink1
  a1.sinks.k1.hdfs.fileType = DataStream
  # defined the sink 2
  a1.sinks.k2.type = hdfs
  a1.sinks.k2.hdfs.path = /flume/hdfs/sink2
  a1.sinks.k2.hdfs.fileType = DataStream
  # The channel can be defined as follows.
  a1.sources.s1.channels = c1 c2
  a1.sinks.k1.channel = c1
  a1.sinks.k2.channel = c2
flmue目录下执行
  bin/flume-ng agent -c conf/ -n a1 -f conf/hive-file-sinks.properties -Dflume.root.logger=INFO,console
hive目录下执行
  bin/hive -e "show databases"

Flume_企业中日志处理的更多相关文章

  1. 东正王增涛浅析OA信息化整合平台系统在企业中的应用价值

    王增涛说OA信息化整合平台系统作为企业管理中最基础的管理软件,已在企业成长道路上存在多年,它的应用开启了智能移动办公的先河,也让企业的办公流程管理更加的便捷.高效.流畅.省时.省力,它的使用不但让企业 ...

  2. 利用log4j+mongodb实现分布式系统中日志统一管理

    背景     在分布式系统当中,我们有各种各样的WebService,这些服务可能分别部署在不同的服务器上,并且有各自的日志输出.为了方便对这些日志进行统一管理和分析.我们可以将日志统一输出到指定的数 ...

  3. 再谈SQL Server中日志的的作用

    简介     之前我已经写了一个关于SQL Server日志的简单系列文章.本篇文章会进一步挖掘日志背后的一些概念,原理以及作用.如果您没有看过我之前的文章,请参阅:     浅谈SQL Server ...

  4. LR中日志设置和日志函数

    LR中日志参数的设置与使用 1.Run-Time Setting日志参数的设置 在loadrunner的vuser菜单下的Run-Time Setting的General的LOG选项中可以对在执行脚本 ...

  5. Android中日志信息的打印方式

    Android中日志信息的打印方式主要有以下7种: 1)System.out(i级别) 2)System.err(w级别) 3)Log.v 4)Log.d 5)Log.i 6)Log.w 7)Log. ...

  6. SQL Server中日志

    再谈SQL Server中日志的的作用 简介 之前我已经写了一个关于SQL Server日志的简单系列文章.本篇文章会进一步挖掘日志背后的一些概念,原理以及作用.如果您没有看过我之前的文章,请参阅: ...

  7. 详解BOM用途分类及在汽车企业中的应用

    摘要:在整车企业中,信息系统的BOM是联系CAD.CAPP.PDM和ERP的纽带,按照用途划分产品要经过产品设计,工程设计.工艺制造设计.生产制造4个阶段,相应的在这4个过程中分别产生了名称十分相似但 ...

  8. YII2中日志的配置与使用

    YII2中给我们提供了非常方便的日志组件,只需要简单配置一下就可以使用. 我们在config/web.php中配置如下: return [ //log必须在bootstrap期间就被加载,便于及时调度 ...

  9. Tomcat中日志组件

    Tomcat日志组件 AccessLog接口 public interface AccessLog { public void log(Request request, Response respon ...

随机推荐

  1. (原创)ssm sql 例子(freemarker+jsp)

    ssm整合地址:http://www.cnblogs.com/xiaohuihui96/p/6104351.html 接下讲解一个插入语句的流程和顺带讲解freemarker+jsp视图的整合 初次接 ...

  2. 编译osgEarth2.8遇到gdal_vrt.h找不到的问题

    在编译plugins osgearth_gdal的ReaderWriterGDAL.cpp的时候可能会遇到这个问题 gdal_vrt.h这个头文件在gdal-1.11.0\frmts\vrt目录下,从 ...

  3. 一键启动NameNode和DataNode--shell脚本

    使用shell脚本,一键启动hadoop中的NameNode和DataNode.分为普通版和装逼版.装逼版较普通版多了很多判断和信息提示,当然主要还是为了我联系shell脚本而写的. 如果想实现复用, ...

  4. quicktest Professional下载地址,无限制使用方法

    QTP是quicktest Professional的简称,是一种自动测试工具.使用QTP的目的是想用它来执行重复的自动化测试,主要是用于回归测试和测试同一软件的新版本.因此你在测试前要考虑好如何对应 ...

  5. Oracle Database 12c Release 1下载安装(自身经历)

    1.访问Oracle官网:https://www.oracle.com/index.html,下载Oracle Database 12c Release 1 (注意:File1和File2都要下载!! ...

  6. display:table-cell的应用

    一.display:table-cell属性简述 display:table-cell属性指让标签元素以表格单元格的形式呈现,类似于td标签.目前IE8+以及其他现代浏览器都是支持此属性的,但是IE6 ...

  7. H5(一)

    HTML5目前最新的规范(标准)是2014年10月推出   2005年左右出现HTML5版本(非标准)     W3C组织(两个组织定义H5规范)   学习(研究)HTML5是学习未来(将来主流)   ...

  8. Win7 U盘安装Ubuntu16.04 双系统详细教程

    Win7 U盘安装Ubuntu16.04 双系统详细教程 安装主要分为以下几步: 一. 下载Ubuntu 16.04镜像软件: 二. 制作U盘启动盘使用ultraISO: 三. 安装Ubuntu系统: ...

  9. 如何在vim里删除空行?

    删除空行,进入底行模式 :g/^$/d ^代表首列 $代表尾列 d代表删除 g代表全局替换

  10. (UWP开发)更为合理的一种ListView下拉刷新(PullToRefresh)实现方法

    最近在做的一个项目需要用到下拉刷新,但是参考了现在网络上比较普遍的方法,觉得都不太好,因为要在外部套上一个SrollViewer,容易出现滚动错误.于是刚开始的时候就把思路定到了ListView内部的 ...