flume安装后检查flume版本出错
检查版本的时候出现错误:flume-ng version
解决方法:需要修改flume-ng脚本中代码,bash对正则表达式解析错误引起的。可以按照下面步骤修改:
在81行下, 正则表达式用双引号包含,修改为:
if [[ $line =~ "^java\.library\.path=(.*)$" ]]; then
在101行下, 修改为:
if [[ $PIECE =~ "slf4j-(api|log4j12).*\.jar" ]]; then
在130行下, 修改为:
if [[ $line =~ "^java\.library\.path=(.*)$" ]]; then
在150行下, 修改为:
if [[ $PIECE =~ "slf4j-(api|log4j12).*\.jar" ]]; then
flume单点配置:
配置avro简单模式:flume配置分为sources、channels、sinks三大组件。需要配置这三个模块。
1)案例1:Avro
Avro可以发送一个给定的文件给Flume,Avro 源使用AVRO RPC机制。
各个组件只配置一个实例
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = avro
a1.sources.r1.bind = 0.0.0.0
a1.sources.r1.port = 4141
# Describe the sink
a1.sinks.k1.type = logger
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
在服务机器上启动服务:flume-ng agent -c . -f ../conf/avro.conf -n a1 -Dflume.root.logger=INFO,console
在另外一台linux机器上使用AVRO RPC调用:
flume-ng avro-client -c . -H xxxx(ip地址) -p 4141(端口) -F ../logs/log.00(文件)【文件中的每一行都是一个event事件】
配置使用这种个人心得:数据从客户端请求过来,当然也可以是flume配置的sink组件,可以用于集群扩展。
案例2:Spool
Spool监测配置的目录下新增的文件,并将文件中的数据读取出来。需要注意两点:
1) 拷贝到spool目录下的文件不可以再打开编辑。
2) spool目录下不可包含相应的子目录
sources数据来源不同,监控指定目录文件变化。事件的headers为文件名,事件body为文件内容。
异常:出现异常java.nio.charset.MalformedInputException: Input length = 1(后续解决)
案例3:Exec(用linux中命令获取的数据作为输出源)
例如:a1.sources.r1.command = tail -F /home/hadoop/flume-1.5.0-bin/log_exec_tail 使用tail命令进行配置。
案例4:Syslogtcp
Syslogtcp监听TCP的端口做为数据源
配置文件
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = syslogtcp
a1.sources.r1.port = 5140 (监听端口)
a1.sources.r1.host = localhost (配置服务器IP地址)
# Describe the sink
a1.sinks.k1.type = logger
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
案例5:JSONHandler
sources的类型
a1.sources.r1.type = org.apache.flume.source.http.HTTPSource(默认是json解析发送过来的数据,可以自定义数据格式,如xml格式)