最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

HBase安裝配置和管理

2023-06-28 19:58 作者:thisishui  | 我要投稿

一、HBase配置和啟動(dòng)

1、安裝zookeeper和hbase

下載文件zookeeper-3.4.14.tar.gz
https://archive.apache.org/dist/zookeeper/zookeeper-3.4.14/
下載的文件需上傳至Linux本地的/home目錄下,然后執(zhí)行解壓的操作

tar xfz /home/zookeeper-3.4.14.tar.gz

默認(rèn)解壓到/home/zookeeper-3.4.14

下載文件hbase-2.1.5-bin.tar.gz
https://archive.apache.org/dist/hbase/2.1.5/
下載的文件同樣需上傳至Linux本地的/home目錄下,然后執(zhí)行解壓的操作

tar xfz /home/hbase-2.1.5-bin.tar.gz

默認(rèn)解壓到/home/hbase-2.1.5

2、將hbase添加到環(huán)境變量中

vi /etc/profile
export HBASE_HOME=/home/hbase-2.1.5
export PATH=$HBASE_HOME/bin:$PATH

3、修改hbase-env.sh

vi /home/hbase-2.1.5/conf/hbase-env.sh
export JAVA_HOME=/home/jdk1.8.0_161	//去掉該行注釋并改為實(shí)際安裝的jdk版本

4、修改conf/hbase-site.xml的配置
注意把第三行"主節(jié)點(diǎn)IP地址“和第七行指定位置替換為hadoop集群中主節(jié)點(diǎn)的IP地址


<configuration> ?
 ?<property>
 ? ?<name>hbase.rootdir</name>				//指定本機(jī)的hbase的存儲(chǔ)目錄
 ? <value>hdfs://主節(jié)點(diǎn)IP地址:9000/hbase</value>	//必須與hadoop中的core-site.xml中的地址保持一致
 ?</property>
 ?<property>
 ? ?<name>hbase.cluster.distributed</name>		//指定hbase的運(yùn)行模式,true代表全分布模式
 ? ?<value>true</value>
 ?</property>
 ?<property>
 ? ?<name>hbase.zookeeper.property.dataDir</name>	//Zookeeper安裝目錄
 ? ?<value>/home/zookeeper-3.4.14</value>
 ?</property>
 ?<property>
 ? ?<name>hbase.unsafe.stream.capability.enforce</name>
 ? ?<value>false</value>
 ?</property>
 ?<property>
 ? ?<name>hbase.zookeeper.quorum</name>			//Zookeeper的運(yùn)行節(jié)點(diǎn)
 ? ?<value>節(jié)點(diǎn)ip或主機(jī)名:2181(多個(gè)節(jié)點(diǎn)用逗號(hào)隔開)</value>	//須配置多個(gè)節(jié)點(diǎn)
 ?</property>
 ?<property>
 ? ?<name>hbase.master.info.port</name>		//HBase Web服務(wù)
 ?<value>60010</value>
</property>
</configuration> 

5、修改域服務(wù)器地址

vi /home/hbase-2.1.5/conf/regionservers

可以使用主機(jī)名或IP地址,最好使用主機(jī)名,比如:


6、將zookeeper和hbase復(fù)制至slave(需要修改為自己實(shí)際的節(jié)點(diǎn)IP地址或主機(jī)名)

scp -r /home/zookeeper-3.4.14 root@從節(jié)點(diǎn)1IP地址:/home
scp -r /home/zookeeper-3.4.14 root@從節(jié)點(diǎn)2IP地址:/home
scp -r /home/hbase-2.1.5 root@從節(jié)點(diǎn)1IP地址:/home
scp -r /home/hbase-2.1.5 root@從節(jié)點(diǎn)2IP地址:/home

7、啟動(dòng)hbased
首先啟動(dòng)hadoop

cd /home/hadoop/hadoop-3.1.2
sbin/start-all.sh

啟動(dòng)hbase


cd /home/hbase-2.1.5
bin/start-hbase.sh

