<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    gembin

    OSGi, Eclipse Equinox, ECF, Virgo, Gemini, Apache Felix, Karaf, Aires, Camel, Eclipse RCP

    HBase, Hadoop, ZooKeeper, Cassandra

    Flex4, AS3, Swiz framework, GraniteDS, BlazeDS etc.

    There is nothing that software can't fix. Unfortunately, there is also nothing that software can't completely fuck up. That gap is called talent.

    About Me

     

    Try HBase on single host on fedora

       Download and Setup

    1. download the latest hbase-0.19.3 release from http://hadoop.apache.org/hbase/

    2. tar zxvf hbase-0.19.3.tar.gz -C /home/gembin/hbase-dev  (i.e.)

    3. set env variable HBASE_HOME
         $vi /etc/profile
         #set hbase env
        HBASE_HOME=/home/gembin/hbase-dev/hbase-0.19.3
       
    PATH=$HBASE_HOME/bin:$PATH
        export HBASE_HOME PATH
       
        $source  /etc/profile  

    4. modify $HBAE_HOME/conf/hbase-env.sh, set the right JAVA_HOME.
       i.e.  export JAVA_HOME=/home/gembin/jdk1.6.0_14

    5.
    modify $HBAE_HOME/conf/hbase-default.xml,  set the our own hbase.rootdir instead of using the default tmp dir  (this is optional step)
        

    1 <property>
    2     <name>hbase.rootdir</name>
    3     <value>file:///home/gembin/hbase-dev/hbase-0.19.3/hbase_root</value>
    4     <description>The directory shared by region servers.</description>
    5 </property>

    6. ok, now it's time to start hbase
         
    $cd $HBASE_HOME
          $bin/start-hbase.sh 

         
          starting master, logging to /home/gembin/hbase-dev/hbase-0.19.3/bin/../logs/hbase-gembin-master-
    gembin.fedora11.out
          root@localhost's password:
          localhost: starting regionserver, logging to /home/gembin/hbase-dev/hbase-0.19.3/bin/../logs/hbase-root-regionserver-gembin.fedora11.out
        
         you can check the logs in $HBASE_HOME/logs

    7. start hbase shell by:
         $bin/hbase shell
        
    hbase(main):001:0> help
         enter help to check the commands of hbase shell

      Create Table and Put Data

    1. create a table 'blog' with family 'entry' by using:  (These families are “static” like the columns in the RDBMS world.)
       
    hbase(main):004:0> create 'blog','entry'
      0 row(s) in 6.0543 seconds
     
    2. describe table 'blog'
        hbase(main):005:0> describe 'blog'

      {NAME => 'blog', FAMILIES => [{NAME => 'entry', COMPRESSION => 'NONE', VERSIONS => '3', LENGTH => '2147483647', TTL => '-1',
        IN_MEMORY => 'false', BLOCKCACHE => 'false'}]}
        
                                               
    3. insert some data to table  
      hbase(main):006:0> put 'blog','entry1','entry:title','first post'
      hbase(main):007:0> put 'blog','entry1','entry:author','gembin'
      hbase(main):008:0> put 'blog','entry1','entry:content','welcome to hbase world'

    4.query the table
      hbase(main):009:0> get 'blog','entry1'

         COLUMN                       CELL                                                                            
         entry:author                 timestamp=1250344106859, value=gembin                                           
         entry:content               timestamp=1250344149651, value=welcome to hbase world                           
         entry:title                      timestamp=1250343923204, value=first post    

    5. list tables in the hbase by using:
        hbase(main):010:0> list
        blog      
               
    6. enable or disable a table by using:
        hbase(main):011:0> disable 'blog'
        09/08/15 21:56:20 INFO client.HBaseAdmin: Disabled
    blog
        hbase(main):012:0> enable 'blog'
        09/08/15 21:57:03 INFO client.HBaseAdmin: Enabled table blog

    7. drop a table (NOTE: before drop a table, you must first disable a table)
         hbase(main):013:0> drop 'blog'
         09/08/15 22:09:10 INFO client.HBaseAdmin: Deleted blog

       Play Hbase with java code


    package org.hbase.test;

    import java.io.IOException;
    import java.util.HashMap;
    import java.util.Map;

    import org.apache.hadoop.hbase.HBaseConfiguration;
    import org.apache.hadoop.hbase.HConstants;
    import org.apache.hadoop.hbase.client.HTable;
    import org.apache.hadoop.hbase.io.BatchUpdate;
    import org.apache.hadoop.hbase.io.RowResult;

    public class HBaseTester implements HConstants{
        
    public static final String TABLE_BLOG="blog";
        
    public static HTable table;
        
    static{
            
    try {
                table
    =new HTable(new HBaseConfiguration(),TABLE_BLOG);
            } 
    catch (IOException e) {
                e.printStackTrace();
            }
        }
     
        
        
    public static Map<String,String> getEntry(String entryId) throws IOException {
            Map
    <String,String> post = new HashMap<String,String>();
            RowResult result 
    = table.getRow(entryId);
            
    if(result==null){
                System.out.println(
    "not data");
                
    return null;
            }
            
    for (byte[] column : result.keySet()) {
                String theColumn
    =new String(column);
                String theValue
    =new String(result.get(column).getValue());
                
    //System.out.println("{"+theColumn+","+theValue+"}");
                post.put(theColumn,theValue);
            }
            
    return post;
        }
         
        
    public static void main(String[] args) throws Exception {
            Map
    <String,String>entry = getEntry("entry1");
            System.out.println(entry.get(
    "entry:title"));

        }

    }





    1. create table

    static HBaseAdmin admin = null;
        static {
            try {
                HBaseConfiguration conf = new HBaseConfiguration();
                admin = new HBaseAdmin(conf);
            } catch (MasterNotRunningException e) {
                e.printStackTrace();
            }
        }


    public
    static void creatTable(String tableName,HColumnDescriptor[]columnDescriptors) {
            
    try {
                
    if (!admin.tableExists(tableName)) {
                    HTableDescriptor tableDescriptor 
    = new HTableDescriptor(tableName);
                    
    for(HColumnDescriptor column:columnDescriptors){
                        tableDescriptor.addFamily(column);
                    }
                    admin.createTable(tableDescriptor);
                    System.out.println(
    "table create ok!!!");
                } 
    else {
                    System.out.println(
    "table Already exists");
                }
            } 
    catch (MasterNotRunningException e) {
                e.printStackTrace();
            } 
    catch (IOException e) {
                e.printStackTrace();
            }
     }

    HColumnDescriptor[]cols=new HColumnDescriptor[]{
                    new HColumnDescriptor("title:"),
                    new HColumnDescriptor("author:"),
                    new HColumnDescriptor("content:")
    };

    createTable('"blog",cols)

    2.List tables

    public static void listTables() {
            
    try {
                HTableDescriptor[] ts
    = admin.listTables();
                
    if(ts==null)return;
                
    for (int i = 0; i < ts.length; i++) {
                    HTableDescriptor tableDescriptor
    =ts[i];
                    System.out.println(tableDescriptor);

                }
            } 
    catch (IOException e) {
                e.printStackTrace();
            }
    }


    3. insert data to 'blog' table

    public static void insertData(){
            
    try {
                HTable table 
    = new HTable(new HBaseConfiguration(),"blog");
                table.setAutoFlush(
    false);
                table.setWriteBufferSize(
    10);
                ArrayList
    <BatchUpdate> rowsUpdate = new ArrayList<BatchUpdate>();
                BatchUpdate batchUpdate 
    = new BatchUpdate("entry1");
                batchUpdate.put(
    "entry:author""gembin".getBytes());
                batchUpdate.put(
    "entry:content""hbase is great".getBytes());
                batchUpdate.put(
    "entry:title""try hbase".getBytes());
                rowsUpdate.add(batchUpdate);
                table.commit(rowsUpdate); 
                table.flushCommits();
            } 
    catch (IOException e) {
                e.printStackTrace();
            }
    }

    4. List data of table
    public static void listData(){
            
    try {
                HTable table
    =new HTable(new HBaseConfiguration(),"blog");
                Scanner scanner
    =table.getScanner(new String[]{"entry:"});
                Iterator
    <RowResult> it=scanner.iterator();
                
    while(it.hasNext()){
                    RowResult rowResult
    =it.next();
                    System.out.println(
    "------"+new String(rowResult.getRow())+"--------");
    //row name
                    for (Map.Entry<byte[], Cell> e: rowResult.entrySet()) {
                        String column
    =new String(e.getKey());
                        Cell cell 
    = e.getValue();
                        System.out.println(column
    +""+new String(cell.getValue()));
                    }
                }
            } 
    catch (IOException e) {
                e.printStackTrace();
            }
    }

    enjoy it!!!

    next entry, ORM with HBase: http://www.tkk7.com/gembin/archive/2009/08/17/291576.html


    posted on 2009-08-16 00:33 gembin 閱讀(2053) 評論(0)  編輯  收藏 所屬分類: Databasehbase

    導(dǎo)航

    統(tǒng)計(jì)

    常用鏈接

    留言簿(6)

    隨筆分類(440)

    隨筆檔案(378)

    文章檔案(6)

    新聞檔案(1)

    相冊

    收藏夾(9)

    Adobe

    Android

    AS3

    Blog-Links

    Build

    Design Pattern

    Eclipse

    Favorite Links

    Flickr

    Game Dev

    HBase

    Identity Management

    IT resources

    JEE

    Language

    OpenID

    OSGi

    SOA

    Version Control

    最新隨筆

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    free counters
    主站蜘蛛池模板: 久久亚洲AV无码精品色午夜 | 亚洲三级视频在线观看| 三级黄色免费观看| 亚洲国产天堂久久久久久| 亚洲欧美综合精品成人导航| 在线免费观看中文字幕| 亚洲av中文无码字幕色不卡| 日本高清免费不卡在线| 国产亚洲综合视频| 亚洲女同成人AⅤ人片在线观看| 污污污视频在线免费观看| 亚洲综合在线另类色区奇米| 国产成人一区二区三区视频免费| 亚洲高清国产AV拍精品青青草原| 无码一区二区三区免费| 亚洲精品欧洲精品| 最近中文字幕无免费视频| 毛片亚洲AV无码精品国产午夜| www.亚洲一区| 国产成人免费AV在线播放| 亚洲综合久久综合激情久久| 在线视频精品免费| 色天使色婷婷在线影院亚洲| 亚洲色一色噜一噜噜噜| 日日麻批免费40分钟无码| 亚洲人成7777影视在线观看| 日本a级片免费看| 中文在线免费观看| 亚洲专区先锋影音| 免费无遮挡无码视频网站| 美女啪啪网站又黄又免费| 亚洲AV无码国产丝袜在线观看 | 日日AV拍夜夜添久久免费| japanese色国产在线看免费| 亚洲午夜免费视频| 免费鲁丝片一级观看| 日韩精品无码免费专区午夜不卡 | 国产成人精品亚洲| 亚洲国产精品特色大片观看完整版| 可以免费看的卡一卡二| 日韩免费码中文在线观看|