04 flume将数据导入到Hbase


我们已经了解了使用flume监听端口以及文件内容,本节将展示使用flume导入数据到hbase。

1 系统、软件以及前提约束

2 操作

  • 1 使用xshell登录到192.168.100.200
  • 2 启动hbase服务,登录到hbase客户端,创建表
# 进到hbase启动目录
cd /root/hbase-1.2.6/bin
# 启动hbase服务
./start-hbase.sh
# 登录到hbase客户端
./hbase shell
# 在hbase命令行创建一个表
hbase(main):001:0> create 't2','f2'
  • 3 修改flume-conf.properties,其中a1为flume的服务名称
a1.sources = r1 
a1.sinks = k1 
a1.channels = c1 # Describe/configure the source 
a1.sources.r1.type = exec 
a1.sources.r1.command = tail -F /root/hbase.txt 
a1.sources.r1.channels = c1 # Describe the sink 
a1.sinks.k1.type = logger 
a1.sinks.k1.type = hbase 
# 与hbase中创建的表名相同
a1.sinks.k1.table = t2
# 与hbase中创建的表的列簇相同
a1.sinks.k1.columnFamily = f2
a1.sinks.k1.serializer = org.apache.flume.sink.hbase.RegexHbaseEventSerializer 
a1.sinks.k1.channel = memoryChannel # 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
  • 4 拷贝jar包
# 如有jar包已经存在,选择y予以覆盖
cp /root/hbase-1.2.6/lib/* /root/apache-flume-1.8.0-bin/lib/
  • 5 启动flume服务
# 进入flume的启动目录
cd /root/apache-flume-1.8.0-bin/bin
# 启动flume
./flume-ng agent -c ../conf -f ../conf/flume-conf.properties -n a1 -Dflume.root.logger=INFO,console
  • 6 测试
# 创建flume监听的文件
touch /root/hbase.txt 
# 向hbase.txt中写入字符串
echo 'Iamzhangli'>>/root/hbase.txt
echo 'jiangsuwanhe'>>/root/hbase.txt
  • 7 查看hbase中t2表的内容
# 登录到hbase客户端
./hbase shell
# 查看t2表,我们会看到刚才加入到hbase.txt中的数据已经进入hbase
hbase(main):001:0> scan 't2'

以上就是flume将数据导入Hbase的过程。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM