• hbase多master和动态添加节点,hbase获取不同版本


    8. 如何配置HMater主备

    在任意的安装了hbase的机器上启动hmaster

    命令:

    hbase-deamon.sh start master  

    9.添加HBase节点

     9.1 复制原子节点到新节点上

    92. hbase-daemon.sh start regionserver

     

     

     

    hbase获取不同版本

    版本问题

    1. 查看

    在HBase中 一个row对应的相同的列只会有一行。使用scan 或get 得到都是最新的数据,如果我们对这某一row所对应的列进行了更改操作后,并不会多生成一条数据,

    不会像数据库一样,插入时多生成一条记录,在HBase中对同一条数据的修改或插入都只是put操作,最终看到的都是最新的数据,其它的数据在不同的version中保存,

    默认是隐藏的,通过时间戳区分,Hbase默认保存最近的三个版本,如何才能看到这些旧版本的数据了?

     

    1.1. 插入测试数据:

     

    [sql] view plaincopy

    hbase(main):026:0> put 'testtable1','row-1','colfam1:qual1','你好,中国'  

    0 row(s) in 0.0200 seconds  

      

    hbase(main):027:0> put 'testtable1','row-1','colfam1:qual1','你好,广州'  

    0 row(s) in 0.0130 seconds  

      

    hbase(main):027:0> put 'testtable1','row-1','colfam1:qual1','welcome,hbase'  

    0 row(s) in 0.0130 seconds  

     

    1.2. 下面3个命令,只显示最近的三个版本

    [sql] view plaincopy

    hbase(main):015:0> get 'testtable1','row-1',{COLUMN=>'colfam1:qual1',VERSIONS=>10}  

    COLUMN                             CELL                                                                                               

     colfam1:qual1                     timestamp=1410943676361, value=welcomexEFxBCx8Chbase                                            

     colfam1:qual1                     timestamp=1410942935244, value=xE4xBDxA0xE5xA5xBDxEFxBCx8CxE5xB9xBFxE5xB7x9E        

     colfam1:qual1                     timestamp=1410942917285, value=xE4xBDxA0xE5xA5xBDxEFxBCx8CxE4xB8xADxE5x9BxBD        

    3 row(s) in 0.0270 seconds  

      

    hbase(main):016:0> scan 'testtable1', {COLUMN=>'colfam1:qual1',VERSIONS=>10}  

    ROW                                COLUMN+CELL                                                                                        

     row-1                             column=colfam1:qual1, timestamp=1410943676361, value=welcomexEFxBCx8Chbase                      

     row-1                             column=colfam1:qual1, timestamp=1410942935244, value=xE4xBDxA0xE5xA5xBDxEFxBCx8CxE5xB9  

                                       xBFxE5xB7x9E                                                                                   

     row-1                             column=colfam1:qual1, timestamp=1410942917285, value=xE4xBDxA0xE5xA5xBDxEFxBCx8CxE4xB8  

                                       xADxE5x9BxBD                                                                                   

    1 row(s) in 0.0300 seconds  

      

    hbase(main):017:0> scan 'testtable1', {FILTER => "PrefixFilter ('row-1')",COLUMN=>'colfam1:qual1',VERSIONS=>10}  

    ROW                                COLUMN+CELL                                                                                        

     row-1                             column=colfam1:qual1, timestamp=1410943676361, value=welcomexEFxBCx8Chbase                      

     row-1                             column=colfam1:qual1, timestamp=1410942935244, value=xE4xBDxA0xE5xA5xBDxEFxBCx8CxE5xB9  

                                       xBFxE5xB7x9E                                                                                   

     row-1                             column=colfam1:qual1, timestamp=1410942917285, value=xE4xBDxA0xE5xA5xBDxEFxBCx8CxE4xB8  

                                       xADxE5x9BxBD                                                                                   

    1 row(s) in 0.0220 seconds  

     

    1.3. 下面2个命令,可以显示所有的版本

    [sql] view plaincopy

    hbase(main):018:0> scan 'testtable1',{FILTER => "(QualifierFilter (>=, 'binary:qual1')))",RAW => true, VERSIONS => 10}  

    ROW                                COLUMN+CELL                                                                                        

     row-1                             column=colfam1:qual1, timestamp=1410943676361, value=welcomexEFxBCx8Chbase                      

     row-1                             column=colfam1:qual1, timestamp=1410942935244, value=xE4xBDxA0xE5xA5xBDxEFxBCx8CxE5xB9  

                                       xBFxE5xB7x9E                                                                                   

     row-1                             column=colfam1:qual1, timestamp=1410942917285, value=xE4xBDxA0xE5xA5xBDxEFxBCx8CxE4xB8  

                                       xADxE5x9BxBD                                                                                   

     row-1                             column=colfam1:qual1, timestamp=1410936055137, value=xE4xB8xADxE5x9BxBDxE7xACxACxE4xB8  

                                       x89xE6x96xB9xE7x9Ax84xE4xBAx8CxE6x96xB9xE7x9Ax84                                   

     row-1                             column=colfam1:qual1, timestamp=1410936031157, value=xE4xB8xADxE5x9BxBDxE7xACxACxE4xB8  

                                       x89xE6x96xB9xE7x9Ax84                                                                       

    1 row(s) in 0.0290 seconds  

      

    hbase(main):019:0> scan 'testtable1',{FILTER => "PrefixFilter ('row-1')",RAW => true, VERSIONS => 10}  

    ROW                                COLUMN+CELL                                                                                        

     row-1                             column=colfam1:qual1, timestamp=1410943676361, value=welcomexEFxBCx8Chbase                      

     row-1                             column=colfam1:qual1, timestamp=1410942935244, value=xE4xBDxA0xE5xA5xBDxEFxBCx8CxE5xB9  

                                       xBFxE5xB7x9E                                                                                   

     row-1                             column=colfam1:qual1, timestamp=1410942917285, value=xE4xBDxA0xE5xA5xBDxEFxBCx8CxE4xB8  

                                       xADxE5x9BxBD                                                                                   

     row-1                             column=colfam1:qual1, timestamp=1410936055137, value=xE4xB8xADxE5x9BxBDxE7xACxACxE4xB8  

                                       x89xE6x96xB9xE7x9Ax84xE4xBAx8CxE6x96xB9xE7x9Ax84                                   

     row-1                             column=colfam1:qual1, timestamp=1410936031157, value=xE4xB8xADxE5x9BxBDxE7xACxACxE4xB8  

                                       x89xE6x96xB9xE7x9Ax84                                                                       

     row-1                             column=colfam2:col-0, timestamp=1410935938913, value=val-1.0                                       

     row-1                             column=colfam2:col-1, timestamp=1410935938921, value=val-1.1                                       

     row-1                             column=colfam2:col-2, timestamp=1410935938927, value=val-1.2                                       

     row-1                             column=colfam2:col-3, timestamp=1410935938929, value=val-1.3                                       

     row-1                             column=colfam2:col-4, timestamp=1410935938932, value=val-1.4                                       

     row-1                             column=colfam2:col-5, timestamp=1410935938935, value=val-1.5                                       

     row-1                             column=colfam2:col-6, timestamp=1410935938937, value=val-1.6                                       

     row-1                             column=colfam2:col-7, timestamp=1410935938939, value=val-1.7                                       

     row-1                             column=colfam2:col-8, timestamp=1410935938941, value=val-1.8                                       

     row-1                             column=colfam2:col-9, timestamp=1410935938944, value=val-1.9                                       

                                         

    1 row(s) in 0.0690 seconds  

     

    1.4. 用java代码测试:

    [java] view plaincopy

    package client;  

      

    // cc GetExample Example application retrieving data from HBase  

    import org.apache.hadoop.conf.Configuration;  

    import org.apache.hadoop.hbase.HBaseConfiguration;  

    import org.apache.hadoop.hbase.client.Get;  

    import org.apache.hadoop.hbase.client.HTable;  

    import org.apache.hadoop.hbase.client.Result;  

    import org.apache.hadoop.hbase.util.Bytes;  

      

    import util.HBaseHelper;  

      

    import java.io.IOException;  

      

    import org.apache.hadoop.hbase.KeyValue;  

      

    import java.util.List;  

    public class GetExample {  

      

      public static void main(String[] args) throws IOException {  

        // vv GetExample  

        Configuration conf = HBaseConfiguration.create(); // co GetExample-1-CreateConf Create the configuration.  

        conf.set("hbase.zookeeper.property.clientPort", "2181");    

        conf.set("hbase.zookeeper.quorum", "jifeng01");    

        conf.set("zookeeper.znode.parent", "/hbase");  

        /*/ ^^ GetExample

        HBaseHelper helper = HBaseHelper.getHelper(conf);

        if (!helper.existsTable("testtable1")) {

          helper.createTable("testtable1", "colfam1");

        }

        */  

        //vv GetExample  

        HTable table = new HTable(conf, "testtable1"); // co GetExample-2-NewTable Instantiate a new table reference.  

      

        Get get = new Get(Bytes.toBytes("row-1")); // co GetExample-3-NewGet Create get with specific row.  

        get.setMaxVersions();  

        get.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"));  

        Result result = table.get(get);  

        List<KeyValue> list = result.list();   

         for(final KeyValue kv:list){  

            // System.out.println("value: "+ kv+ " str: "+Bytes.toString(kv.getValue()));  

             System.out.println(String.format("row:%s, family:%s, qualifier:%s, qualifiervalue:%s, timestamp:%s.",   

                     Bytes.toString(kv.getRow()),   

                     Bytes.toString(kv.getFamily()),   

                     Bytes.toString(kv.getQualifier()),   

                     Bytes.toString(kv.getValue()),  

                     kv.getTimestamp()));       

         }  

        /*

        get.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1")); // co GetExample-4-AddCol Add a column to the get.

         

        Result result = table.get(get); // co GetExample-5-DoGet Retrieve row with selected columns from HBase.

     

        byte[] val = result.getValue(Bytes.toBytes("colfam1"),

          Bytes.toBytes("qual1")); // co GetExample-6-GetValue Get a specific value for the given column.

     

        System.out.println("Value: " + Bytes.toString(val)); // co GetExample-7-Print Print out the value while converting it back.

         

        */  

        // ^^ GetExample  

      }  

    }  

     

    输出结果:

    [sql] view plaincopy

    row:row-1, family:colfam1, qualifier:qual1, qualifiervalue:welcome,hbase, timestamp:1410943676361.  

    row:row-1, family:colfam1, qualifier:qual1, qualifiervalue:你好,广州, timestamp:1410942935244.  

    row:row-1, family:colfam1, qualifier:qual1, qualifiervalue:你好,中国, timestamp:1410942917285.  

    2. 删除

    删除指定版本的数据:

    delete 'testtable1','row-1','colfam1:qual1',1433337394363

    注意:如果是删除最新的版本,那么将查不出数据了。

    3. 列族操作

    3.1. 增加

    1、表置为不可用:disable 'scores'

    2、增加列族:alter 'scores',NAME=>'info'

    3、表可用:enable 'scores'

    3.2. 删除

    alter 't1′, NAME => 'f1′, METHOD => 'delete'

    alter 't1′, 'delete' => 'f1′

     

     

     

     

     

    HBase 性能优化

     

     

    1. 修改Linux最大文件数

     

    Linux系统最大可打开文件数一般默认的参数值是1024,如果你不进行修改并发量上来的时候会出现“Too Many Open Files”的错误,导致整个HBase不可运行

     

    查看: ulimit -a    结果:open files (-n) 1024

     

    临时修改: ulimit -n 4096

     

    持久修改:

     

    vi /etc/security/limits.conf在文件最后加上:

     

    * soft nofile 65535

     

    * hard nofile 65535

     

    * soft nproc 65535

     

    * hard nproc 65535

     

    2. 修改 JVM 配置

     

    修改hbase-env.sh文件中的配置参数
    —HBASE_HEAPSIZE 4000 #HBase使用的 JVM 堆的大小
    —HBASE_OPTS "‐server ‐XX:+UseConcMarkSweepGC"JVM #GC 选项

     

    参数解释:

     

    -client,-server

     

    这两个参数用于设置虚拟机使用何种运行模式,client模式启动比较快但运行时性能和内存管理效率不如server模式,通常用于客户端应用程序。相反,server模式启动比client慢,但可获得更高的运行性能。

     

    ‐XX:+UseConcMarkSweepGC:设置为并发收集

     

    3. 修改HBase配置:hbase-site.xml

     

    3.1. zookeeper.session.timeout

     

    —默认值:3分钟(180000ms),可以改成1分钟
    说明:RegionServer与Zookeeper间的连接超时时间。当超时时间到后,ReigonServer会被Zookeeper从RS集群清单中移除,HMaster收到移除通知后,会对这台server负责的regions重新balance,让其他存活的RegionServer接管.

     

    调优:
    这个timeout决定了RegionServer是否能够及时的failover。设置成1分钟或更低,可以减少因等待超时而被延长的failover时间。
    不过需要注意的是,对于一些Online应用,RegionServer从宕机到恢复时间本身就很短的(网络闪断,crash等故障,运维可快速介入),如果调低timeout时间,反而会得不偿失。因为当ReigonServer被正式从RS集群中移除时,HMaster就开始做balance了(让其他RS根据故障机器记录的WAL日志进行恢复)。当故障的RS在人工介入恢复后,这个balance动作是毫无意义的,反而会使负载不均匀,给RS带来更多负担。特别是那些固定分配regions的场景。 

     

    3.2. ——hbase.regionserver.handler.count 

     

    —默认值:10
    说明:RegionServer的请求处理IO线程数。
    调优:
    这个参数的调优与内存息息相关。
    较少的IO线程,适用于处理单次请求内存消耗较高的Big PUT场景(大容量单次PUT或设置了较大cache的scan,均属于Big PUT)或ReigonServer的内存比较紧张的场景。
    较多的IO线程,适用于单次请求内存消耗低,TPS(吞吐量)要求非常高的场景。

     

    3.3. hbase.hregion.max.filesize 

     

    默认值:256M
    说明:在当前ReigonServer上单个Reigon的最大存储空间,单个Region超过该值时,这个Region会被自动split成更小的region。
    调优:
    小region对split和compaction友好,因为拆分region或compact小region里的storefile速度很快,内存占用低。缺点是split和compaction会很频繁。
    特别是数量较多的小region不停地split, compaction,会导致集群响应时间波动很大,region数量太多不仅给管理上带来麻烦,甚至会引发一些Hbase的bug。
    一般512以下的都算小region。
    大region,则不会经常split和compaction,因为做一次compact和split会产生较长时间的停顿,对应用的读写性能冲击非常大。 

     

    3.4. hfile.block.cache.size  

     

    默认值:0.2
    说明:storefile的读缓存占用内存的大小百分比,0.2表示20%。该值直接影响数据读的性能。
    调优:当然是越大越好如果写比读少很多,开到0.4-0.5也没问题。如果读写较均衡,0.3左右。如果写比读多,果断默认吧。
    —HBase上Regionserver的内存分为两个部分一部分作为Memstore,主要用来写另外一部分作为BlockCache,主要用于读。
    —写请求会先写入Memstore,Regionserver会给每个region提供一个Memstore,当Memstore满64MB以后,会启动 flush刷新到磁盘。
    读请求先到Memstore中查数据,查不到就到BlockCache中查再查不到就会到磁盘上读,并把读的结果放入BlockCache。由于BlockCache采用的是LRU策略(Least Recently Used 近期最少使用算法),因此BlockCache达到上限(heapsize * hfile.block.cache.size * 0.85)后,会启动淘汰机制,淘汰掉最老的一批数据。
    —一个Regionserver上有一个BlockCache和N个Memstore,它们的大小之和不能大于等于内存 * 0.8,否则HBase不能启动。默认BlockCache为0.2而Memstore为0.4。对于注重读响应时间的系统可以将 BlockCache设大些,比如设置BlockCache=0.4,Memstore=0.39,以加大缓存的命中率
     

     

    3.5. hbase.hregion.memstore.block.multiplier  

     

    默认值:2
    说明:当一个region里的memstore占用内存大小超过hbase.hregion.memstore.flush.size两倍的大小时,block该region的所有请求,进行flush,释放内存。
    虽然我们设置了region所占用的memstores总内存大小,比如64M,但想象一下,在最后63.9M的时候,我Put了一个200M的数据,此时memstore的大小会瞬间暴涨到超过预期的hbase.hregion.memstore.flush.size的几倍。这个参数的作用是当memstore的大小增至超过hbase.hregion.memstore.flush.size 2倍时,block所有请求,遏制风险进一步扩大。
    调优: 这个参数的默认值还是比较靠谱的。如果你预估你的正常应用场景(不包括异常)不会出现突发写或写的量可控,那么保持默认值即可。 

     

  • 相关阅读:
    mysql在ubuntu中的操作笔记(详)
    Ubuntu16.04上安装MySQL(详细过程)
    Python全栈开发day7
    Python全栈开发day6
    Python全栈开发day5
    Python内置函数总结
    Python全栈开发day4
    Python 集合方法总结
    Python全栈开发day3
    Web前端之CSS_day3-4
  • 原文地址:https://www.cnblogs.com/shan13936/p/13785001.html
Copyright © 2020-2023  润新知