flume是配置和使用


下载地址:


解压 tar -zxvf filename


配置环境变量:sudo vim /etc/profile
export    FLUME_HOME=文件的主目录
export FLUME_CONF_DIR=$FLUME_HOME/conf
export    PATH=$PATH:$FLUME_HOME/bin

source /etc/profile

修改flume-env.sh中的JAVA_HOME的路径和FLUME_OPTS


然后命令行输入flume-ng version验证是否成功配置出现如下,成功



然后配置flume-conf.properties文件,配置source接受数据的方式

1.exec

a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = exec

#输入文件所在的位置
a1.sources.r1.command = tail -F /home/spark/log
# 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


启动agent a1

在$FLUME_HOME目录中输入

bin/flume-ng agent --conf ./conf -f conf/flume-conf.properties -Dflume.root.logger=DEBUG,console -n a1


然后重新开启一个终端输入

for i in {1..100};do echo "exec tail$i" >> /home/spark/log;echo $i;sleep 0.1;done

成功截图:





2.netcat

# Name the components on this agent
agent1.sources = source1
agent1.sinks = sink1
agent1.channels = channel1


# Describe/configure source1
agent1.sources.source1.type = netcat
agent1.sources.source1.bind = localhost
agent1.sources.source1.port = 44444


# Describe sink1
agent1.sinks.sink1.type = logger


# Use a channel which buffers events in memory
agent1.channels.channel1.type = memory
agent1.channels.channel1.capacity = 1000
agent1.channels.channel1.transactionCapactiy = 100


# Bind the source and sink to the channel
agent1.sources.source1.channels = channel1
agent1.sinks.sink1.channel = channel1


启动agent agent1

在$FLUME_HOME目录中输入

bin/flume-ng agent --conf ./conf -f conf/flume-conf.properties -Dflume.root.logger=DEBUG,console -nagent1



然后重新开启一个终端输入

telnet localhost 44444


成功截图:





3.exec--hdfs

# Name the components on this agent
agent1.sources = r1
agent1.sinks = s_hdfs
agent1.channels = c_hdfs
agent1.sources.r1.channels = c_hdfs


# Describe/configure source1
agent1.sources.r1.type = exec
agent1.sources.r1.command = tail -F /home/spark/log1
#channels 
agent1.channels.c_hdfs.type = memory
agent1.channels.c_hdfs.capacity = 1000
agent1.channels.c_hdfs.transactionCapacity = 100


#sinks
agent1.sinks.s_hdfs.type = hdfs
agent1.sinks.s_hdfs.channel = c_hdfs
#default port :8082
agent1.sinks.s_hdfs.hdfs.path= hdfs://spark03:9000/root/source
#agent1.sinks.s_hdfs.filePrefix = event-
agent1.sinks.s_hdfs.hdfs.fileType = DataStream
agent1.sinks.s_hdfs.hdfs.writeFormat = Text
agent1.sinks.s_hdfs.hdfs.rollCount = 30
agent1.sinks.s_hdfs.hdfs.rollSize = 0
agent1.sinks.s_hdfs.hdfs.rollInterval = 0
agent1.sinks.s_hdfs.hdfs.useLocalTimeStamp = true
agent1.sinks.s_hdfs.hdfs.idleTimeout = 51
agent1.sinks.s_hdfs.hdfs.threadsPoolSize = 1


启动agent agent1

在$FLUME_HOME目录中输入

bin/flume-ng agent --conf ./conf -f conf/flume-conf.properties -Dflume.root.logger=DEBUG,console -n agent1


在另一个终端输入

for i in {1..100};do echo "exec tail$i" >> /home/spark/log;echo $i;sleep 0.1;done

结束后输入

hadoop fs -ls -R /root/source 查看是否成功输入到hdfs中


4.spooldir:

agent.sources = r1
agent.sinks = k1
agent.channels = c1


#Describe/configure the source
agent.sources.r1.type=spooldir
#input file location
agent.sources.r1.spoolDir=/home/spark/log/
agent.sources.r1.inputCharset=utf-8




#Derscribe the sink
agent.sinks.k1.type=org.apache.flume.sink.kafka.KafkaSink


#topic
agent.sinks.k1.topic = test
agent.sinks.k1.brokerList = spark02:9092
agent.sinks.k1.requireAcks = 1
agetn.sinks.k1.batchSize = 2000




#User a channel which buffers events in memory
agent.channels.c1.type=memory
agent.channels.c1.capacity=1000
agent.channels.c1.transactionCapacity=100




#Bind the sources and sink to the channel
agent.sources.r1.channels = c1
agent.sinks.k1.channel = c1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Flume是一个分布式、可靠和高效的服务,用于收集、聚合和移动大量日志数据。它主要用于将日志数据从各种源(如Web服务器、数据库、应用程序日志等)中收集,经过处理后将其传输到各种目的地(如Hadoop HDFS、Hive、Kafka等)。 下面是Flume配置使用步骤: 1. 下载并安装Flume 可以从Apache Flume官网下载Flume的最新版本,并按照安装说明进行安装。 2. 编写Flume配置文件 Flume配置文件是一个.properties文件,其中定义了数据源、数据目的地、数据传输顺序等信息。 下面是一个简单的Flume配置文件示例: ``` # 定义agent名称和数据源 agent.sources = source1 agent.sources.source1.type = exec agent.sources.source1.command = tail -F /var/log/messages # 定义数据目的地 agent.sinks = sink1 agent.sinks.sink1.type = avro agent.sinks.sink1.hostname = localhost agent.sinks.sink1.port = 41414 # 定义数据处理管道 agent.channels = channel1 agent.channels.channel1.type = memory agent.channels.channel1.capacity = 1000 agent.channels.channel1.transactionCapacity = 100 #将数据源和数据目的地连接起来 agent.sources.source1.channels = channel1 agent.sinks.sink1.channel = channel1 ``` 其中,agent.sources定义了数据源,agent.sinks定义了数据目的地,agent.channels定义了数据处理管道,通过将数据源和数据目的地连接到数据处理管道上,就可以将数据从源头传输到目的地了。 3. 启动Flume agent 启动Flume agent的命令为: ``` bin/flume-ng agent -n agentName -f /path/to/flume-conf.properties ``` 其中,-n参数指定了agent的名称,-f参数指定了Flume配置文件的路径。 4. 监控Flume agent 可以使用Flume自带的监控工具来监控Flume agent的运行状态。启动监控工具的命令为: ``` bin/flume-ng agent -n agentName -f /path/to/flume-conf.properties -Dflume.monitoring.type=http -Dflume.monitoring.port=34545 ``` 其中,-Dflume.monitoring.type参数指定了监控工具的类型,-Dflume.monitoring.port参数指定了监控工具的端口号。在浏览器中访问http://localhost:34545即可查看监控信息。 这就是Flume配置使用步骤,希望能帮助到您。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值