Flume案例六-2【主机名拦截器】

Posted on 2020-03-30 10:58  MissRong  阅读(156)  评论(0)    收藏  举报

二、主机名拦截器

1.配置flume-主机名拦截器配置文件:

flume-host.conf

#1.定义agent

a1.sources= r1

a1.sinks = k1

a1.channels = c1

 

#2.定义source

a1.sources.r1.type = exec

a1.sources.r1.command = tail -F /opt/plus

#主机名拦截器

a1.sources.r1.interceptors = i1

a1.sources.r1.interceptors.i1.type = host

 

#参数为true时用IP192.168.1.111,参数为false时用主机名,默认为true

a1.sources.r1.interceptors.i1.useIP = false

a1.sources.r1.interceptors.i1.hostHeader = agentHost

 

 #3.定义sinks

a1.sinks.k1.type=hdfs

a1.sinks.k1.hdfs.path = hdfs://bigdata111:9000/flumehost/%{agentHost}

a1.sinks.k1.hdfs.filePrefix = plus_%{agentHost}

#往生成的文件加后缀名.log

a1.sinks.k1.hdfs.fileSuffix = .log

a1.sinks.k1.hdfs.fileType = DataStream

a1.sinks.k1.hdfs.writeFormat = Text

a1.sinks.k1.hdfs.rollInterval = 10

a1.sinks.k1.hdfs.useLocalTimeStamp = true

 

a1.channels.c1.type = memory

a1.channels.c1.capacity = 1000

a1.channels.c1.transactionCapacity = 100

 

a1.sources.r1.channels = c1

a1.sinks.k1.channel = c1

2.准备好监控的文件之后,执行配置文件

启动命令:

[root@bigdata111 myconf]# flume-ng agent -c ../conf/ -n a1 -f flume-host.conf -Dflume.root.logger=INFO,console

3.查看效果

1)查看bigdata111的flume日志:

 

2) 查看Web页面:

 4.将主机名换成IP形式的:

1)如果将参数useIP改成:true-如下改动:

#参数为true时用IP192.168.1.111,参数为false时用主机名,默认为true

a1.sources.r1.interceptors.i1.useIP = true

2)再次运行的logger结果就会变成:

 

web页面:

 

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3