HBase配置以及在Windows下串連HBase設定

來源:互聯網
上載者:User

本文介紹了在Linux環境下以單機模式安裝HBase,並在Windows下使用Eclipse進行開發時串連HBase的相關設定。

1、  安裝Linux系統(ubuntu 10.04server)安裝時請安裝上附加的open ssh-server。機器名字:ubuntu(cat /etc/hostname,結果是ubuntu)

2、  安裝java,設定環境變數。在/etc/profile末尾追加下面三行。

exportJAVA_HOME="/home/had/jdk1.6.0_20"

exportCLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib

export PATH=.:$PATH:$JAVA_HOME/bin

         其中JAVA_HOME指向的目錄是java安裝目錄

3、  ssh上傳hbase-0.90.4.tar.gz至/home/had目錄。tar xzf hbase-0.90.4.tar.gz解壓

4、  進入hbase-0.90.4目錄,編輯conf/hbase-site.xml檔案,在configuration裡面加入:

<property>

           <name>hbase.rootdir</name>

           <value>/home/had/hbase-0.90.4/data</value>

</property>

作用是將資料存放區路徑設定在value指定的目錄

5、  Linux Ubuntu 10.04 server./etc/hosts

a)        注釋掉127.0.1.1     ubuntu.localdomain      Ubuntu

b)        加一行192.168.128.128  ubuntu  

                        i.             192.168.128.128是本機ip

                      ii.             ubuntu是機器名

6、  測試hbase:

a)        cd hbase-0.90.4

b)        bin/start-hbase.sh

c)        bin/hbase shell

d)        create  ‘database’,’cf’

e)        list

f)         如果成功則可以看到有下面的結果:

hbase(main):001:0>list

TABLE                                                                                                                                                                             

database                                                                                                                                                                          

1 row(s)in 0.5910 seconds

 

hbase(main):002:0>

http://192.168.128.128:60010/master.jsp這個頁面也可看到相應資訊

7、  windows c:/windows/system32/dirvers/hosts檔案加一行:

192.168.128.128 ubuntu 

使得windows將ubuntu解析為ip地址192.168.128.128

8、  開啟eclipse,建立工程,將hbase-0.90.4下面的lib目錄拷貝到工程,將其中的jar包加入classpath

9、  建立一類HelloHbase:

package demo;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.util.Bytes;

public class HelloHBase {
public static void main(String[] args) throws IOException {
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "192.168.128.128");
HBaseAdmin admin = new HBaseAdmin(conf);
HTableDescriptor tableDescriptor = admin.getTableDescriptor(Bytes.toBytes("database"));
byte[] name = tableDescriptor.getName();
System.out.println(new String(name));
HColumnDescriptor[] columnFamilies = tableDescriptor.getColumnFamilies();
for (HColumnDescriptor d : columnFamilies) {
System.out.println(d.getNameAsString());
}
}
}

 

運行,此時應該列印出下面兩行:

database

cf

若沒有,說明配置失敗,請檢查其他設定。

 

其中,第5、7步以及代碼中的conf.set("hbase.zookeeper.quorum","192.168.128.128");一行至關重要。決定著能否在windows上連上HBase。

 

 

參考資料:

HBase官方文檔:http://hbase.apache.org/book/quickstart.html

HBase 中文文檔:http://www.yankay.com/wp-content/hbase/book.html

解決在其它機器使用Eclipse開發串連HBase出現異常時的參考資料:http://hi.baidu.com/laozhenghit/blog/item/987608440c76d5146a63e523.html

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.