Hadoop学习之Flume日志采集

目录

一、Flume简介

二、Flume的安装配置

1.下载并上传

 2.解压

3.配置 

4.配置环境变量 

5.使环境变量起作用 

三、Flume入门 

1.配置采集方案

2.指定采集方案启动Flume 

3.采集数据测试

四、案例测试1:监控某个文件夹的变化,将添加的新文件采集存入到hdfs

1.采集方案需要确定三大部分

2.采集配置文件

3.测试

4.出现错误

 5.重新启动flume

6.重新启动该flume上传一个文件 

7.查看结果

8.修改采集方案

9.重新启动flume

10.查看结果

五、案例测试2:监控某个文件的变化,把变化的内容存储到hdfs上

1.采集方案

2.配置采集方案

3.测试采集功能

 4.启动flume

5.在hdfs上查看 

六、案例测试3:Flume的可靠性保证-负载均衡

1.搭建并配置flume集群

1)分发hadoop001上的flume文件到

2)分发环境变量配置文件

3)起作用 

2.配置采集方案 

1)在hadoop01上配置第一级采集方案

2)在hadoop002和hadoop003上配置第二级采集方案 

3.启动flume

1)在hadoop002和hadoop003上启动flume

2)启动hadoop001的flume

3)启动成功的连接信息 

 4)同时在hadoop002和hadoop003上也提示连接成功

4.负载均衡的测试

1)克隆hadoop001的会话,编写脚本并运行

5.查看结果

1)hadoop002

2) hadoop003

七、Flume的可靠性保证-故障恢复 

1.配置采集方案 

2.启动flume

3.把hadoop003的flume关闭,等待十秒钟(超时时间,在采集方案中进行的定义) 

八.flume拦截器

1.场景 

2.hadoop002与hadoop003的配置文件

3.hadoop001的配置文件

4.启动flume

1)先启动hadoop001上的flume

2)再启动hadoop002和hadoop003上的flume 


一、Flume简介

 

Logo表示通过河道(频道channel)把木材(数据)从一个地方(数据源source)传送到另一个地方(数据目的地-下沉sink)

二、Flume的安装配置

1.下载并上传

 2.解压

3.配置 

 

4.配置环境变量 

5.使环境变量起作用 

三、Flume入门 

1.配置采集方案

 

 

启动命令

 

2.指定采集方案启动Flume 

查看官网

 

表示已经成功

3.采集数据测试

先安装telnet

四、案例测试1:监控某个文件夹的变化,将添加的新文件采集存入到hdfs

1.采集方案需要确定三大部分

数据源:查看官网

数据下沉:

2.采集配置文件

3.测试

 flume会检测根目录/var/log/apache/flumeSpool/是否有新文件产生。往该文件夹上传一个文件,flume会把该文件上传到hdfs集群中

4.出现错误

由于guava版本不一致造成

低版本guava做备份

复制hadoop下的高版本

 5.重新启动flume

启动成功

测试采集效果

6.重新启动该flume上传一个文件 

处理成功

7.查看结果

乱码

8.修改采集方案

9.重新启动flume

10.查看结果

乱码解决

五、案例测试2:监控某个文件的变化,把变化的内容存储到hdfs上

1.采集方案

数据源

数据下沉不用修改

2.配置采集方案

3.测试采集功能

写shell脚本持续输出当前日期到监控文件/var/log/test.log中

再克隆一个会话,查看新增的内容

 4.启动flume

5.在hdfs上查看 

六、案例测试3:Flume的可靠性保证-负载均衡

1.搭建并配置flume集群

三台服务器集群flume集群:hadoop001,hadoop002,hadoop003,

1)分发hadoop001上的flume文件到

[root@hadoop001 servers]# scp -r apache-flume-1.9.0-bin/ hadoop002:$PWD

[root@hadoop001 servers]# scp -r apache-flume-1.9.0-bin/ hadoop003:$PWD

2)分发环境变量配置文件

3)起作用 

2.配置采集方案 

两级配置方案

1)在hadoop01上配置第一级采集方案

 

2)在hadoop002和hadoop003上配置第二级采集方案 

Hadoop002

Hadoop003

3.启动flume

1)在hadoop002和hadoop003上启动flume

从最后一级开始启动flume

Hadoop002

Hadoop003

2)启动hadoop001的flume

3)启动成功的连接信息 

 4)同时在hadoop002和hadoop003上也提示连接成功

4.负载均衡的测试

1)克隆hadoop001的会话,编写脚本并运行

while true;do date >> /var/log/test1.log;sleep 5;done

5.查看结果

1)hadoop002

2) hadoop003

 

