@zhangyy
2020-01-16T09:13:52.000000Z
字数 7601
阅读 377
hbase的部分
- 一:hbase 表的设计管理
- 二:hbase hive 集成
- 三:sqoop 与hbase 的集成
- 四:hbase 与hue 集成
- 五:hbase 表的修复
在新版本的hbase 中 表是存储在命名空间当中,默认的命名空间是default创建一个命名空间:create_namespace 'ns2'查看有多少个命名空间:list_namespace在命名空间中建立表:create 'ns2:student','info'查询命名空间中的表:list_namespace_tables 'ns2'



create 'ns1:t1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'}相当于:create 'ns1:t1', 'f1', 'f2', 'f3'描述一张表:describe 't1'

默认情况下hbase 创建表时,会默认划分region 区域结合实际环境来看,无论是测试环境还是生产环节,我们创建好的hbase 需要大量的的导入数据file/data --> hfile -> bulk load into hbase tables方式一:create 't1', 'f1', SPLITS => ['10', '20', '30', '40']ti(rowkey) Start Key End Keyregion1 10region2 10 20region3 20 30region4 30 40region5 40----方式二:cd /home/hadoop/vim region.txt20160601201606022016060320160604create 't2', 'f1', SPLITS_FILE => '/home/hadoop/region.txt', OWNER => 'johndoe'---方式三: 采用十六进制的这种方式创建create 't3', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit'}



需求: 查询在一段时间的内的通话数依据条件查询telphone + (starttime -- endtime)---time area active phone talktime mode price设计思想:根据rowkey 查询时间比较快rowkey:telphone + time18721732851_20151001092345info:area active phone talktime mode pricescanstartrow18721732851_20150401000000stoprow18721732851_20150413000000---实时性如何在海量数据中,获取我所需要的数据(查询的数据)。表的rowkey设计中:核心思想:依据rowkey查询最快对rowkey进行范围查询range前缀匹配表分区的处理---新需求:新的需求(话单数据的查询)phone + time>>> 依据前面设计的表使用filtercolumnFilter索引表/辅助表(主表) -- 功能phone_time比如:182600937645_2015100100000182600937645_2015102400000列簇:info列:rowkey ->Get最快的数据查询---主表和索引表的数据 如何同步呢?????>> 程序,事物>> phoenix>> JDBC方式,才能同步创建索引表>> solrlilycloudera search
'user',{NAME => 'info',DATA_BLOCK_ENCODING => 'NONE',BLOOM FILTER => 'ROW',REPLICATION_SCOPE => '0',VERSIONS => '1',COMPRESSION => 'NONE',MIN_VERSIONS => '0',TTL => 'FOREVER',KEEP_DELETED_CELLS => 'false',BLOCKSIZE => '65536',IN_MEMORY => 'false',BLOCKCACHE => 'true'}
压缩参数:COMPRESSION => 'NONE',---cd /home/hadoop/yangyang/hadoopbin/hadoop checknative

配置hbase-site.xml 增加:<property><name>hbase.regionserver.codecs</name><value>snappy</value></property>
tar -zxvf hadoop-snappy-0.0.1-SNAPSHOT.tar.gzcd hadoop-snappy-0.0.1-SNAPSHOT/libcp -p hadoop-snappy-0.0.1-SNAPSHOT.jar /home/hadoop/yangyang/hbase/lib/cd /home/hadoop/yangyang/hbase/libmkdir nativecd nativeln -s /home/hadoop/yangyang/hadoop/lib/native ./Linux-amd64-64---从新启动hbasebin/stop-hbase.shbin/start-hbase.shhbase 创建压缩的表create 't1_snappy' ,{NAME => 'f1',COMPRESSION => 'SNAPPY'}put 't1_snappy','1001','f1:name','zhangyy'


