大数据实战(1)---日志收集:Flume

1.Flume概述

Flume is a distributed, reliable,
and available service for efficiently collecting(收集),
aggregating(聚合), and moving(移动) large amounts of log data

1.业界同类产品的对比

    Flume: Cloudera/Apache   Java   
    Scribe: Facebook   C/C++   不再维护
    Chukwa: Yahoo/Apache  Java  不再维护
    Kafka:
    Fluentd: Ruby
    Logstash: ELK(ElasticSearch,Kibana)

       2.基础信息

1)flume:分布式日志收集框架
2)Apache 顶级项目,java开发
3)对比canal,canal只是模拟mysql的备份库,对于其它数据源不好用,可以通过flume来统一数据源
4)flume只是移动日志

 

2.Flume架构及核心组件

1) Source   收集  

2) Channel  聚集

3) Sink     输出
 

3.安装

Flume安装前置条件
    Java Runtime Environment - Java 1.7 or later
    Memory - Sufficient memory for configurations used by sources, channels or sinks
    Disk Space - Sufficient disk space for configurations used by channels or sinks
    Directory Permissions - Read/Write permissions for directories used by agent


安装jdk
    下载
    解压到~/app
    将java配置系统环境变量中: ~/.bash_profile    
        export JAVA_HOME=/home/hadoop/app/jdk1.8.0_144
        export PATH=$JAVA_HOME/bin:$PATH
    source下让其配置生效
    检测: java  -version


安装Flume
    下载
    解压到~/app
    将java配置系统环境变量中: ~/.bash_profile    
        export FLUME_HOME=/home/hadoop/app/apache-flume-1.6.0-cdh5.7.0-bin
        export PATH=$FLUME_HOME/bin:$PATH
    source下让其配置生效    
    flume-env.sh的配置:export JAVA_HOME=/home/hadoop/app/jdk1.8.0_144
    检测: flume-ng version

4.配置、使用

使用Flume的关键就是写配置文件

A) 配置Source
B) 配置Channel
C) 配置Sink
D) 把以上三个组件串起来

a1: agent名称
r1: source的名称
k1: sink的名称
c1: channel的名称

conf下新建:example.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 = hadoop000
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

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1


启动agent
flume-ng agent \
--name a1  \
--conf $FLUME_HOME/conf  \
--conf-file $FLUME_HOME/conf/example.conf \
-Dflume.root.logger=INFO,console

使用telnet进行测试: telnet hadoop000 44444


Event: { headers:{} body: 68 65 6C 6C 6F 0D hello. }
Event是FLume数据传输的基本单元
Event =  可选的header + byte array

 

 


需求二:
Agent选型:exec source + memory channel + logger sink
# 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 /home/hadoop/data/data.log
a1.sources.r1.shell = /bin/sh -c

# Describe the sink
a1.sinks.k1.type = logger

# Use a channel which buffers events in memory
a1.channels.c1.type = memory

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

启动agent
flume-ng agent \
--name a1  \
--conf $FLUME_HOME/conf  \
--conf-file $FLUME_HOME/conf/exec-memory-logger.conf \
-Dflume.root.logger=INFO,console


需求三:
技术选型:
    exec source + memory channel + avro sink
    avro source + memory channel + logger sink

exec-memory-avro.conf

exec-memory-avro.sources = exec-source
exec-memory-avro.sinks = avro-sink
exec-memory-avro.channels = memory-channel

exec-memory-avro.sources.exec-source.type = exec
exec-memory-avro.sources.exec-source.command = tail -F /home/hadoop/data/data.log
exec-memory-avro.sources.exec-source.shell = /bin/sh -c

exec-memory-avro.sinks.avro-sink.type = avro
exec-memory-avro.sinks.avro-sink.hostname = hadoop000
exec-memory-avro.sinks.avro-sink.port = 44444

exec-memory-avro.channels.memory-channel.type = memory

exec-memory-avro.sources.exec-source.channels = memory-channel
exec-memory-avro.sinks.avro-sink.channel = memory-channel

 

avro-memory-logger.conf
avro-memory-logger.sources = avro-source
avro-memory-logger.sinks = logger-sink
avro-memory-logger.channels = memory-channel

avro-memory-logger.sources.avro-source.type = avro
avro-memory-logger.sources.avro-source.bind = hadoop000
avro-memory-logger.sources.avro-source.port = 44444

avro-memory-logger.sinks.logger-sink.type = logger

avro-memory-logger.channels.memory-channel.type = memory

avro-memory-logger.sources.avro-source.channels = memory-channel
avro-memory-logger.sinks.logger-sink.channel = memory-channel

 

先启动avro-memory-logger
flume-ng agent \
--name avro-memory-logger  \
--conf $FLUME_HOME/conf  \
--conf-file $FLUME_HOME/conf/avro-memory-logger.conf \
-Dflume.root.logger=INFO,console


flume-ng agent \
--name exec-memory-avro  \
--conf $FLUME_HOME/conf  \
--conf-file $FLUME_HOME/conf/exec-memory-avro.conf \
-Dflume.root.logger=INFO,console

5.启动测试

 

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

avro-mempry-kafka:
flume-ng agent  --name avro-memory-kafka  --conf  $FLUME_HOME/conf   --conf-file  $FLUME_HOME/conf/avro-memory-kafka.conf   -Dflume.root.logger=INFO,console 

flume-ng agent  --name exec-memory-avro --conf  $FLUME_HOME/conf   --conf-file  $FLUME_HOME/conf/exec-memory-avro.conf   -Dflume.root.logger=INFO,console 

mysql-memory-logger:
flume-ng agent   --name agent    --conf $FLUME_HOME/conf   --conf-file    $FLUME_HOME/conf/sqlSource-memory-logger.conf      -Dflume.root.logger=INFO,console

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值