05 flume將數據導入到Hive


我們已經了解了使用flume監聽端口以及文件內容,本節將展示使用flume導入數據到hbase。

1 系統、軟件以及前提約束

2 操作

  • 1 使用xshell登錄到192.168.100.200
  • 2 啟動hadoop
cd /root/hadoop-2.5.2/sbin
./start-all.sh
  • 3 啟動metastore
    cd /root/apache-hive-0.14.0-bin/bin
    ./hive --service metastore
  • 4 修改flume-conf.properties
a1.sources=r1
a1.channels=c1
a1.sinks=s1

a1.sources.r1.type=netcat
a1.sources.r1.bind=192.168.100.200
a1.sources.r1.port=44444

a1.sinks.s1.type=hive
a1.sinks.s1.hive.metastore=thrift://192.168.100.200:9083
a1.sinks.s1.hive.database=flume
a1.sinks.s1.hive.table=t_user
a1.sinks.s1.serializer=DELIMITED
a1.sinks.s1.serializer.delimiter="\t"
a1.sinks.s1.serializer.serdeSeparator='\t'
a1.sinks.s1.serializer.fieldnames=user_id,user_name,age

a1.channels.c1.type=memory
a1.channels.c1.capacity=1000
a1.channels.c1.transactionCapacity=100

a1.sources.r1.channels=c1
a1.sinks.s1.channel=c1
  • 5 拷貝jar包
cp /root/apache-hive-0.14.0-bin/hcatalog/share/hcatalog/* /root/apache-flume-1.8.0-bin/lib/
  • 6 在hive中創建數據庫和表
cd /root/apache-hive-0.14.0-bin/bin
./hive
>create database flume;
>create table t_user(user_id int,user_name string, age int) clustered by(user_id) into 2 buckets stored as orc tblproperties("transactional"='true');
  • 5 通過nc【如果沒有需要通過yum安裝nc】向192.168.100.200的44444端口寫入符合要求的數據
    nc 192.168.100.200 44444
  • 6 查看hive中表的數據
cd /root/apache-hive-0.14.0-bin/bin
./hive
>select * from flume.t_user;

至此,我們完成了flume導入數據到hive。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM