分布式日志收集框架Flume
3-2业务现状分析
3-3Flume概述
Flume官网:http://flume.apache.org/
Flume is a distributed, reliable, and available service for efficiently collecting(收集), aggregating(聚合), and moving(移动) large amounts of log data.
Webserver==>flume==>hdfs(目的地)
3-4Flume架构及核心组件
-
source 收集
-
channel 聚集
-
sink 输出
3-5环境部署
前置条件
1.Java Runtime Environment - Java 1.8 or later
2.Memory - Sufficient memory for configurations used by sources, channels or sinks
3.Disk Space - Sufficient disk space for configurations used by channels or sinks
4.Directory Permissions - Read/Write permissions for directories used by agent
jdk解压:tar -zxvf jdk-8u11-linux-x64.tar.gz -C ~/app/
vi ~/.bash_profile
export JAVA_HOME=/home/hadoop000/app/jdk1.8.0_11
export PATH=
J
A
V
A
H
O
M
E
/
b
i
n
:
JAVA_HOME/bin:
JAVAHOME/bin:PATH
source ~/.bash_profile
检测: java -version
安装Flume
export FLUME_HOME=/home/hadoop000/app/apache-flume-1.6.0-cdh5.7.0-bin
export PATH=
F
L
U
M
E
H
O
M
E
/
b
i
n
:
FLUME_HOME/bin:
FLUMEHOME/bin:PATH
conf 目录下 cp flume-env.sh.template flume-env.sh
flume-env.sh
配置JAVA_HOME的路径
bin目录下 检测:flume-ng version
3-6Flume实战
需求:从指定网络端口采集数据输出到控制台
example.conf :A single-node Flume configuration
使用Flume的关键就是写配置文件
A) 配置source
B) 配置channel
C) 配置sink
D) 将以上三个组件穿起来
a1:agent的名称
r1:source的名称
k1:sink的名称
c1:channel的名称
#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 = localhost
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
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
启动agent
$ bin/flume-ng agent -n $agent_name -c conf -f conf/flume-conf.properties.template
flume-ng agent
–name a1
–conf $FLUME_HOME/conf
–conf-file $FLUME_HOME/conf/example.conf
-Dflume.root.logger=INFO,console
另开一个控制台 telnet hadoop000
如果没安装telnet :
Linux安装telnet
一、安装telnet
1、检测telnet-server的rpm包是否安装
[root@localhost ~]# rpm -qa telnet-server
若无输入内容,则表示没有安装。出于安全考虑telnet-server.rpm是默认没有安装的,而telnet的客户端是标配。即下面的软件是默认安装的。
2、若未安装,则安装telnet-server,否则忽略此步骤
[root@localhost ~]#yum install telnet-server
3、检测telnet-server的rpm包是否安装
[root@localhost ~]# rpm -qa telnet
telnet-0.17-47.el6_3.1.x86_64
4、若未安装,则安装telnet,否则忽略此步骤
[root@localhost ~]# yum install telnet
二、重新启动xinetd守护进程
由于telnet服务也是由xinetd守护的,所以安装完telnet-server,要启动telnet服务就必须重新启动xinetd
[root@locahost ~]#service xinetd restart
三、测试
我们先来查看TCP的23端口是否开启正常
[root@localhost ~]#netstat -tnl |grep 23
tcp 0 0 0.0.0.0:23 0.0.0.0:* LISTEN
如果上面的一行存在就说明服务已经运行了。如果netstat命令没有返回内容,我们就只好继续进行更深入的配置了。
Event: { headers:{} body: 68 65 6C 6C 6F 0D hello. }
Event是flume数据传输的基本单元
Event = 可选的header + byte array