脚本宝典收集整理的这篇文章主要介绍了Flume的安装与部署,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
1.安装JDK
https://www.cnblogs@R_512_1718@/live41/p/14235891.htML
2.下载安装包
假定下载到home目录
cd /home
http://flume.apache.org/download.html
下载apache-flume-1.9.0-bin.tar.gz文件
* 其中1.9.0是版本号,如果有新版就下载新版
3.解压安装包
tar -xvf apache-flume-1.9.0-bin.tar.gz
4.改名
5.配置系统环境变量
vim ~/.bashrc
添加以下内容:
export PATH=$PATH:home/flume/bin
更新环境变量
source ~/.bashrc
6.修改配置文件
vim /home/flume/conf/flume-conf
添加以下内容:
# Name the components on this agent a1.sources = r1 a1.sinks = k1 a1.channels = c1 # Describe/configure the source a1.sources.r1.type = netcat a1.sources.r1.bind = localhost a1.sources.r1.port = 44444 # 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
这里的a1是agent名,也就是启动实例名,对应启动命令的agent名(--name)。
常修改的有2个属性
(1) a1.sources.r1.type
http://flume.apache.org/FlumeUserGuide.html#flume-sources
* 常用的有:
netcat - 接收的是原始数据,一般是telnet测试时使用 avro - 只能接收用avro序列化后的数据,一般是实际生产时使用 spooling - 监听本地硬盘的指定目录的文件 kafka - 从kafka的topic获取数据
(2) a1.sinks.k1.type
接收数据的目的地类型(就是保存到哪里),官方说明文档:
http://flume.apache.org/FlumeUserGuide.html#flume-sinks
* 常用的有:
logger - 输出到log4j配置的地方 file_roll - 输出到指定目录 kafka - 输出数据到kafka的指定topic,大数据场景常用 hbase - 存入hbase hive - 存入hive elasticseArch - 输出到elasticsearch,检索类大数据场景常用 avro - 输出为以avro序列化的数据,一般是多级flume时使用。例如,flume1接收原始数据后,序列化为avro数据,再发送给flume2
7.启动
flume-ng agent --conf conf --conf-file /home/flume/conf/flume-conf --name a1 -DFlume.root.logger=INFO,console
也可以用缩写参数,下面语句跟上面的同样效果:
flume-ng agent -c conf -f /home/flume/conf/flume-conf -n a1 -Dflume.root.logger=INFO,console
* 这里的a1必须跟flume-conf里面的agent名一致
8.命令测试
由于上面的flume启动是用前台运行,独占了不能输入命令,所以如果要测试,有2个方法:
a.另外新开窗口输入测试命令
b.使用nohup命令在后台运行flume
下面假设用了a方法,另外新开了窗口输入命令:
telnet localhost 44444
然后输入任意内容,看到运行flume的窗口显示对应消息,就是部署成功了。
9.代码测试
public class FlumeSender { public static void main(String[] args) { String hostname = "localhost"; int port = 44444; RpcClient client = null; try { client = RpcClientFactory.getDefaultInstance(hostname, port); String data = "Hello Flume! times: "; for (int i = 0; i < 3; i++) { Event event = EventBuilder.withBody(data + i, Charset.forName("UTF-8")); client.append(event); } } catch (Exception e) { System.out.println(e); } finally { if (client != null) { client.close(); } } } }
以上是脚本宝典为你收集整理的Flume的安装与部署全部内容,希望文章能够帮你解决Flume的安装与部署所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。