查看守護(hù)進(jìn)程,jps,除了hadoop的守護(hù)進(jìn)程外還需要包括hbase的守護(hù)進(jìn)程:
Master:HMaster (由Zookpeer選舉產(chǎn)生,一般在主節(jié)點(diǎn)中)
域服務(wù)器:HRegionServer (regionservers中指定的節(jié)點(diǎn)有此進(jìn)程)
Zookeeper節(jié)點(diǎn):HQuorumPeer (在多個(gè)節(jié)點(diǎn)上運(yùn)行,hbase.zookeeper.quorum中配置的節(jié)點(diǎn))


查看web頁面
宿主機(jī)瀏覽器中:主節(jié)點(diǎn)地址:60010

二、解決HMaster消失問題
1、在第一步最后,執(zhí)行jps之后,過一段時(shí)間再執(zhí)行jps,可能發(fā)現(xiàn)HMaster守護(hù)進(jìn)程消失
HMaster消失,一般是zookeeper崩潰導(dǎo)致,進(jìn)入HBase的logs目錄,查看zookeeper的日志可看到類似錯(cuò)誤:
quorum.QuorumCnxManager: Cannot open channel to 1 at election address node2/192.168.56.12:3888
java.net.ConnectException: Connection refused(Connection refused)

也有可能zookeeper未崩潰,但是無法選舉新的hmaster,執(zhí)行建表命令時(shí)會(huì)報(bào)錯(cuò):
ERROR: KeeperErrorCode = NoNode for /hbase/master

2、解決方案:
1.確定DataNode正常運(yùn)行,最好是三個(gè)節(jié)點(diǎn)都配上DataNode
在hadoop的workers文件中將三個(gè)節(jié)點(diǎn)都配上

2.(1)進(jìn)入hbase安裝目錄
(2)進(jìn)入配置文件目錄conf
(3)打開配置文件hbase-site.xml
(4)修改配置項(xiàng)hbase.zookeeper.quorum的值,將所有節(jié)點(diǎn)配入(最好是奇數(shù)個(gè)),以自己實(shí)際的主機(jī)名或IP地址為主
主節(jié)點(diǎn)IP地址:2181,從節(jié)點(diǎn)1IP地址:2181,從節(jié)點(diǎn)2IP地址:2181
(5)用scp命令將hbase-site.xml復(fù)制到其他節(jié)點(diǎn)

3.(1)進(jìn)入zookeeper安裝目錄

cd /home/zookeeper-3.4.14

分別查看三個(gè)節(jié)點(diǎn)的myid文件


cat myid

(2)進(jìn)入配置文件目錄conf
(3)用拷貝命令從示例文件中創(chuàng)建配置文件


cp zoo_sample.cfg zoo.cfg

(4)修改zoo.cfg,在尾部添加
注意:server.后的數(shù)字為前文查看三個(gè)節(jié)點(diǎn)中myid對(duì)應(yīng)的數(shù)字


server.0:主節(jié)點(diǎn)名稱或IP地址:2888:3888
 server.1:從節(jié)點(diǎn)1名稱或IP地址:2888:3888
 server.2:從節(jié)點(diǎn)2名稱或IP地址:2888:3888

(5)用scp命令將zoo.cfg復(fù)制到其他節(jié)點(diǎn)

scp zoo.cfg root@從節(jié)點(diǎn)1IP地址:/home/zookeeper-3.4.14/conf
scp zoo.cfg root@從節(jié)點(diǎn)2IP地址:/home/zookeeper-3.4.14/conf

4.(1)添加zookeeper數(shù)據(jù)目錄(三個(gè)節(jié)點(diǎn)均操作)


mkdir /tmp/zookeeper

(2)在三個(gè)節(jié)點(diǎn)中的/tmp/zookeeper中分別創(chuàng)建文本文件myid,內(nèi)容具體為zoo.cfg中server后的數(shù)字,如:
節(jié)點(diǎn)Hadoop01中的myid文件內(nèi)容為0
節(jié)點(diǎn)Hadoop02中的myid文件內(nèi)容為1
節(jié)點(diǎn)Hadoop03中的myid文件內(nèi)容為2
三、HBase命令行測(cè)試(確保hadoop已啟動(dòng),且HMaster不再消失)
啟動(dòng)hbase,進(jìn)入hbase命令行


