1 解压改名(所谓压缩:将相同的二进制用特定的二进制代替,减少数据量)
tar -zvxf apache-flume-1.8.0-bin.tar.gz
rm apache-flume-1.8.0-bin.tar.gz
mv apache-flume-1.8.0-bin/ flume-1.8.0
2 配置
官方文档:http://flume.apache.org/ 左侧目录栏中找到
- Documentation 选择用户文档
- Flume User Guide (unreleased version) 找到
- Configuration 对应可以查看Flume Sources、Flume Sinks、Flume Channels
- Flume Sinks:1 roll:滚动切换 2 Prefix:前缀 3 Suffix:后缀 4 Count:计数 5 Interval:间隔 6: Timeout:超时 7 inUse: 正在使用中 8 hdfs.batchSize 攒够多少条数据进行写入 9
hdfs.fileType |
写入文件的类型 |
SequenceFile(序列化文件,key-value 默认的), DataStream(和读取的文件保持一致) or CompressedStream(压缩文件) |
hdfs.writeFormat |
Writable(对应默认写入类型) |
Format for sequence file records. One of Text or Writable. Set to Text(对应DataStream) before creating data files with Flume, otherwise those files cannot be read by either Apache Impala (incubating) or Apache Hive. |
写flume的配置文件 vi /usr/local/flume-1.8.0
#定义三大组件的名称 ag1.sources = source1 ag1.sinks = sink1 ag1.channels = channel1 # 配置source组件 ag1.sources.source1.type = spooldir ##读取目录的source类型,只要出现新的文件,就读取 ag1.sources.source1.spoolDir = /root/logs ## 读取的目录 ag1.sources.source1.fileSuffix=.FINISHED ##文件后缀,给采集过的文件添加后缀名,默认为.COMPLETED #ag1.sources.source1.deletePolicy=immediate ##删除已经采集过的文件,默认为never 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 ##放置文件的前缀 hdfs.inUsePrefix 正在写的文件的前缀 ag1.sinks.sink1.hdfs.fileSuffix = .log ##放置文件的后缀 hdfs.inUseSuffix 正在写的文件的后缀,默认为.tmp ag1.sinks.sink1.hdfs.batchSize= 100 ##按100条数据写入一次 ag1.sinks.sink1.hdfs.fileType = DataStream ##写入的文件和读取的文件类型保持一致 ag1.sinks.sink1.hdfs.writeFormat =Text ##写入的时候对应fileType ## roll:滚动切换:控制写文件的切换规则 ag1.sinks.sink1.hdfs.rollSize = 512000 ## 按文件体积(大小,字节)来切(停止写入,生成新的文件)500k ag1.sinks.sink1.hdfs.rollCount = 1000000 ## 按event条数切 写成0就不生效 ag1.sinks.sink1.hdfs.rollInterval = 60 ## 创建的文件过了60s后正在写的文件停止,生成新的写入文件 写成0就不生效 ## 控制生成目录的规则--目录多久变化一次 ag1.sinks.sink1.hdfs.round = true ag1.sinks.sink1.hdfs.roundValue = 10 ag1.sinks.sink1.hdfs.roundUnit = minute ## second, minute or hour. ag1.sinks.sink1.hdfs.useLocalTimeStamp = true ##按时间戳取时间 # channel组件配置 ag1.channels.channel1.type = memory ag1.channels.channel1.capacity = 500000 ## event条数(暂时存储的最大even事件数目,实际应该大于sink的条数batchSize) ag1.channels.channel1.transactionCapacity = 600 ##flume事务控制所需要的缓存容量600条event(默认归纳的条数为100条) # 绑定source、channel和sink之间的连接 ag1.sources.source1.channels = channel1 ag1.sinks.sink1.channel = channel1 |
### 运行flume的shell :./flume-ng agent -c /home/hadoop/flume-1.8.0/conf/ -f ../conf/dir-hdfs.conf -n ag1 -Dflume.root.logger=INFO,console
cd /usr/local/flume-1.8.0
cd conf/
cp flume-env.sh.template flume-env.sh
[root@sure conf]# vi flume-env.sh →/JAVA_HOME搜索
1. 去掉开头 #的注释
2. Jdk为服务器中jdk的路径 :
export JAVA_HOME=/usr/java/jdk1.8.0_144