Flume集群环境搭建以及几种类型的conf配置文件

1、Flume的安装非常简单,只需要解压即可,当然,前提是已有hadoop环境上传安装包到数据源所在节点上然后解压  tar -zxvfapache-flume-1.6.0-bin.tar.gz,然后进入flume的目录,修改conf下的flume-env.sh,在里面配置JAVA_HOME
2、根据数据采集的需求 配置采集方案,描述在配置文件中(文件名可任意自定义)
3、 指定采集方案配置文件,在相应的节点上启动flume agent

4、Flume没有高可用,失败后只能重启---只有自己写个脚本监听,失败后自动重启

0. 软件版本下载
http://mirror.bit.edu.cn/apache/flume/

1. 集群环境
Master 172.16.11.97
Slave1 172.16.11.98
Slave2 172.16.11.99

2. 下载软件包
#Master
wget http://mirror.bit.edu.cn/apache/flume/1.6.0/apache-flume-1.6.0-bin.tar.gz
tar zxvf apache-flume-1.6.0-bin.tar.gz

3. 修改Flume配置

实践一:NetCat方式

#NetCat
vim conf/flume-netcat.conf
# Name the components on this agent

# 定义这个agent中各组件的名字

agent.sources = r1
agent.sinks = k1
agent.channels = c1

# Describe/configuration the source
# 描述和配置source组件:r1配置source的详细信息
#类型, 从网络端口接收数据,在本机启动, 所以localhost, type=spoolDir采集目录源,目录里有就采 netcat在数据太长会截断
//类型:从网络端口获取数据 如linux的socket程序nc命令 其他机器可以通过 new Socket(127.0.0.1,44444)发送数据 把接收到的一行数据注册成一个event 如果不是netcat而是spoolDir,则是目录下的所有数据
agent.sources.r1.type = netcat
agent.sources.r1.bind = 127.0.0.1
agent.sources.r1.port = 44444

# Describe the sink

# 描述和配置sink组件:k1  把数据下沉到logger服务器,然后logger打印到屏幕上

agent.sinks.k1.type = logger

# Use a channel which buffers events in memory
# 描述和配置channel组件,此处使用是内存缓存的方式,数据量不大的时候
#下沉的时候是一批一批的, 下沉的时候是一个个eventChannel参数解释:
#capacity:默认该通道中最大的可以存储的event数量

#trasactionCapacity:每次最大可以从source中拿到或者送到sink中的event数量

agent.channels.c1.type = memory
agent.channels.c1.capacity = 1000 //通道中最大可存储的数量:1000条数据 1000个event
agent.channels.c1.transactionCapacity = 100//每次最大可以从source中拿到或者送到sink中的event数量

# Bind the source and sink to the channel

# 描述和配置source  channel  sink之间的连接关系 --将source、channel、sink链接起来

agent.sources.r1.channels = c1
agent.sinks.k1.channel = c1

#验证
#Server 启动agent去采集数据
启动命令: 给logger一个参数,打印到控制台console上
#告诉flum启动一个agent,指定配置文件的路径, --name:agent的名字,--name 后面的a1必须和配置文件的名字一模一样
$ bin/flume-ng agent --conf conf --conf-file conf/netcat-logger.conf --name a1 -Dflume.root.logger=INFO,console
在其他节点上 telnet 192.168.163.13 44444 连接flume节点输入数据 然后flume就能看到数据--其中节点地址必须和配置文件一模一样,如果客户端节点也是flume节点且配置文件一模一样,注意IP地址冲突
例子:
bin/flume-ng agent -c conf -f conf/netcat-logger.conf -n a1  -Dflume.root.logger=INFO,console
-c conf  指定flume自身的配置文件所在目录
-f conf/netcat-logger.con  指定我们所描述的采集方案
-n a1 指定我们这个agent的名字
#Client
telnet master 44444
先要往agent采集监听的端口上发送数据,让agent有数据可采
随便在一个能跟agent节点联网的机器上

telnet anget-hostname port 


监视文件夹

启动命令:  
bin/flume-ng agent -c ./conf -f ./conf/spool-logger.conf -n a1 -Dflume.root.logger=INFO,console
测试: 往/home/hadoop/flumeSpool放文件(mv ././xxxFile /home/hadoop/flumeSpool),但是不要在里面生成文件
#######配置文件spooldir-hdfs#######
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
#监听目录,spoolDir指定目录, fileHeader要不要给文件夹前坠名
a1.sources.r1.type = spooldir//spooldir也会有自己的参数
a1.sources.r1.spoolDir = /home/hadoop/flumespool  //要创建这个路径 不能不存在
a1.sources.r1.fileHeader = true

# 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

此时只要有文件在此路径发生创建、移动、改变均能被采集到日志

实践二:Exec方式

#Exec
vim conf/flume-exec.conf
# Name the components on this agent
agent.sources = r1
agent.sinks = k1
agent.channels = c1

# Describe/configuration the source
agent.sources.r1.type = exec
agent.sources.r1.command = tail -f /data/hadoop/flume/test.txt

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

# Use a channel which buffers events in memory
agent.channels.c1.type = memory
agent.channels.c1.capacity = 1000
agent.channels.c1.transactionCapacity = 100

# Bind the source and sink to the channel
agent.sources.r1.channels = c1
agent.sinks.k1.channel = c1
#Server
bin/flume-ng agent --conf conf --conf-file conf/flume-exec.conf --name=agent -Dflume.root.logger=INFO,console
#Client
while true;do echo `date` >> /data/hadoop/flume/test.txt ; sleep 1; done

实践三:HDFS

