查企业的网站有哪些,seo怎样优化网站,企业所得税怎么算小规模纳税人,智慧团建系统手机端Exec source 适用于监控一个实时追加的文件#xff0c;不能实现断点续传#xff1b;Spooldir Source 适合用于同步新文件#xff0c;但不适合对实时追加日志的文件进行监听并同步#xff1b;而 Taildir Source 适合用于监听多个实时追加的文件#xff0c;并且能够实现断点…Exec source 适用于监控一个实时追加的文件不能实现断点续传Spooldir Source 适合用于同步新文件但不适合对实时追加日志的文件进行监听并同步而 Taildir Source 适合用于监听多个实时追加的文件并且能够实现断点续传。 1案例需求:使用 Flume 监听整个目录的实时追加文件并上传至 HDFS 2需求分析: 3实现步骤 1创建配置文件 flume-taildir-hdfs.conf
创建一个文件
[roothadoop100 job]$ vim flume-taildir-hdfs.conf
添加如下内容
a3.sources r3
a3.sinks k3
a3.channels c3
# Describe/configure the source
a3.sources.r3.type TAILDIR
a3.sources.r3.positionFile /opt/module/flume/tail_dir.json
a3.sources.r3.filegroups f1 f2
a3.sources.r3.filegroups.f1 /opt/module/flume/files/.*file.*
a3.sources.r3.filegroups.f2 /opt/module/flume/files2/.*log.*
# Describe the sink
a3.sinks.k3.type hdfs
a3.sinks.k3.hdfs.path hdfs://hadoop100:8020/flume/upload2/%Y%m%d/%H
#上传文件的前缀
a3.sinks.k3.hdfs.filePrefix upload-
#是否按照时间滚动文件夹
a3.sinks.k3.hdfs.round true
#多少时间单位创建一个新的文件夹
a3.sinks.k3.hdfs.roundValue 1
#重新定义时间单位
a3.sinks.k3.hdfs.roundUnit hour
#是否使用本地时间戳
a3.sinks.k3.hdfs.useLocalTimeStamp true
#积攒多少个 Event 才 flush 到 HDFS 一次
a3.sinks.k3.hdfs.batchSize 100
#设置文件类型可支持压缩
a3.sinks.k3.hdfs.fileType DataStream
#多久生成一个新的文件
a3.sinks.k3.hdfs.rollInterval 60
#设置每个文件的滚动大小大概是 128M
a3.sinks.k3.hdfs.rollSize 134217700
#文件的滚动与 Event 数量无关
a3.sinks.k3.hdfs.rollCount 0
# Use a channel which buffers events in memory
a3.channels.c3.type memory
a3.channels.c3.capacity 1000
a3.channels.c3.transactionCapacity 100
# Bind the source and sink to the channel
a3.sources.r3.channels c3
a3.sinks.k3.channel c3 2启动监控文件夹命令
bin/flume-ng agent --conf conf/ --name a3 --conf-file job/flume-taildir-hdfs.conf
3向 files 文件夹中追加内容
在/opt/module/flume 目录下创建 files 文件夹
[roothadoop102 flume]$ mkdir files
[roothadoop100 files]$ touch file1.txt
[roothadoop100 files]$ touch file2.txt
向 upload 文件夹中添加文件
[roothadoop102 files]$ echo hello file1.txt
[roothadoop102 files]$ echo atguigu file2.txt
4查看 HDFS 上的数据
Taildir 说明 Taildir Source 维护了一个 json 格式的 position File其会定期的往 position File 中更新每个文件读取到的最新的位置因此能够实现断点续传。Position File 的格式如下
{inode:2496272,pos:12,file:/opt/module/flume/files/file1.txt}
{inode:2496275,pos:12,file:/opt/module/flume/files/file2.txt}
注Linux 中储存文件元数据的区域就叫做 inode每个 inode 都有一个号码操作系统 用 inode 号码来识别不同的文件Unix/Linux 系统内部不使用文件名而使用 inode 号码来 识别文件。 引升出来的问题 当日的hive.log会在第二天更名为hive.log.xxxx这样的结果就会导致在更名的时候会让flume进行上传就会造成二次上传的错误结果
解决方法
进行源码的修改让文件更名时不会产生新文件上传的效果。