Flume OG:Flume original generation,即Flume0.9x版本linux
Flume NG:Flume next generation,即Flume1.x版本shell
flume的事件(agent)apache
Source: 用来定义采集系统的源头安全
Channel: 把Source采集到的日志进行传输,处理网络
Sink:定义数据的目的地分布式
准备安装文件日志
解压code
重命名事件
添加环境变量事务
#配置Flume的环境变量 export FLUME_HOME=/opt/flume export PATH=$PATH:$FLUME_HOME/bin
配置文件
[root@uplooking01 /opt/flume/conf] mv flume-env.sh.template flume-env.sh
[root@uplooking01 /opt/flume/conf/flume-env.sh] export JAVA_HOME=/opt/jdk
flume-nc.properties
# flume-nc.conf: 用于监听网络数据的flume agent实例的配置文件 ############################################ # 对各个组件的描述说明 # 其中a1为agent的名字 # r1是a1的source的代号名字 # c1是a1的channel的代号名字 # k1是a1的sink的代号名字 ############################################ a1.sources = r1 a1.sinks = k1 a1.channels = c1 # 用于描述source的,类型是netcat网络 a1.sources.r1.type = netcat # source监听的网络ip地址和端口号 a1.sources.r1.bind = uplooking01 a1.sources.r1.port = 44444 # 用于描述sink,类型是日志格式 a1.sinks.k1.type = logger # 用于描述channel,在内存中作数据的临时的存储 a1.channels.c1.type = memory # 该内存中最大的存储容量,1000个events事件 a1.channels.c1.capacity = 1000 # 可以同时对100个events事件监管事务 a1.channels.c1.transactionCapacity = 100 # 将a1中的各个组件创建关联关系,将source和sink都指向了同一个channel a1.sources.r1.channels = c1 a1.sinks.k1.channel = c1
flume-ng agent --name a1 --conf /opt/flume/conf --conf-file /opt/flume/conf/flume-nc.properties -Dflume.root.logger=INFO,console
flume-ng agent --name a1 --conf-file /opt/flume/conf/flume-nc.properties
rpm -ivh nc-1.84-22.el6.x86_64.rpm
监听端口: nc -lk 4444
链接主机的端口: nc host port
cat xxx: 查看文件的所有内容
head -100 xxx:查看文件内容开始的100行(默认不加-100是查看10行)
tail -100 xxx:查看文件内容末尾的100行(默认不加-100是查看10行)
tail -f xxx:查看文件内容末尾10行,而且监听文件的变化
常见采集的数据类型
channel的类型 :
sink的表现形式不少好比:打印到控制台、hdfs上、avro服务中、文件中等
常见采集的数据类型
event是Flume NG传输的数据的基本单位,也是事务的基本单位
在文本文件,一般是一行记录就是一个event。
网络消息传输系统中,一条消息就是一个event。
event里有header、body
Event里面的header类型:Map<String, String>
咱们能够在source中自定义header的key:value,在某些channel和sink中使用header
配置agent
############################################ # 对各个组件的描述说明 # 其中a1为agent的名字 # r1是a1的source的代号名字 # c1是a1的channel的代号名字 # k1是a1的sink的代号名字 ############################################ a1.sources = r1 a1.sinks = k1 a1.channels = c1 # 用于描述source的,类型是linux命令 a1.sources.r1.type = exec a1.sources.r1.command = tail -F /opt/flume/conf/logs/test01.txt # 用于描述sink,类型是日志格式 a1.sinks.k1.type = logger # 用于描述channel,在内存中作数据的临时的存储 a1.channels.c1.type = memory # 该内存中最大的存储容量,1000个events事件 a1.channels.c1.capacity = 1000 # 可以同时对100个events事件监管事务 a1.channels.c1.transactionCapacity = 100 # 将a1中的各个组件创建关联关系,将source和sink都指向了同一个channel a1.sources.r1.channels = c1 a1.sinks.k1.channel = c1
运行agent,开始采集数据
flume-ng agent --name a1 --conf-file flume-exec.properties
配置agent
############################################ # 对各个组件的描述说明 # 其中a1为agent的名字 # r1是a1的source的代号名字 # c1是a1的channel的代号名字 # k1是a1的sink的代号名字 ############################################ a1.sources = r1 a1.sinks = k1 a1.channels = c1 # 用于描述source的,监听的是一个目录 a1.sources.r1.type = spooldir a1.sources.r1.spoolDir = /opt/flume/conf/logs/aa a1.sources.r1.fileSuffix = .OK a1.sources.r1.deletePolicy = never a1.sources.r1.fileHeader = true # 用于描述sink,类型是日志格式 a1.sinks.k1.type = logger # 用于描述channel,在内存中作数据的临时的存储 a1.channels.c1.type = memory # 该内存中最大的存储容量,1000个events事件 a1.channels.c1.capacity = 1000 # 可以同时对100个events事件监管事务 a1.channels.c1.transactionCapacity = 100 # 将a1中的各个组件创建关联关系,将source和sink都指向了同一个channel a1.sources.r1.channels = c1 a1.sinks.k1.channel = c1
运行agent,开始采集数据
flume-ng agent --name a1 --conf-file flume-dir.properties
nohup flume-ng agent --name a1 --conf-file flume-dir.properties >dev/null 2>&1 &