#Avro
vim conf/flume-avro.conf
# Define a memory channel called c1 on agent
agent.channels.c1.type = memory

# Define an avro source alled r1 on agent and tell it
agent.sources.r1.channels = c1
agent.sources.r1.type = avro
agent.sources.r1.bind = 127.0.0.1
agent.sources.r1.port = 44444

# Describe/configuration the source
agent.sinks.k1.type = hdfs
agent.sinks.k1.channel = c1
agent.sinks.k1.hdfs.path = hdfs://master:9000/flume_data_pool
agent.sinks.k1.hdfs.filePrefix = events-
agent.sinks.k1.hdfs.fileType = DataStream
agent.sinks.k1.hdfs.writeFormat = Text
agent.sinks.k1.hdfs.rollSize = 0
agent.sinks.k1.hdfs.rollCount= 600000
agent.sinks.k1.hdfs.rollInterval = 600

agent.channels = c1
agent.sources = r1
agent.sinks = k1
#验证
#Server
bin/flume-ng agent --conf conf --conf-file conf/flume-netcat.conf --name=agent -Dflume.root.logger=DEBUG,console
#Client
telnet master 44444

• 上图的端口配置方式的验证(注意端口号):
• ./bin/flume-ng avro-client --conf conf -H master -p 41414 -F

/home/badou/flume_test/monitor_source/3.txt -Dflume.root.logger=DEBUG,console

实践四:模拟使用Flume监听日志变化,并且把增量的日志文件写入到hdfs中

• ]# vim flume.conf
• 运行flume-ng
• ./bin/flume-ng agent --conf conf -- conf-file ./conf/flume.conf -name a1 - Dflume.root.logger=DEBUG,console
• 验证:

• echo "11113" >> 1.log

用tail命令获取数据,下沉到hdfs

vim tail-hdfs.conf  

配置参数详情查看官网
mkdir /home/hadoop/log
while true
do
echo 111111 >> /home/hadoop/log/test.log
sleep 0.5
done

tail -F test.log
采集到hdfs中, 文件中的目录不用自己建的


启动hdfs:start-dfs.sh

检查下hdfs式否是salf模式:(刚刚启动时很容易还在safe模式)
hdfs dfsadmin -report

bin/flume-ng agent -c conf -f conf/tail-hdfs.conf -n a1
前端页面查看下, master:50070, 文件目录: /flum/events/16-04-20/

启动命令:
bin/flume-ng agent -c conf -f conf/tail-hdfs.conf -n a1
################################################################

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

#exec 指的是命令
# Describe/configure the source
a1.sources.r1.type = exec
#F根据文件名追中, f根据文件的nodeid追中--采集的文件
a1.sources.r1.command = tail -F /home/hadoop/log/test.log
a1.sources.r1.channels = c1

# Describe the sink
#下沉目标
a1.sinks.k1.type = hdfs
a1.sinks.k1.channel = c1
#指定目录, flum帮做目的替换
a1.sinks.k1.hdfs.path = /flume/events/%y-%m-%d/%H%M/ 路径为年月日时分秒
#文件的命名, 前缀 后缀为时间戳
a1.sinks.k1.hdfs.filePrefix = events-

#10 分钟就改目录
a1.sinks.k1.hdfs.round = true
a1.sinks.k1.hdfs.roundValue = 10
a1.sinks.k1.hdfs.roundUnit = minute

#文件滚动之前的等待时间(秒)
a1.sinks.k1.hdfs.rollInterval = 3

#文件滚动的大小限制(bytes)
a1.sinks.k1.hdfs.rollSize = 500

#写入多少个event数据后滚动文件(事件个数)
a1.sinks.k1.hdfs.rollCount = 20

#5个事件就往里面写入
a1.sinks.k1.hdfs.batchSize = 5

#用本地时间格式化目录 a1.sinks.k1.hdfs.path = /flume/events/%y-%m-%d/%H%M/
a1.sinks.k1.hdfs.useLocalTimeStamp = true

#下沉后, 生成的文件类型,默认是Sequencefile,可用DataStream,则为普通文本
a1.sinks.k1.hdfs.fileType = DataStream

# 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

从avro端口接收数据,下沉到logger

bin/flume-ng agent -c conf -f conf/avro-logger.conf -n al -Dflume.root.logger=INFO,console
#########
采集配置文件,avro-hdfs.conf
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
#source中的avro组件是接收者服务, 绑定本机
a1.sources.r1.type = avro
a1.sources.r1.channels = c1
a1.sources.r1.bind = 0.0.0.0
a1.sources.r1.port = 4141

# 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

发送数据:
$ bin/flume-ng avro-client -H localhost -p 4141 -F /usr/logs/log.10


flume串联---多个flume的联合使用

从tail命令获取数据发送到avro端口(tail到avro,avro到logger)--要和上一个配置文件avro-hdfs.conf中的IP地址和端口号对应,本agent会发送event到上面avro-hdfs.conf这个的agent上,然后再由avro-hdfs.conf的agent写到logger中

另一个节点可配置一个avro源来中继数据,发送外部存储

##################
# 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/log/test.log
a1.sources.r1.channels = c1

# Describe the sink
#绑定的不是本机, 是另外一台机器的服务地址, sink端的avro是一个发送端, avro的客户端, 往master这个机器上发
a1.sinks = k1
a1.sinks.k1.type = avro ---这次不是hdfs 要指定一个服务器主机和端口号
a1.sinks.k1.channel = c1
a1.sinks.k1.hostname = master
a1.sinks.k1.port = 4141
a1.sinks.k1.batch-size = 2  //一批次两个event

# 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


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值