hadoop(十一)、Flume安装配置

本文介绍如何下载并安装Apache Flume 1.8.0版本,包括配置环境变量及部署实例的过程。通过创建netcat.conf配置文件实现数据采集,设置source、channel和sink组件,并使用Flume Agent监听指定端口接收数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、下载安装
1、下载地址:http://flume.apache.org/download.html
2、解压 tar -xvf flume-1.8.0-bin.tar.gz
3、配置环境变量:
vi .bash_profile

    #flume 
    export FLUME_HOME=/opt/module/flume-1.8.0-bin
    export PATH=$PATH:$FLUME_HOME/bin

source .bash_profile

二、部署实例
1、在/opt/module/flume-1.8.0-bin/conf/目录下新建 netcat.conf 配置文件,编辑netcat.conf:

#定义agent名称,source,channel,sink的名称
#a1就是我们给agent起的名字,我们知道有多个agent,那么我们就是通过这个来进行区别
#我们知道agent包含了三个重要的组件,有source,channel,sink
#那么我们也给这个三个组件分别取名字
a1.sources = r1	
a1.channels = c1	
a1.sinks = k1

#定义具体的source内容
#这里是执行命令以及下面对应的具体命令
#这个命令执行后的数据返回给这个source
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444


#定义具体的channel信息
#我们source定义好了,就要来定义我们的channel
a1.channels.c1.type = memory	
a1.channels.c1.capacity = 10000	
a1.channels.c1.transactionCapacity = 100

#定义具体的sink信息
#这个logger sink,就是将信息直接打印到控制台
#就是打印日志
a1.sinks.k1.type = logger

#最后来组装我们之前定义的channel和sink
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

2、运行FlumeAgent,监听本机的44444端口:

flume-ng agent --conf conf --conf-file netcat.conf --name a1 -Dflume.root.logger=INFO,console

conf : 配置文件目录
netcat.conf : 配置文件地址
a1 : agent名称

3、 打开另一终端,通过telnet登录localhost的44444,输入测试数据

telnet 127.0.0.1 44444
### 如何在Hadoop环境中配置并启动Flume #### 配置Flume环境变量 为了确保Flume能够在Hadoop环境中正常运行,首先需要正确设置Flume的环境变量。可以通过编辑`/etc/profile`文件来完成此操作: ```bash vim /etc/profile ``` 在文件末尾添加以下内容以定义Flume的路径[^3]: ```bash export FLUME_HOME=/opt/module/apache-flume-1.9.0-bin export PATH=$PATH:$FLUME_HOME/bin ``` 保存并退出后,执行以下命令使环境变量生效: ```bash source /etc/profile ``` #### 安装和初始化Flume 假设已经下载了Flume压缩包,将其解压至指定目录。例如,可以将Flume解压到`/opt/module`目录下: ```bash tar -zxvf apache-flume-1.9.0-bin.tar.gz -C /opt/module/ ``` 确认解压成功后,进入Flume安装目录验证版本信息: ```bash cd /opt/module/apache-flume-1.9.0-bin ./bin/flume-ng version ``` 如果显示Flume的版本号,则说明安装成功。 #### 启动Flume代理 Flume通过代理(agent)的方式工作,因此需要编写一个简单的Flume配置文件。例如,在`/opt/module/apache-flume-1.9.0-bin/conf`目录下创建名为`flume-conf.properties`的文件,并写入以下内容作为示例[^4]: ```properties # Define a memory channel named 'ch1' agent.channels.ch1.type = memory # Define an Avro source that listens on port 41414 and binds to localhost agent.sources.r1.type = avro agent.sources.r1.bind = 0.0.0.0 agent.sources.r1.port = 41414 # Define a logger sink (writes events to the console) agent.sinks.k1.type = logger # Bind the source, channel, and sink together agent.channels = ch1 agent.sources = r1 agent.sinks = k1 agent.sources.r1.channels = ch1 agent.sinks.k1.channel = ch1 ``` 保存配置文件后,使用以下命令启动Flume代理: ```bash /opt/module/apache-flume-1.9.0-bin/bin/flume-ng agent --conf /opt/module/apache-flume-1.9.0-bin/conf --name agent --conf-file /opt/module/apache-flume-1.9.0-bin/conf/flume-conf.properties -Dflume.root.logger=INFO,console ``` 此时,Flume将在端口`41414`上监听数据输入,并将接收到的数据打印到控制台。 #### 测试FlumeHadoop集成 为了让Flume能够将日志数据传输到HDFS中,需修改配置文件中的sink部分。例如,替换为HDFS Sink: ```properties agent.sinks.k1.type = hdfs agent.sinks.k1.hdfs.path = hdfs://namenode:8020/user/flume/logs/%Y%m%d agent.sinks.k1.hdfs.fileType = DataStream agent.sinks.k1.hdfs.writeFormat = Text agent.sinks.k1.hdfs.rollInterval = 30 ``` 重新启动Flume代理即可实现日志数据向HDFS的传输。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值