我们已经了解了使用flume监听端口以及文件内容,本节将展示使用flume导入数据到hbase。
# 进到hbase启动目录
cd /root/hbase-1.2.6/bin
# 启动hbase服务
./start-hbase.sh
# 登录到hbase客户端
./hbase shell
# 在hbase命令行创建一个表
hbase(main):001:0> create ‘t2‘,‘f2‘
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
# 如有jar包已经存在,选择y予以覆盖
cp /root/hbase-1.2.6/lib/* /root/apache-flume-1.8.0-bin/lib/
# 进入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
# 创建flume监听的文件
touch /root/hbase.txt
# 向hbase.txt中写入字符串
echo ‘Iamzhangli‘>>/root/hbase.txt
echo ‘jiangsuwanhe‘>>/root/hbase.txt
# 登录到hbase客户端
./hbase shell
# 查看t2表,我们会看到刚才加入到hbase.txt中的数据已经进入hbase
hbase(main):001:0> scan ‘t2‘
以上就是flume将数据导入Hbase的过程。
原文:https://www.cnblogs.com/alichengxuyuan/p/12576882.html