cd /home/hbase-2.1.5
bin/start-hbase.sh
bin/hbase shell

1.創(chuàng)建一個(gè)Student表,包含Base和Score兩個(gè)列族;Base列族包含Number、Name、Sex、Prof列;Score列族包含English、Math、Market、Java、Python、BigData列

2.往表中新增數(shù)據(jù),每行rowkey設(shè)置為學(xué)生學(xué)號(hào)

3.獲取列鍵001的數(shù)學(xué)成績;

get 'Student','001','Score:Math'

4.刪除一行數(shù)據(jù)

deleteall 'Student','004'

5.獲取學(xué)號(hào)范圍從001~003的學(xué)生的基本信息(列族為Base)

scan 'Student',{STARTROW=>'001',STOPROW=>'004',COLUMNS=>'Base'}

6.搜索所有bigdata專業(yè)的學(xué)生

scan 'Student',{COLUMNS=>'Base:Prof',FILTER=>"ValueFilter(=,'binary:bigdata')"}

7.使用scan命令的filter搜索所有不及格的成績記錄

scan 'Student',{COLUMN=>'Score',FILTER=>"ValueFilter(<,'binary:60')"}

四、HBase Java API 操作
1、在IDEA中新建Marven項(xiàng)目,修改pom.xml,在pom.xml文件中的根節(jié)點(diǎn)中,添加一個(gè)子節(jié)點(diǎn),如下圖:

2、查詢maven組件配置https://mvnrepository.com/
?。∽⒁庠诓樵兘M件時(shí)選擇的組件要和實(shí)際安裝的hadoop版本一致,下面的以hadoop-3.1.2版本為例
需要查詢的組件:
hadoop-client

<!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-client -->
<dependency>
 ? ?<groupId>org.apache.hadoop</groupId>
 ? ?<artifactId>hadoop-client</artifactId>
 ? ?<version>3.1.2</version>
</dependency>

hadoop-hdfs

<!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-hdfs -->
<dependency>
 ? ?<groupId>org.apache.hadoop</groupId>
 ? ?<artifactId>hadoop-hdfs</artifactId>
 ? ?<version>3.1.2</version>
 ? ?<scope>test</scope>
</dependency>

hadoop-common

<!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-common -->
<dependency>
 ? ?<groupId>org.apache.hadoop</groupId>
 ? ?<artifactId>hadoop-common</artifactId>
 ? ?<version>3.1.2</version>
</dependency>

hbase-client

<!-- https://mvnrepository.com/artifact/org.apache.hbase/hbase-client -->
 ? ?<dependency>
 ? ? ?<groupId>org.apache.hbase</groupId>
 ? ? ?<artifactId>hbase-client</artifactId>
 ? ? ?<version>2.1.5</version>
 ? ?</dependency>

將所有查詢到的組件的XML插入到節(jié)點(diǎn)中去,如下圖:

pom.xml修改完畢后,點(diǎn)擊右下角的"Import Changes"即可將MAVEN庫中的JAR包下載到項(xiàng)目中,默認(rèn)情況下,會(huì)從MAVEN官網(wǎng)下載,速度比較慢;可事先配置MAVEN淘寶鏡像庫,基本方法就是在IntelliJ IDEA的安裝目錄下,找到MAVEN插件的安裝目錄,修改其配置文件,將鏡像設(shè)置添加到配置文件中即可

3、如果已經(jīng)創(chuàng)建過Student表,需要首先刪除

disable 'Student'
drop 'Student'

4、要求:
使用HBase Shell往Student表新增一行rowkey為index的數(shù)據(jù),列族/列為Base:Indexes,值為:001,002,004
編寫代碼獲取值:Student,rowkey,Base:Indexes
將獲取到的值按 , 切分為數(shù)組,遍歷數(shù)組,以數(shù)組中的值為rowkey獲取其對(duì)應(yīng)的姓名、學(xué)號(hào)、英語和Java成績,并print出來,print格式為:
Tim(001): 80 85
Lucy(002): 78 88
Golden(004): 80
注意:對(duì)一個(gè)表創(chuàng)建一次連接后,所有的get操作執(zhí)行完后,再close連接
注意:以下代碼中 節(jié)點(diǎn)名:2181需要替換為自己實(shí)際的節(jié)點(diǎn)主機(jī)名
并修改C:\Windows\System32\drivers\etc\hosts文件,添加對(duì)應(yīng)的映射即可,如:
主節(jié)點(diǎn)IP地址 主節(jié)點(diǎn)主機(jī)名
從節(jié)點(diǎn)1IP地址 從節(jié)點(diǎn)1主機(jī)名
從節(jié)點(diǎn)2IP地址 從節(jié)點(diǎn)2主機(jī)名
*若無權(quán)限修改,可將其拷貝到其他地方,修改了后再拷貝回來覆蓋

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class HBaseTest {
 ? ?static Configuration conf = HBaseConfiguration.create();
 ? ?static Connection conn;

 ? ?public static void main(String[] args){
 ? ? ? ?//創(chuàng)建HBase配置
 ? ? ? ?//conf.set("hbase.rootdir", "hdfs://node1:9000/hbase");
 ? ? ? ?conf.set("hbase.zookeeper.quorum", "Hadoop01:2181,Hadoop02:2181,Hadoop03:2181");
 ? ? ? ?//conf.set("hbase.zookeeper.property.clientPort", "2181");
 ? ? ? ?try {
 ? ? ? ? ? ?//創(chuàng)建HBase連接
 ? ? ? ? ? ?System.out.println("連接Hbase...");
 ? ? ? ? ? ?conn = ConnectionFactory.createConnection(conf);
 ? ? ? ? ? ?//創(chuàng)建表
 ? ? ? ? ? ?System.out.println("創(chuàng)建表");
 ? ? ? ? ? ?createTable("Student", new String[]{ "Base", "Score" });	//創(chuàng)建一個(gè)具備Base和Score兩個(gè)CollumnFamily(列族)的表Student
 ? ? ? ? ? ?//數(shù)據(jù)寫入例
 ? ? ? ? ? ?System.out.println("數(shù)據(jù)寫入");
 ? ? ? ? ? ?putSingleValue("Student", "001", "Base", "Number", "001");	//5個(gè)參數(shù)分別為:表名、RowKey、CollumnFamily、Collumn、Cell值
 ? ? ? ? ? ?putSingleValue("Student", "001", "Base", "Name", "Tim");
 ? ? ? ? ? ?putSingleValue("Student", "001", "Base", "Sex", "m");
 ? ? ? ? ? ?putSingleValue("Student", "001", "Base", "Prof", "bigdata");
 ? ? ? ? ? ?putSingleValue("Student", "001", "Score", "English", "50");
 ? ? ? ? ? ?putSingleValue("Student", "001", "Score", "Math", "72");
 ? ? ? ? ? ?putSingleValue("Student", "001", "Score", "Java", "85");
 ? ? ? ? ? ?putSingleValue("Student", "001", "Score", "Python", "75");
 ? ? ? ? ? ?putSingleValue("Student", "001", "Score", "BigData", "80");

 ? ? ? ? ? ?putSingleValue("Student", "002", "Base", "Number", "002");
 ? ? ? ? ? ?putSingleValue("Student", "002", "Base", "Name", "Lucy");
 ? ? ? ? ? ?putSingleValue("Student", "002", "Base", "Sex", "f");
 ? ? ? ? ? ?putSingleValue("Student", "002", "Base", "Prof", "bigdata");
 ? ? ? ? ? ?putSingleValue("Student", "002", "Score", "English", "78");
 ? ? ? ? ? ?putSingleValue("Student", "002", "Score", "Math", "68");
 ? ? ? ? ? ?putSingleValue("Student", "002", "Score", "Java", "58");
 ? ? ? ? ? ?putSingleValue("Student", "002", "Score", "Python", "80");
 ? ? ? ? ? ?putSingleValue("Student", "002", "Score", "BigData", "76");

 ? ? ? ? ? ?putSingleValue("Student", "003", "Base", "Number", "003");
 ? ? ? ? ? ?putSingleValue("Student", "003", "Base", "Name", "Vivian");
 ? ? ? ? ? ?putSingleValue("Student", "003", "Base", "Sex", "f");
 ? ? ? ? ? ?putSingleValue("Student", "003", "Base", "Prof", "biz");
 ? ? ? ? ? ?putSingleValue("Student", "003", "Score", "English", "82");
 ? ? ? ? ? ?putSingleValue("Student", "003", "Score", "Math", "70");
 ? ? ? ? ? ?putSingleValue("Student", "003", "Score", "Market", "70");

 ? ? ? ? ? ?putSingleValue("Student", "004", "Base", "Number", "004");
 ? ? ? ? ? ?putSingleValue("Student", "004", "Base", "Name", "Golden");
 ? ? ? ? ? ?putSingleValue("Student", "004", "Base", "Sex", "m");
 ? ? ? ? ? ?putSingleValue("Student", "004", "Base", "Prof", "biz");
 ? ? ? ? ? ?putSingleValue("Student", "004", "Score", "English", "80");
 ? ? ? ? ? ?putSingleValue("Student", "004", "Score", "Math", "57");
 ? ? ? ? ? ?putSingleValue("Student", "004", "Score", "Market", "68");

 ? ? ? ? ? ?System.out.println("寫入學(xué)生索引");
 ? ? ? ? ? ?putSingleValue("Student", "index", "Base", "Indexes", "001,002,004");
 ? ? ? ? ? ?//數(shù)據(jù)讀取例
 ? ? ? ? ? ?String value = getSingleValue("Student", "index", "Base", "Indexes");	//4個(gè)參數(shù)分別為:表名、RowKey、CollumnFamily、Collumn、Cell值
 ? ? ? ? ? ?String[] valsplit=value.split(",");
 ? ? ? ? ? ?String name,number,English,Java;
 ? ? ? ? ? ?List<String> lst=new ArrayList<String>();
 ? ? ? ? ? ?for (String rk : valsplit) {
 ? ? ? ? ? ? ? ?name=getSingleValue("Student",rk,"Base","Name");
 ? ? ? ? ? ? ? ?number=getSingleValue("Student",rk,"Base","Number");
 ? ? ? ? ? ? ? ?English=getSingleValue("Student",rk,"Score","English");
 ? ? ? ? ? ? ? ?Java=getSingleValue("Student",rk,"Score","Java");
 ? ? ? ? ? ? ? ?lst.add(name+"("+number+"): "+English+" ?"+Java); //把要求輸出的信息存入列表

 ? ? ? ? ? ?}
 ? ? ? ? ? ?System.out.println();
 ? ? ? ? ? ?System.out.println("打印出獲取到的姓名、學(xué)號(hào)、英語和Java成績");
 ? ? ? ? ? ?for (String info : lst) {
 ? ? ? ? ? ? ? ?System.out.println(info); //依次遍歷列表輸出要輸出的信息
 ? ? ? ? ? ?}
 ? ? ? ? ? ?conn.close();
 ? ? ? ? ? ?//String name = getSingleValue("Student", "001", "Base", "Name");		//獲取學(xué)號(hào)為001的學(xué)生姓名
 ? ? ? ?}
 ? ? ? ?catch(Exception e) {
 ? ? ? ? ? ?e.printStackTrace();
 ? ? ? ?}
 ? ?}

 ? ?//創(chuàng)建表
 ? ?public static void createTable(String table, String[] families) throws IOException {
 ? ? ? ?//構(gòu)造表名對(duì)象
 ? ? ? ?TableName tableName = TableName.valueOf(table);
 ? ? ? ?//獲取管理對(duì)象
 ? ? ? ?Admin admin = conn.getAdmin();
 ? ? ? ?//判斷表是否存在
 ? ? ? ?if(!admin.tableExists(tableName)) {
 ? ? ? ? ? ?//構(gòu)造表描述器器
 ? ? ? ? ? ?TableDescriptorBuilder tableDescipt = TableDescriptorBuilder.newBuilder(tableName);
 ? ? ? ? ? ?////////////////////////////////////////////////////////////////////////////////////////////
 ? ? ? ? ? ?for(String family : families){
 ? ? ? ? ? ? ? ?//構(gòu)造列族描述器
 ? ? ? ? ? ? ? ?ColumnFamilyDescriptorBuilder columnFamilyDescript = ?ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(family));
 ? ? ? ? ? ? ? ?//創(chuàng)建列描述器
 ? ? ? ? ? ? ? ?ColumnFamilyDescriptor columnFamily = columnFamilyDescript.build();
 ? ? ? ? ? ? ? ?//添加列族
 ? ? ? ? ? ? ? ?tableDescipt.setColumnFamily(columnFamily);
 ? ? ? ? ? ?}
 ? ? ? ? ? ?////////////////////////////////////////////////////////////////////////////////////////////
 ? ? ? ? ? ?//獲得表描述器
 ? ? ? ? ? ?TableDescriptor td = tableDescipt.build();
 ? ? ? ? ? ?//創(chuàng)建表
 ? ? ? ? ? ?admin.createTable(td);
 ? ? ? ?}else {
 ? ? ? ? ? ?System.out.println("表 " + tableName.getNameAsString() + " 已存在");
 ? ? ? ?}
 ? ?}

 ? ?//新增單條數(shù)據(jù)
 ? ?public static void putSingleValue(String tableStr, String rowKey, String columnFamily, String columnName, String cellValue) throws IOException{
 ? ? ? ?TableName tableName = TableName.valueOf(tableStr);
 ? ? ? ?Table table = conn.getTable(tableName);// Tabel負(fù)責(zé)跟記錄相關(guān)的操作如增刪改查等//
 ? ? ? ?Put put=new Put(Bytes.toBytes(rowKey));
 ? ? ? ?put.addColumn(Bytes.toBytes(columnFamily), Bytes.toBytes(columnName), Bytes.toBytes(cellValue));
 ? ? ? ?table.put(put);
 ? ? ? ?table.close();
 ? ? ? ?System.out.println("add data Success!");
 ? ?}

 ? ?//刪除單條數(shù)據(jù)
 ? ?public static void deleteSingleValue(String tableStr,String rowKey, String columnFamily, String columnName) throws IOException {
 ? ? ? ?TableName tableName = TableName.valueOf(tableStr);
 ? ? ? ?//創(chuàng)建表對(duì)象,實(shí)現(xiàn)表刪除
 ? ? ? ?Table table = conn.getTable(tableName);
 ? ? ? ?Delete delete = new Delete(Bytes.toBytes(rowKey)); ?//定義行
 ? ? ? ?//delete.addFamily(Bytes.toBytes(columnFamily)); ? ?//定義需要?jiǎng)h除的列族
 ? ? ? ?//delete.addColumn(Bytes.toBytes(columnFamily), Bytes.toBytes(columnName)); ? //定義需要?jiǎng)h除的列
 ? ? ? ?table.delete(delete);
 ? ? ? ?table.close();
 ? ?}

 ? ?//刪除表
 ? ?public static ?void deleteTable(String tableStr) throws IOException{
 ? ? ? ?TableName tableName = TableName.valueOf(tableStr);
 ? ? ? ?//創(chuàng)建管理對(duì)象并禁用表,刪除表前先禁用掉
 ? ? ? ?Admin admin = conn.getAdmin();
 ? ? ? ?admin.disableTable(tableName);
 ? ? ? ?admin.deleteTable(tableName);
 ? ?}

 ? ?//獲取單條數(shù)據(jù)
 ? ?public static String getSingleValue(String tableStr, String rowKey, String columnFamily, String columnName) throws IOException {
 ? ? ? ?TableName tableName = TableName.valueOf(tableStr);
 ? ? ? ?Table table = conn.getTable(tableName);
 ? ? ? ?Get get = new Get(Bytes.toBytes(rowKey));
 ? ? ? ?//get.addFamily(Bytes.toBytes(columnFamily));
 ? ? ? ?get.addColumn(Bytes.toBytes(columnFamily), Bytes.toBytes(columnName));
 ? ? ? ?//執(zhí)行數(shù)據(jù)讀取并返回結(jié)果對(duì)象
 ? ? ? ?Result set = table.get(get);
 ? ? ? ?//獲取一行數(shù)據(jù)集中的所有單元格(cell)對(duì)象
 ? ? ? ?Cell[] cells ?= set.rawCells();
 ? ? ? ?//遍歷所有單元格對(duì)象
 ? ? ? ?for(Cell cell : cells) {
 ? ? ? ? ? ?//System.out.println(Bytes.toString(cell.getRowArray()));
 ? ? ? ? ? ?//System.out.println(Bytes.toString(cell.getFamilyArray()));
 ? ? ? ? ? ?//System.out.println(Bytes.toString(cell.getQualifierArray()));
 ? ? ? ? ? ?//System.out.println(Bytes.toString(cell.getValueArray()));
 ? ? ? ? ? ?byte[] cellValue = cell.getValueArray();
 ? ? ? ? ? ?String row = Bytes.toString(cellValue, cell.getRowOffset(), cell.getRowLength());
 ? ? ? ? ? ?String family = Bytes.toString(cellValue, cell.getFamilyOffset(), cell.getFamilyLength());
 ? ? ? ? ? ?String column = Bytes.toString(cellValue, cell.getQualifierOffset(), cell.getQualifierLength());
 ? ? ? ? ? ?Long timestamp = cell.getTimestamp();
 ? ? ? ? ? ?String value = Bytes.toString(cellValue, cell.getValueOffset(), cell.getValueLength());
 ? ? ? ? ? ?System.out.println(String.format("%s:%s:%s:%d=%s",row, family, column, timestamp, value));
 ? ? ? ? ? ?return ?value;
 ? ? ? ?}
 ? ? ? ?table.close();
 ? ? ? ?return "";
 ? ?}
}