七、Flume的可靠性保证-故障恢复 

1.配置采集方案 

2.启动flume

3.把hadoop003的flume关闭,等待十秒钟(超时时间,在采集方案中进行的定义) 

Hadoop002开始工作实现故障恢复

八.flume拦截器

1.场景 

在实际开发的应用场景中,两台服务器A、B在实时产生日志数据,日志类型主要为access.log、nginx.log和web.log。现需要将A、B两台服务器产生的日志数据access.log、nginx.log和web.log采集汇总到服务器C上,并统一收集并上传到HDFS文件系统进行保存。在HDFS中保存日志数据的文件必须按照以下要求进行归类统计(20180723表示收集日志数据的当前日期):

/source/logs/access/20180723/**

/source/logs/nginx/20180723/**

/source/logs/web/20180723/**

2.hadoop002与hadoop003的配置文件

 

# example.conf: A single-node Flume configuration

# Name the components on this agent

# 定义代理的名字a1及各个组件sources、sinks和channels

a1.sources = r1 r2 r3

a1.sinks = k1

a1.channels = c1

# Describe/configure the source

# 定义r1数据源

a1.sources.r1.type = exec

a1.sources.r1.command = tail -F /var/log/access.log

# 定义第一个r1

a1.sources.r1.interceptors = i1

a1.sources.r1.interceptors.i1.type = static

a1.sources.r1.interceptors.i1.key = type

a1.sources.r1.interceptors.i1.value = access

# 定义r2数据源

a1.sources.r2.type = exec

a1.sources.r2.command = tail -F /var/log/nginx.log

# 定义第二个r2

a1.sources.r2.interceptors = i2

a1.sources.r2.interceptors.i2.type = static

a1.sources.r2.interceptors.i2.key = type

a1.sources.r2.interceptors.i2.value = nginx

# 定义r3数据源

a1.sources.r3.type = exec

a1.sources.r3.command = tail -F /var/log/web.log

# 定义第二个r3

a1.sources.r3.interceptors = i3

a1.sources.r3.interceptors.i3.type = static

a1.sources.r3.interceptors.i3.key = type

a1.sources.r3.interceptors.i3.value = web

# Describe the sink

# 定义数据的目的地(下沉)

a1.sinks.k1.type = avro

a1.sinks.k1.hostname = hadoop001

a1.sinks.k1.port = 41414

# 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.sources.r2.channels = c1

a1.sources.r3.channels = c1

a1.sinks.k1.channel = c1

# 启动命令

# flume-ng agent --conf conf --conf-file conf/exec-avro.conf --name a1

3.hadoop001的配置文件

 

# Name the components on this agent

# 定义代理的名字a1及各个组件sources、sinks和channels

a1.sources = r1

a1.sinks = k1

a1.channels = c1

# Describe/configure the source

# 定义数据源

a1.sources.r1.type = avro

a1.sources.r1.bind = hadoop001

a1.sources.r1.port = 41414

#定义拦截器

a1.sources.r1.interceptors = i1

a1.sources.r1.interceptors.i1.type = timestamp

# Describe the sink

# 定义数据的目的地(下沉)

a1.sinks.k1.type = hdfs

a1.sinks.k1.hdfs.path = /flume/logs/%{type}/%y%m%d

a1.sinks.k1.hdfs.filePrefix = events-

# 是否循环创建文件夹

a1.sinks.k1.hdfs.round = true

# 循环创建文件夹的时间间隔是十分钟

a1.sinks.k1.hdfs.roundValue = 10

a1.sinks.k1.hdfs.roundUnit = minute

# 使用本地时间个数

a1.sinks.k1.hdfs.useLocalTimeStamp = true

// 列编辑模式,按住alt选择多列

# 时间间隔

a1.sinks.k1.hdfs.rollInterval = 0

# 大小间隔

a1.sinks.k1.hdfs.rollSize = 10485760

# event的个数,这三个参数谁先满足就出发循环滚动

a1.sinks.k1.hdfs.rollCount = 0

# 批处理数量

a1.sinks.k1.hdfs.batchSize = 10

# 文件格式 表示普通文本文件

a1.sinks.k1.hdfs.fileType = DataStream

a1.sinks.k1.hdfs.writeFormat = Text

a1.sinks.k1.hdfs.threadsPoolSize=10

a1.sinks.k1.hdfs/callTimeout=30000

# 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

# 启动命令

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

4.启动flume

1)先启动hadoop001上的flume

 

2)再启动hadoop002和hadoop003上的flume 

测试效果

在hadoop02和hadoop03上分别克隆三个会话,分别执行以下三个脚本,用来产生生产日志数据

结果

 

  • 4
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值