Hbase版本:hbase-0.98.17-hadoop2/
Windows Eclipse 配置
1. 新建maven工程,添加maven依赖
<dependencies>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>0.98.17-hadoop2</version>
</dependency>
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<version>1.7</version>
<scope>system</scope>
<systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
</build>
3. 将hbase配置文件hbase-site.xml添加到上一步新建的Class Folder中
若不添加hbase-site配置文件至Class Folder中,也可在代码中添加
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.property.clientPort", "2181");
conf.set("hbase.zookeeper.quorum", "192.168.1.101");
调用静态create()方法时,代码会尝试使用当前的Java classpath来加载hbase-default.xml和hbase-site.xml两个配置文件。
当然在HTable使用之前,用户也可以修改配置,因此没有没有添加hbase-site.xml至classpath中,也可在代码中添加集群信息。
4. Windows环境下本地新建Hadoop Home
Main函数添加Hadoop Home
public static void main(String[] args) throws Exception {
System.setProperty("hadoop.home.dir", "d:\\hadoop_home");
......
}
Linux Hbase 设置
~/hbase-0.98.17-hadoop2/conf$ regionservers 设置IP
vi /etc/hosts 将IP与hosts关联
常见报错
•
java.io.IOException: Could notlocate executable D:\hadoop_home\bin\winutils.exe in the Hadoop binaries.
解决:
本地没有设置hadoop home,见上文
•
org.apache.hadoop.ipc.RpcClient]- IPC Client (143695640) connection to hbase01/192.168.1.101:60020 from user1:closing ipc connection to hbase01/192.168.1.101:60020: Connection refused: nofurther information
java.net.ConnectException: Connection refused: no further information
解决:
60020为regionserver端口号,regionserver拒绝连接
/ect/hosts将局域网IP与主机名关联,取消127.0.0.1与主机名的关联
Hbas econf/regionservers 设置局域网IP,非127.0.0.1