日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hbase伪分布式配置

發布時間:2024/7/19 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hbase伪分布式配置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.在單機模式的基礎上進行配置,打開hbase-env.sh。

vim /usr/local/hbase/conf/hbase-env.sh

2.配置HBASE_CLASSPATH為hadoop安裝目錄下的conf目錄,即 /usr/local/hadoop/conf。JAVA_HOME、HBASE_MANAGES_ZK之前已經配置好了。

export HBASE_CLASSPATH=/usr/local/hadoop/conf

3.打開hbase-site.xml文件,hbase.rootdir指定hbase數據在HDFS的存儲路徑;將hbase.cluter.distributed設置為true。

vim /usr/local/hbase/conf/hbase-site.xml

配置信息如下

<configuration><property><name>hbase.rootdir</name><value>hdfs://localhost:9000/hbase</value>#指定HBase的存儲目錄。</property><property><name>hbase.cluster.distributed</name>#設置集群處于分布式模式<value>true</value></property><property><name>hbase.unsafe.stream.capability.enforce</name>#避免出現啟動錯誤。<value>false</value></property> </configuration>

4.Hbase的啟動測試,先啟動hadoop,在啟動hbase。

ssh localhost cd /usr/local/hadoop ./sbin/start-dfs.sh jps cd /usr/local/hbase bin/start-hbase.sh jps

最終看到如下信息,則成功開啟。

5.關閉, 先關閉hbase,在關閉hadoop。

bin/stop-hbase.sh cd /usr/local/hadoop ./sbin/stop-dfs.sh

6.Hbase shell 命令

  • 進入hbase的shell
hbase shell 在這里插入代碼片

7.Java API編程

  • 導入hbase的lib目錄下的所有jar包。
package my.hbase; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.*; import org.apache.hadoop.hbase.client.*; import org.apache.hadoop.hbase.util.Bytes;import java.io.IOException;public class HbaseCode {public static Configuration configuration;public static Connection connection;public static Admin admin;public static void main(String[] args)throws IOException{init();createTable("student-info",new String[]{"score"});insertData("student-info","zhangsan","score","English","69");insertData("student-info","zhangsan","score","Math","86");insertData("student-info","zhangsan","score","Computer","77");getData("student-info", "zhangsan", "score","English");close();}public static void init(){configuration = HBaseConfiguration.create();//設置hbase數據存儲的根路徑,放在分布式文件系統hdfs目錄下configuration.set("hbase.rootdir","hdfs://localhost:9000/hbase");try{//建立鏈接connection = ConnectionFactory.createConnection(configuration);admin = connection.getAdmin();}catch (IOException e){e.printStackTrace();}}public static void close(){try{if(admin != null){admin.close();}if(null != connection){connection.close();}}catch (IOException e){e.printStackTrace();}}public static void createTable(String myTableName,String[] colFamily) throws IOException {TableName tableName = TableName.valueOf(myTableName);if(admin.tableExists(tableName)){System.out.println("talbe is exists!");}else {//管理表的信息TableDescriptorBuilder tableDescriptor = TableDescriptorBuilder.newBuilder(tableName);for(String str:colFamily){//管理列族的類ColumnFamilyDescriptor family = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(str)).build();tableDescriptor.setColumnFamily(family);}admin.createTable(tableDescriptor.build());} }public static void insertData(String tableName,String rowKey,String colFamily,String col,String val) throws IOException { Table table = connection.getTable(TableName.valueOf(tableName));Put put = new Put(rowKey.getBytes());put.addColumn(colFamily.getBytes(),col.getBytes(), val.getBytes());table.put(put);table.close(); }public static void getData(String tableName,String rowKey,String colFamily, String col)throws IOException{ Table table = connection.getTable(TableName.valueOf(tableName));Get get = new Get(rowKey.getBytes());get.addColumn(colFamily.getBytes(),col.getBytes());Result result = table.get(get);System.out.println(new String(result.getValue(colFamily.getBytes(),col==null?null:col.getBytes())));table.close(); } }

運行結果查看如下student-info表。

8.源鏈接
廈門大學數據庫實驗室

總結

以上是生活随笔為你收集整理的hbase伪分布式配置的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。