1 flume简介
flume是分布式的海量日志采集、聚合和传输的系统。从各类数据发送方接收数据进行简单处理后再写到各数据接收方。
配置项名称介绍:
a1.sources = r1 r2
a1.channels = c1 c2
a1.sinks = k1 k2
a1:flume节点名称,启动时通过参数命令-name指定。
a1.sources:监听的源,若有多个用空格隔开,用于收集数据并发送到channel。
a1.channels:临时通道,若有多个用空格隔开,存放source收集的数据,sink从这里读取数据。
a1.sinks:接收器,若有多个用空格隔开,从channel读取数据,并发送给目标 。
a1.sources.r1.type:源的类型,r1是源名称,可以是目录、日志文件、监听端口等。 常用的source的类型包括avro、exec、netcat、spooldir和syslog等。
a1.channels.c1.type:通道的类型,c1为通道名称,= memory表示为常用的memory-channel,同时也有其他类型的channel,如JDBC、file-channel、custom-channel等。
a1.sinks.k1.type:接收器类型,k1为接收器名称, = logger表示直接写入日志, 常用的包括avro、logger、HDFS、Hbase以及kafka等。
2 flume安装
1) 解压并安装
tar -zxvf apache-flume-1.8.0-bin.tar.gz
mv apache-flume-1.8.0-bin /opt/sqm
2) 修改配置文件
cd /opt/sqm/apache-flume-1.8.0-bin/conf
vi flume.conf
配置文件在文章后面。
3) 启动flume
nohup /opt/sqm/apache-flume-1.8.0-bin/bin/flume-ng agent --conf /opt/sqm/apache-flume-1.8.0-bin/conf --conf-file /opt/sqm/apache-flume-1.8.0-bin/conf/image_load.conf --name a1 -Dflume.root.logger=INFO,console &
此启动脚本为后台启动,因为指定的全路径,可在任一目录启动。
--conf:指定配置文件夹,包含flume-env.sh和log4j的配置文件
--conf-file:.conf 配置文件的地址
--name:agent(flume节点)名称
3 flume常用配置
1)常用source
(1)Avro Source
a1.sources.r1.type = avro
a1.sources.r1.channels = c1 c2
a1.sources.r1.bind = 0.0.0.0
a1.sources.r1.port = 20001
a1.sources.r1.selector.type= multiplexing
# selector配置
a1.sources.r1.selector.header = logType
a1.sources.r1.selector.mapping.scsp_login = c1
a1.sources.r1.selector.mapping.scsp_auth = c2
(2)Taildir Source
a1.sources.r1.type = TAILDIR
a1.sources.r1.channels = c1
a1.sources.r1.positionFile = /scsp_taildir_position.json # json记录文件断点续传的位置,程序默认创建
a1.sources.r1.filegroups = f1 f2
a1.sources.r1.filegroups.f1 = /scsp_login.*.log #正则匹配需要采集的SCSP登录日志
a1.sources.r1.headers.f1.logType = scsp_login
a1.sources.r1.filegroups.f2 = /scsp_auth.*.log # 正则匹配需要采集的SCSP鉴权日志
a1.sources.r1.headers.f2.logType = scsp_auth
a1.sources.r1.batchSize = 1000
(3)Syslog Sources
a1.sources.s1.type = org.apache.flume.source.SyslogTcpSource
a1.sources.s1.port = 9511
a1.sources.s1.host = 10.221.xxx.xx
a1.sources.s1.channels = c1
2)cannnel类型:
(1) memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 300000
a1.channels.c1.transactionCapactiy = 20000
a1.channels.c1.keep-alive = 30
3)sink类型:
(1)kafka
a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink
a1.sinks.k1.kafka.topic = image_load
a1.sinks.k1.kafka.bootstrap.servers =ip01:9092,ip02:9092,ip03:9092,ip04:9092
a1.sinks.k1.kafka.producer.acks = 1
a1.sinks.k1.flumeBatchSize = 1000
a1.sinks.k1.channel = c1
(2)avro
a1.sinks.k1.type = avro
a1.sinks.k1.channel = c1
a1.sinks.k1.hostname = xxx
a1.sinks.k1.port = 20001
自己用过的配置:
1)Taildir Source + Memory Channel + Avro Sink
2)Avro Source + Memory Channel + Kafka Sink
3)Syslogtcp Source + Memory Channel + Kafka Sink
我是将1)和2)配合使用的,但是要注意的是,先启动2)再启动1)。
记录一下,以免时间久了忘掉。若有问题,欢迎批评指正。