RegionServer - 12G>> MemStore 40%write>> BlockCache 40%read>> other 20%
块缓存参数:BLOCKCACHE => 'true'---关于:Memstore& BlockCache1.HBase上Regionserver的内存分为两个部分,一部分作为Memstore,主要用来写;另外一部分作为BlockCache,主要用于读。2.写请求会先写入Memstore,Regionserver会给每个region提供一个Memstore,当Memstore满64MB以后,会启动flush刷新到磁盘。当Memstore的总大小超过限制时(heapsize * hbase.regionserver.global.memstore.upperLimit * 0.9),会强行启动flush进程,从最大的Memstore开始flush直到低于限制。3.读请求先到Memstore中查数据,查不到就到BlockCache中查,再查不到就会到磁盘上读,并把读的结果放入BlockCache。由于BlockCache采用的是LRU策略,因此BlockCache达到上限(heapsize * hfile.block.cache.size * 0.85)后,会启动淘汰机制,淘汰掉最老的一批数据。4.在注重读响应时间的应用场景下,可以将BlockCache设置大些,Memstore设置小些,以加大缓存的命中率。---BlockCache:将Cache分级思想的好处在于:1.首先,通过inMemory类型Cache,可以有选择地将in-memory的column families放到RegionServer内存中,例如Meta元数据信息;2.通过区分Single和Multi类型Cache,可以防止由于Scan操作带来的Cache频繁颠簸,将最少使用的Block加入到淘汰算法中。3.默认配置下,对于整个BlockCache的内存,又按照以下百分比分配给Single、Multi、InMemory使用:0.25、0.50和0.25。
概述:随着memstore 中的数据不断的刷写到磁盘中,会产生越来越多的HFile 文件, HBASE 内部有一个解决这个问题的管理机制,即用合并将多个文件合并成一个较大的文件,合并有两种:minor合并(minor compaction)和major 合并(major compaction). minor 合并将多个小文件从写为数据量较少的大文件,减少对存储文件的数量,这个过程实际上是个多路归并的过程,以为HFile 的每个文件都是经过归类的,所以合并速度很快,只受到磁盘I/O的性能影响。major 合并将一个region 中一个列簇的若干个Hfile 从写为一个新的Hfile,与minor 合并相比,还有更独特的功能:major 合并 能扫描所有的键/值对,顺序从写全部的数据,重写数据的过程中略过做凌删除标记的数据,断言删除此时生效,比如:对于那些超过版本号限制的数据以及生存时间到期的数据,在重写数据时就不再写入磁盘了。
HRegoin Server上的storefile文件是被后台线程监控的,以确保这些文件保持在可控状态。磁盘上的storefile的数量会随着越来越多的memstore被刷新而变等于越来越多——每次刷新都会生成一个storefile文件。当storefile数量满足一定条件时(可以通过配置参数类调整),会触发文件合并操作——minor compaction,将多个比较小的storefile合并成一个大的storefile文件,直到合并的文件大到超过单个文件配置允许的最大值时会触发一次region的自动分割,即region split操作,将一个region平分成2个。
1. minor compaction:轻量级将符合条件的最早生成的几个storefile合并生成一个大的storefile文件,它不会删除被标记为“删除”的数据和以过期的数据,并且执行过一次minor合并操作后还会有多个storefile文件。2. major compaction,重量级把所有的storefile合并成一个单一的storefile文件,在文件合并期间系统会删除标记为"删除"标记的数据和过期失效的数据,同时会block所有客户端对该操作所属的region的请求直到合并完毕,最后删除已合并的storefile文件。
参考官网:https://cwiki.apache.org/confluence/display/Hive/HBaseIntegration进行配置
cd /home/hadoop/yangyang/hive/lib/---ln -s /home/hadoop/yangyang/hbase/lib/hbase-server-0.98.6-cdh5.3.6.jar ./hbase-server-0.98.6-cdh5.3.6.jarln -s /home/hadoop/yangyang/hbase/lib/hbase-client-0.98.6-cdh5.3.6.jar ./hbase-client-0.98.6-cdh5.3.6.jarln -s /home/hadoop/yangyang/hbase/lib/hbase-protocol-0.98.6-cdh5.3.6.jar ./hbase-protocol-0.98.6-cdh5.3.6.jarln -s /home/hadoop/yangyang/hbase/lib/hbase-it-0.98.6-cdh5.3.6.jar ./hbase-it-0.98.6-cdh5.3.6.jarln -s /home/hadoop/yangyang/hbase/lib/htrace-core-2.04.jar ./htrace-core-2.04.jarln -s /home/hadoop/yangyang/hbase/lib/hbase-hadoop2-compat-0.98.6-cdh5.3.6.jar ./hbase-hadoop2-compat-0.98.6-cdh5.3.6.jarln -s /home/hadoop/yangyang/hbase/lib/hbase-hadoop-compat-0.98.6-cdh5.3.6.jar ./hbase-hadoop-compat-0.98.6-cdh5.3.6.jarln -s /home/hadoop/yangyang/hbase/lib/high-scale-lib-1.1.1.jar ./high-scale-lib-1.1.1.jar
vim hive-site.xml 增加:---<property><name>hbase.zookeeper.quorum</name><value>namenode01.hadoop.com</value></property>
cd /home/hadoop/yangyang/hbasebin/stop-hbase.shbin/start-hbase.sh
介于hive管理表:CREATE TABLE hbase_table_1(key int, value string)STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf1:val")TBLPROPERTIES ("hbase.table.name" = "xyz");---hive 截取表的数据到 另一张表:insert overwrite table hbase_table_1 select empno,ename from emp;查询这个表:select * from hbase_table_1;hbase 查询xyz 表:scan 'xyz'注:hive 的管理表中,如果在hive中删除了这张表,hbase 的生成的表也会消失。




