flume安装及使用

flume安装及使用

1.下载&解压安装包

wget https://dlcdn.apache.org/flume/1.10.1/apache-flume-1.10.1-bin.tar.gz
tar -zxvf apache-flume-1.10.1-bin.tar.gz

2.创建配置文件

cd conf
#创建编辑flume-xxxx-to-hdfs.conf文件
vi flume-xxxx-to-hdfs.conf

# 创建一个基于内存的通道ch1,代理为a1
a1.channels.ch1.type = memory
a1.channels.ch1.keep-alive = 60
a1.channels.ch1.transactionCapacity = 1000
a1.channels.ch1.capacity = 1000000

# a1代理的sources为r1,并且绑定通道为ch1
al.sources.r1.channels = ch1
#r1类型为exec,表示为linux命令
a1.sources.r1.type = exec
# r1的命令为监听日志文件
a1.sources.r1.command = tail -F /home/app/logs/xxx.log
# 为r1创建拦截器,regex_extractor的作用是将正则匹配到的内容放入header中
a1.sources.r1.interceptors = i1
a1.sources.r1.interceptors.i1.type=regex_extractor
a1.sources.r1.interceptors.i1.regex = "act":(\\d)
a1.sources.r1.interceptors.i1.serializers = s1
a1.sources.r1.interceptors.i1.serializers.s1.name = log1

# a1的sink为k1,类型为hdfs
a1.sinks.k1.type = hdfs
a1.sinks.k1.channel = ch1
a1.sinks.k1.hdfs.path = hdfs://hadoop01:9000/data/ods/xxx/%Y%m%d/%{log1}
a1.sinks.k1.hdfs.filePrefix = data
a1.sinks.k1.hdfs.fileSuffix = .log
a1.sinks.k1.hdfs.fileType = DataStream
a1.sinks.k1.hdfs.writeFormat = Text
#按时间滚动生成文件(秒)
a1.sinks.k1.hdfs.rollInterval = 3600
#按大小滚动生成文件(byte)
a1.sinks.k1.hdfs.rollSize = 134217728
#生成新的文件之前要求当前文件写入多少事件(0表示不基于事件数生成新文件)
a1.sinks.k1.hdfs.rollCount = 0
#支持文件夹滚动的属性。是否需要新建文件夹。
a1.sinks.k1.hdfs.round = true
#该值与roundUnit一起指定文件夹滚动的时长,会四舍五入
a1.sinks.k1.hdfs.roundValue = 60
#round时间单位,可以设置为- second, minute 或者 hour
a1.sinks.k1.hdfs.roundUnit = minute
#必须设置为1,只是为了不让复制文件触发生成新文件(实际复制数量是默认读取的hadoop配置文件的数量),否则生成文件策略不生效
a1.sinks.k1.hdfs.minBlockReplicas = 1
#一般设置为true,使用本地时间。如果为false,则需要flume在发送的事件header中带有时间戳,否则会报错
a1.sinks.k1.hdfs.useLocalTimeStamp = true

#定义组件名称
a1.channels = ch1
a1.sources = r1
a1.sinks = k1

3.配置环境变量

cp flume-env.sh.template flume-env.sh
#设置java运行内存
export JAVA_OPTS="-Xms1024m -Xmx2048m -Dcom.sun.management.jmxremote"
#设置hadoop环境变量
export HADOOP_HOME=/home/hadoop/hadoop-3.3.1

4.启动agent

nohup bin/flume-ng agent --conf conf --conf-file conf/flume-xxxx-to-hdfs.conf --name a1 &

5.导入依赖包

#避免找不到类报错
# 导入包/hadoop/share/hadoop/common下的所有包
# 导入包/hadoop/share/hadoop/common/lib下的所有包
# 导入包/hadoop/share/hadoop/hdfs下的包
# 导入包/hadoop/share/hadoop/hdfs/lib下的包
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值