運(yùn)行代碼:成功創(chuàng)建表并插入數(shù)據(jù)

在hbase上通過命令查看Student表的信息:

五、啟動(dòng)hbase的常見異常
(1)錯(cuò)誤1:ERROR [main] regionserver.HRegionServer: Failed construction RegionServer java.lang.NoClassDefFoundError: org/apache/htrace/SamplerBuilder

把hbase-2.1.5/lib/client-facing-thirdparty目錄下的htrace-core-3.1.0-incubating.jar 復(fù)制到hbase-2.1.5/lib即可。

(2)錯(cuò)誤2:master.HMaster: Failed to become active master

conf/hbase-site.xml添加

hbase.unsafe.stream.capability.enforce
false

(3)警告:zookeeper.clientcnxn session 0X0 for server null attempting reconnect
zookeeper無法通信的警告,連續(xù)操過一定次數(shù)會(huì)造成zookeeper節(jié)點(diǎn)退出的錯(cuò)誤,最終導(dǎo)致HRegionServer失效
1、檢查節(jié)點(diǎn)防火墻有無關(guān)閉
2、conf/hbase-site.xml添加

hbase.zookeeper.quorum //Zookeeper的運(yùn)行節(jié)點(diǎn)
節(jié)點(diǎn)ip或主機(jī)名:2181(多個(gè)節(jié)點(diǎn)用逗號(hào)隔開)

為Zookeeper多添加幾個(gè)節(jié)點(diǎn)


HBase安裝配置和管理的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國家法律
桦川县| 丹凤县| 察雅县| 珲春市| 南宁市| 苗栗市| 宜州市| 积石山| 循化| 张北县| 从江县| 宜兴市| 秀山| 象山县| 茌平县| 平度市| 鄢陵县| 贵德县| 松滋市| 荥经县| 永顺县| 英德市| 河西区| 屯门区| 南江县| 海口市| 武威市| 宾阳县| 安丘市| 金乡县| 绥化市| 青神县| 临夏县| 盖州市| 阳西县| 淳安县| 新乐市| 渭南市| 沙洋县| 南岸区| 托克逊县|