在hbase 创建一种空表create 'huser','info'put 'huser','1001','info:name','zhangyy'put 'huser','1001','info:age','12'put 'huser','1002','info:name','harry'put 'huser','1002','info:age','22'


hive 中创建外部表进行与hbase 关联:CREATE EXTERNAL TABLE hbase_user(id int, name string,age int)STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,info:name,info:age")TBLPROPERTIES ("hbase.table.name" = "huser");select * from hbase_user;

使用sqoop 将mysql 里面的表提取到hbase 当中cd /home/hadoop/yangyang/sqoopbin/sqoop import --connect jdbc:mysql://namenode01.hadoop.com:3306/yangyang --username root --password 123456 --table my_user --hbase-create-table --hbase-table student --column-family info --hbase-row-key id---查看hbase 中的表:scan 'student'



cd /home/hadoop/yangyang/hbasebin/hbase-daemon.sh start thrift

[hbase]# Comma-separated list of HBase Thrift servers for clusters in the format of '(name|host:port)'.# Use full hostname with security.## hbase_clusters=(Cluster|localhost:9090)hbase_clusters=(Cluster|namenode01.hadoop.com:9090)# HBase configuration directory, where hbase-site.xml is located.hbase_conf_dir=/home/hadoop/yangyang/hbase/conf# Hard limit of rows or columns per row fetched before truncating.## truncate_limit = 500# 'buffered' is the default of the HBase Thrift Server and supports security.# 'framed' can be used to chunk up responses,# which is useful when used in conjunction with the nonblocking server in Thrift.## thrift_transport=buffered
cd /home/hadoop/yangyang/huebuild/env/bin/supervisor &


5.1:当hbase数据表meta 出现问题的时候需要涉及修复:5.2 当hbase 表的迁移时,根据hdfs 数据block块迁移到另一hdfs 集群 的时候,新的hbase表会出现源没有的这种情况需要重新生成数据源meta进行修复
查看hbasemeta情况hbase hbck1.重新修复hbase meta表(根据hdfs上的regioninfo文件,生成meta表)hbase hbck -fixMeta2.重新将hbase meta表分给regionserver(根据meta表,将meta表上的region分给regionservere)hbase hbck -fixAssignments