1.安装hbase环境
(1)使用“tar -zxvfhbase-2.2.7-bin.tar.gz”命令解压安装包,得到hbase-2.2.7文件夹;
(2)使用“mv hbase-2.2.7 /usr/local/hbase2.2.7”命令修改安装路径,注意修改后的路径可以随意设置,笔者这里设置的是“/usr/local/ hbase2.2.7”;
(3)修改环境变量,使用“vi ~/.bashrc”编辑bashrc文件
export HBASE_HOME=/usr/local/hbase2.2.7
export PATH=$HBASE_HOME/bin:$PATH
(4)使用“source ~/.bashrc”命令,使环境变量更改生效;
(5)使用“cd $HBASE_HOME/conf”命令,进入HBase的conf目录;
(6)安装 java develope版,内部有jdk。
yum install java-1.8.0-openjdk-devel.x86_64
(7)编辑hbase-env.sh配置文件,做如下修改:
找到“#export JAVA_HOME=/usr/java/jdk1.8.0/”,去掉前面的#,并修改成自己的 JAVA_HOME路径,笔者修改后的结果是“export JAVA_HOME=/usr/local/java8.144”;
(8)在bin目录下使用“start-hbase.sh”命令启动HBase数据库
(9)修改etc/hosts
#127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
#::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.17.130 localdomain
192.168.17.130为本机地址
刷新hosts生效
/etc/init.d/network restart
(10)修改java程序运行的操作系统hosts(windows10)
(11)开启服务器,到hbase的bin目录下:
start-hbase.sh
(12)如果遇到情况,需要停止服务器运行:
停掉集群:hbase-daemon.sh stop master
停掉服务器:stop-hbase.sh
(13)测试服务器访问:
windows10浏览器中输入:http://localdomain:16010/
2.Java访问单机版Hbase
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.soft</groupId>
<artifactId>hbaseDemo</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.aliyun.hbase/alihbase-client -->
<!-- https://mvnrepository.com/artifact/com.aliyun.hbase/alihbase-client -->
<dependency>
<groupId>com.aliyun.hbase</groupId>
<artifactId>alihbase-client</artifactId>
<version>1.8.0</version>
</dependency>
</dependencies>
</project>
MyTest.java
package com.soft;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
public static void main(String[] args) throws Exception {
String createTableName = "mytable2";
Configuration configuration = HBaseConfiguration.create();;
configuration.set("hbase.zookeeper.quorum", "localdomain");
//configuration.set("hbase.master", "10.10.2.66:600000");
System.out.println("start create table ......");
conn = ConnectionFactory.createConnection(configuration);
System.out.println(" conn = ConnectionFactory.createConnection(configuration);");
try {
Admin admin = conn.getAdmin();
System.out.println(" Admin admin = conn.getAdmin();");
HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf(createTableName));
tableDescriptor.addFamily(new HColumnDescriptor("column1"));
tableDescriptor.addFamily(new HColumnDescriptor("column2"));
tableDescriptor.addFamily(new HColumnDescriptor("column3"));
admin.createTable(tableDescriptor);
System.out.println(" admin.createTable(tableDescriptor);");
admin.close();
} catch (MasterNotRunningException e) {
e.printStackTrace();
} catch (ZooKeeperConnectionException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("end create table ......");
}
日志:
"C:\Program Files\Java\jdk1.8.0_181\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.1.1\lib\idea_rt.jar=52534:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.1.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_181\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\rt.jar;L:\Study\Project\hbaseDemo\target\classes;D:\java\repository\com\aliyun\hbase\alihbase-client\1.8.0\alihbase-client-1.8.0.jar;D:\java\repository\com\aliyun\hbase\alihbase-annotations\1.8.0\alihbase-annotations-1.8.0.jar;D:\java\repository\com\github\stephenc\findbugs\findbugs-annotations\1.3.9-1\findbugs-annotations-1.3.9-1.jar;D:\java\repository\log4j\log4j\1.2.17\log4j-1.2.17.jar;D:\java\repository\com\aliyun\hbase\alihbase-common\1.8.0\alihbase-common-1.8.0.jar;D:\java\repository\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;D:\java\repository\org\mortbay\jetty\jetty-util\6.1.26\jetty-util-6.1.26.jar;D:\java\repository\com\aliyun\hbase\alihbase-protocol\1.8.0\alihbase-protocol-1.8.0.jar;D:\java\repository\com\alibaba\hbase\alihbase-connector\1.0.17\alihbase-connector-1.0.17.jar;D:\java\repository\org\apache\hbase\thirdparty\hbase-shaded-miscellaneous\2.1.0\hbase-shaded-miscellaneous-2.1.0.jar;D:\java\repository\com\yammer\metrics\metrics-core\2.2.0\metrics-core-2.2.0.jar;D:\java\repository\org\apache\thrift\libthrift\0.12.0\libthrift-0.12.0.jar;D:\java\repository\org\apache\httpcomponents\httpcore\4.4.1\httpcore-4.4.1.jar;D:\java\repository\org\apache\httpcomponents\httpclient\4.5.2\httpclient-4.5.2.jar;D:\java\repository\com\alibaba\fastjson\1.2.61\fastjson-1.2.61.jar;D:\java\repository\commons-codec\commons-codec\1.9\commons-codec-1.9.jar;D:\java\repository\commons-io\commons-io\2.4\commons-io-2.4.jar;D:\java\repository\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;D:\java\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;D:\java\repository\com\google\guava\guava\12.0.1\guava-12.0.1.jar;D:\java\repository\com\google\protobuf\protobuf-java\2.5.0\protobuf-java-2.5.0.jar;D:\java\repository\io\netty\netty-all\4.0.23.Final\netty-all-4.0.23.Final.jar;D:\java\repository\org\apache\zookeeper\zookeeper\3.4.6\zookeeper-3.4.6.jar;D:\java\repository\org\slf4j\slf4j-api\1.6.1\slf4j-api-1.6.1.jar;D:\java\repository\org\slf4j\slf4j-log4j12\1.6.1\slf4j-log4j12-1.6.1.jar;D:\java\repository\org\apache\htrace\htrace-core\3.1.0-incubating\htrace-core-3.1.0-incubating.jar;D:\java\repository\org\codehaus\jackson\jackson-mapper-asl\1.9.13\jackson-mapper-asl-1.9.13.jar;D:\java\repository\org\codehaus\jackson\jackson-core-asl\1.9.13\jackson-core-asl-1.9.13.jar;D:\java\repository\org\jruby\jcodings\jcodings\1.0.8\jcodings-1.0.8.jar;D:\java\repository\org\jruby\joni\joni\2.1.2\joni-2.1.2.jar;D:\java\repository\org\apache\hadoop\hadoop-auth\2.5.1\hadoop-auth-2.5.1.jar;D:\java\repository\org\apache\directory\server\apacheds-kerberos-codec\2.0.0-M15\apacheds-kerberos-codec-2.0.0-M15.jar;D:\java\repository\org\apache\directory\server\apacheds-i18n\2.0.0-M15\apacheds-i18n-2.0.0-M15.jar;D:\java\repository\org\apache\directory\api\api-asn1-api\1.0.0-M20\api-asn1-api-1.0.0-M20.jar;D:\java\repository\org\apache\directory\api\api-util\1.0.0-M20\api-util-1.0.0-M20.jar;D:\java\repository\org\apache\hadoop\hadoop-common\2.5.1\hadoop-common-2.5.1.jar;D:\java\repository\org\apache\hadoop\hadoop-annotations\2.5.1\hadoop-annotations-2.5.1.jar;C:\Program Files\Java\jdk1.8.0_181\lib\tools.jar;D:\java\repository\commons-cli\commons-cli\1.2\commons-cli-1.2.jar;D:\java\repository\org\apache\commons\commons-math3\3.1.1\commons-math3-3.1.1.jar;D:\java\repository\xmlenc\xmlenc\0.52\xmlenc-0.52.jar;D:\java\repository\commons-httpclient\commons-httpclient\3.1\commons-httpclient-3.1.jar;D:\java\repository\commons-net\commons-net\3.1\commons-net-3.1.jar;D:\java\repository\commons-el\commons-el\1.0\commons-el-1.0.jar;D:\java\repository\commons-configuration\commons-configuration\1.6\commons-configuration-1.6.jar;D:\java\repository\commons-digester\commons-digester\1.8\commons-digester-1.8.jar;D:\java\repository\commons-beanutils\commons-beanutils\1.7.0\commons-beanutils-1.7.0.jar;D:\java\repository\commons-beanutils\commons-beanutils-core\1.8.0\commons-beanutils-core-1.8.0.jar;D:\java\repository\org\apache\avro\avro\1.7.4\avro-1.7.4.jar;D:\java\repository\com\thoughtworks\paranamer\paranamer\2.3\paranamer-2.3.jar;D:\java\repository\org\xerial\snappy\snappy-java\1.0.4.1\snappy-java-1.0.4.1.jar;D:\java\repository\com\jcraft\jsch\0.1.42\jsch-0.1.42.jar;D:\java\repository\com\google\code\findbugs\jsr305\1.3.9\jsr305-1.3.9.jar;D:\java\repository\org\apache\commons\commons-compress\1.4.1\commons-compress-1.4.1.jar;D:\java\repository\org\tukaani\xz\1.0\xz-1.0.jar;D:\java\repository\org\apache\hadoop\hadoop-mapreduce-client-core\2.5.1\hadoop-mapreduce-client-core-2.5.1.jar;D:\java\repository\org\apache\hadoop\hadoop-yarn-common\2.5.1\hadoop-yarn-common-2.5.1.jar;D:\java\repository\org\apache\hadoop\hadoop-yarn-api\2.5.1\hadoop-yarn-api-2.5.1.jar;D:\java\repository\javax\xml\bind\jaxb-api\2.2.2\jaxb-api-2.2.2.jar;D:\java\repository\javax\xml\stream\stax-api\1.0-2\stax-api-1.0-2.jar;D:\java\repository\javax\activation\activation\1.1\activation-1.1.jar;D:\java\repository\io\netty\netty\3.6.2.Final\netty-3.6.2.Final.jar;D:\java\repository\junit\junit\4.12\junit-4.12.jar;D:\java\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar" com.soft.MyTest
start create table ......
log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
conn = ConnectionFactory.createConnection(configuration);
Admin admin = conn.getAdmin();
admin.createTable(tableDescriptor);
end create table ......
Process finished with exit code 0
回到hbase shell命令: