写好agent配置文件,配置文件名为flume-app.conf(指定source、channel和sink)
启动agent配置文件命令如下:
bin/flume-ng agent
-c /opt/module/flume/conf
-f ~/work/flume-job/flume-app.conf
-n ag1
-Dflume.root.logger=info,console
在flume的安装路径下,启动脚本为bin目录下的flume-ng;
参数 | 作用 | 列表 |
---|---|---|
–conf 或 -c | 指定配置文件夹,包含flume-env.sh和log4j的配置文件 | –conf …/conf |
–conf-file 或 -f | 配置文件地址 | –conf-file …/conf/flume.conf |
–name 或 -n | agent名称 | –name a1 |
-z | zookeeper连接字符串 | -z zkhost:2181,zkhost1:2181 |
-p | zookeeper中的存储路径前缀 | -p /flume |
-Dflume | 启动日志打印到当前控制台 | -Dflume.root.logger=INFO,console |
-c:指向flume安装目录下conf目录的绝对路径
-f:指向flume-app.conf文件的绝对路径
-n:flume-app.conf文件中agent的名字
-Dflume:启动日志打印到当前控制台
linux本地至hdfs配置文件:
#定义三大组件的名称
ag1.sources = source1
ag1.sinks = sink1
ag1.channels = channel1
# 配置source组件
ag1.sources.source1.type = spooldir
ag1.sources.source1.spoolDir = /root/log/
ag1.sources.source1.fileSuffix=.FINISHED
ag1.sources.source1.deserializer.maxLineLength=5120
# 配置sink组件
ag1.sinks.sink1.type = hdfs
ag1.sinks.sink1.hdfs.path =hdfs://hdp-01:9000/access_log/%y-%m-%d/%H-%M
ag1.sinks.sink1.hdfs.filePrefix = app_log
ag1.sinks.sink1.hdfs.fileSuffix = .log
ag1.sinks.sink1.hdfs.batchSize= 100
ag1.sinks.sink1.hdfs.fileType = DataStream
ag1.sinks.sink1.hdfs.writeFormat =Text
## roll:滚动切换:控制写文件的切换规则
ag1.sinks.sink1.hdfs.rollSize = 512000 ## 按文件体积(字节)来切
ag1.sinks.sink1.hdfs.rollCount = 1000000 ## 按event条数切
ag1.sinks.sink1.hdfs.rollInterval = 60 ## 按时间间隔切换文件
## 控制生成目录的规则
ag1.sinks.sink1.hdfs.round = true
ag1.sinks.sink1.hdfs.roundValue = 10
ag1.sinks.sink1.hdfs.roundUnit = minute
ag1.sinks.sink1.hdfs.useLocalTimeStamp = true
# channel组件配置
ag1.channels.channel1.type = memory
ag1.channels.channel1.capacity = 500000 ## event条数
ag1.channels.channel1.transactionCapacity = 600 ##flume事务控制所需要的缓存容量600条event
# 绑定source、channel和sink之间的连接
ag1.sources.source1.channels = channel1
ag1.sinks.sink1.channel = channel1