Created on 09-19-2013 11:46 PM - edited 09-16-2022 01:48 AM
Hello,
I am trying to connect my HBase with JAVA Application for creation, insertion, deletion data into hbase table. I have installed Cloudera Standard Verion with 7 hosts named as shown below:
Server Cloudera-new
Host1 Cluster1
Host2 Cluster2
Host3 Cluster3
Host4 Cluster4
Host5 Cluster5
Host6 Cluster6
Host7 Cluster7
Here is my etc/hosts file:
192.168.3.100 Cloudera-new Cloudera-new
192.168.3.101 Cluster1 Cluster1
192.168.3.102 Cluster2 Cluster2
192.168.3.103 Cluster3 Cluster3
192.168.3.104 Cluster4 Cluster4
192.168.3.105 Cluster5 Cluster5
192.168.3.106 Cluster6 Cluster6
192.168.3.107 Cluster7 Cluster7
All services are started on Cluster1 rest all hosts have some services started not all. Now I want to connect hbase Master running on Cluster 1 with JAVA Application. Here is my program:
package Hive;
import java.sql.SQLException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HBaseAdmin;
public class hbasecommand {
private static String driverName = "org.apache.hadoop.hbase.HBaseConfiguration";
public static void main(String[] args) throws SQLException {
try {
Class.forName(driverName);
}
catch (ClassNotFoundException e) {
e.printStackTrace();
System.exit(1);
}
System.out.println("Running connecting test...");
System.out.println(" 1. From program: Hello from MySimpleHBase");
System.out.println(" 2. From program: Create a HBase config");
Configuration config = HBaseConfiguration.create();
config.set("hbase.master", "192.168.3.101:60000");
config.set("hbase.zookeeper.quorum", "192.168.3.101");
config.set("hbase.zookeeper.property.clientPort", "2181");
try {
String tableName = "hbase_table";
System.out.println("Enetered");
System.out.println(tableName);
HBaseAdmin admin = new HBaseAdmin(config);
System.out.println("===========Delete table========");
admin.disableTable(tableName);
admin.deleteTable(tableName);
System.out.println("delete table " + tableName + " ok.");
} catch (Exception e) {
e.printStackTrace();
}
}
}
When i run this program error occur:
Running connecting test...
1. From program: Hello from MySimpleHBase
2. From program: Create a HBase config
Enetered
hbase_table
13/09/20 11:21:38 INFO zookeeper.ZooKeeper: Client environment:zookeeper.version=3.4.5-cdh4.3.0--1, built on 05/28/2013 02:01 GMT
13/09/20 11:21:38 INFO zookeeper.ZooKeeper: Client environment:host.name=RSPL-NDA-005
13/09/20 11:21:38 INFO zookeeper.ZooKeeper: Client environment:java.version=1.7.0_03
13/09/20 11:21:38 INFO zookeeper.ZooKeeper: Client environment:java.vendor=Oracle Corporation
13/09/20 11:21:38 INFO zookeeper.ZooKeeper: Client environment:java.home=C:\Program Files\Java\jre7
13/09/20 11:21:38 INFO zookeeper.ZooKeeper: Client environment:java.class.path=C:\Users\Surbhi Singh\workspace\HiveTesting\bin;C:\Users\Surbhi Singh\Desktop\hive\commons-logging-1.0.4.jar;C:\Users\Surbhi Singh\Desktop\hive\commons-logging-api-1.0.4.jar;C:\Users\Surbhi Singh\Desktop\hive\guava-11.0.2.jar;C:\Users\Surbhi Singh\Desktop\hive\hadoop-core.jar;C:\Users\Surbhi Singh\Desktop\hive\hbase.jar;C:\Users\Surbhi Singh\Desktop\hive\hive-contrib-0.10.0-cdh4.3.0.jar;C:\Users\Surbhi Singh\Desktop\hive\hive-exec-0.10.0-cdh4.3.1.jar;C:\Users\Surbhi Singh\Desktop\hive\hive-hbase-handler-0.10.0-cdh4.3.0.jar;C:\Users\Surbhi Singh\Desktop\hive\hive-jdbc-0.10.0-cdh4.3.1.jar;C:\Users\Surbhi Singh\Desktop\hive\hive-metastore-0.10.0-cdh4.3.1.jar;C:\Users\Surbhi Singh\Desktop\hive\hive-service-0.10.0-cdh4.3.1.jar;C:\Users\Surbhi Singh\Desktop\hive\libfb303-0.9.0.jar;C:\Users\Surbhi Singh\Desktop\hive\libthrift-0.9.0-cdh4-1.jar;C:\Users\Surbhi Singh\Desktop\hive\log4j-1.2.16.jar;C:\Users\Surbhi Singh\Desktop\hive\mysql-connector-java.jar;C:\Users\Surbhi Singh\Desktop\hive\mysql-connector-java-5.1.25-bin.jar;C:\Users\Surbhi Singh\Desktop\hive\slf4j-api-1.6.1.jar;C:\Users\Surbhi Singh\Desktop\hive\slf4j-log4j12-1.6.1.jar;C:\Users\Surbhi Singh\Desktop\hive\zookeeper.jar;C:\Users\Surbhi Singh\Desktop\hive\commons-lang-2.4.jar;C:\Users\Surbhi Singh\Desktop\hive\commons-configuration-1.6.jar;C:\Users\Surbhi Singh\Desktop\hive\hadoop-common.jar
13/09/20 11:21:38 INFO zookeeper.ZooKeeper: Client environment:java.library.path=C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre7/bin/client;C:/Program Files/Java/jre7/bin;C:/Program Files/Java/jre7/lib/i386;C:\csvn\bin\;C:\csvn\Python25\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;C:\xampp\mysql\bin;;E:\Setup\eclipse;;.
13/09/20 11:21:38 INFO zookeeper.ZooKeeper: Client environment:java.io.tmpdir=C:\Users\SURBHI~1\AppData\Local\Temp\
13/09/20 11:21:38 INFO zookeeper.ZooKeeper: Client environment:java.compiler=<NA>
13/09/20 11:21:38 INFO zookeeper.ZooKeeper: Client environment:os.name=Windows 7
13/09/20 11:21:38 INFO zookeeper.ZooKeeper: Client environment:os.arch=x86
13/09/20 11:21:38 INFO zookeeper.ZooKeeper: Client environment:os.version=6.1
13/09/20 11:21:38 INFO zookeeper.ZooKeeper: Client environment:user.name=Surbhi Singh
13/09/20 11:21:38 INFO zookeeper.ZooKeeper: Client environment:user.home=C:\Users\Surbhi Singh
13/09/20 11:21:38 INFO zookeeper.ZooKeeper: Client environment:user.dir=C:\Users\Surbhi Singh\workspace\HiveTesting
13/09/20 11:21:38 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=192.168.3.101:2181 sessionTimeout=180000 watcher=hconnection
13/09/20 11:21:38 INFO zookeeper.RecoverableZooKeeper: The identifier of this process is 8136@RSPL-NDA-005
13/09/20 11:21:42 INFO zookeeper.ClientCnxn: Opening socket connection to server 192.168.3.101/192.168.3.101:2181. Will not attempt to authenticate using SASL (unknown error)
13/09/20 11:21:42 INFO zookeeper.ClientCnxn: Socket connection established to 192.168.3.101/192.168.3.101:2181, initiating session
13/09/20 11:21:42 INFO zookeeper.ClientCnxn: Session establishment complete on server 192.168.3.101/192.168.3.101:2181, sessionid = 0x1413531a8eb0a86, negotiated timeout = 60000
13/09/20 11:21:45 INFO client.HConnectionManager$HConnectionImplementation: getMaster attempt 0 of 10 failed; retrying after sleep of 1004
java.net.UnknownHostException: unknown host: Cluster1
at org.apache.hadoop.hbase.ipc.HBaseClient$Connection.<init>(HBaseClient.java:276)
at org.apache.hadoop.hbase.ipc.HBaseClient.createConnection(HBaseClient.java:255)
at org.apache.hadoop.hbase.ipc.HBaseClient.getConnection(HBaseClient.java:1111)
at org.apache.hadoop.hbase.ipc.HBaseClient.call(HBaseClient.java:974)
at org.apache.hadoop.hbase.ipc.WritableRpcEngine$Invoker.invoke(WritableRpcEngine.java:86)
at $Proxy5.getProtocolVersion(Unknown Source)
at org.apache.hadoop.hbase.ipc.WritableRpcEngine.getProxy(WritableRpcEngine.java:138)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getMaster(HConnectionManager.java:711)
at org.apache.hadoop.hbase.client.HBaseAdmin.<init>(HBaseAdmin.java:126)
at Hive.hbasecommand.main(hbasecommand.java:33)
13/09/20 11:21:46 INFO client.HConnectionManager$HConnectionImplementation: getMaster attempt 1 of 10 failed; retrying after sleep of 1000
java.net.UnknownHostException: unknown host: Cluster1
at org.apache.hadoop.hbase.ipc.HBaseClient$Connection.<init>(HBaseClient.java:276)
at org.apache.hadoop.hbase.ipc.HBaseClient.createConnection(HBaseClient.java:255)
at org.apache.hadoop.hbase.ipc.HBaseClient.getConnection(HBaseClient.java:1111)
at org.apache.hadoop.hbase.ipc.HBaseClient.call(HBaseClient.java:974)
at org.apache.hadoop.hbase.ipc.WritableRpcEngine$Invoker.invoke(WritableRpcEngine.java:86)
at $Proxy5.getProtocolVersion(Unknown Source)
at org.apache.hadoop.hbase.ipc.WritableRpcEngine.getProxy(WritableRpcEngine.java:138)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getMaster(HConnectionManager.java:711)
at org.apache.hadoop.hbase.client.HBaseAdmin.<init>(HBaseAdmin.java:126)
at Hive.hbasecommand.main(hbasecommand.java:33)
13/09/20 11:21:47 INFO client.HConnectionManager$HConnectionImplementation: getMaster attempt 2 of 10 failed; retrying after sleep of 1002
java.net.UnknownHostException: unknown host: Cluster1
at org.apache.hadoop.hbase.ipc.HBaseClient$Connection.<init>(HBaseClient.java:276)
at org.apache.hadoop.hbase.ipc.HBaseClient.createConnection(HBaseClient.java:255)
at org.apache.hadoop.hbase.ipc.HBaseClient.getConnection(HBaseClient.java:1111)
at org.apache.hadoop.hbase.ipc.HBaseClient.call(HBaseClient.java:974)
at org.apache.hadoop.hbase.ipc.WritableRpcEngine$Invoker.invoke(WritableRpcEngine.java:86)
at $Proxy5.getProtocolVersion(Unknown Source)
at org.apache.hadoop.hbase.ipc.WritableRpcEngine.getProxy(WritableRpcEngine.java:138)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getMaster(HConnectionManager.java:711)
at org.apache.hadoop.hbase.client.HBaseAdmin.<init>(HBaseAdmin.java:126)
at Hive.hbasecommand.main(hbasecommand.java:33)
I can't understand why this error unknown host came. Please help me by providing solution as soon as possible.
Thnaks
Surbhi Singh
Created 10-08-2013 11:22 AM
OK, I see that you are running under Windows, so that may be part of the issue. There is a hosts file in Control Panel->Administration somewhere that needs to have all the cluster hosts info (IP/hostname) in it. /etc/hosts is not applicable on Windows, unless that changed in recent versions.
The basic point is that all the hosts in the cluster need to be able to ping each other by hostname and IP, so just double-check that they are all able to do that. You client server (wherever you are running the app from) needs to also be able to resolve all the IPs and hostnames of the cluster machines.
Created 10-08-2013 11:22 AM
OK, I see that you are running under Windows, so that may be part of the issue. There is a hosts file in Control Panel->Administration somewhere that needs to have all the cluster hosts info (IP/hostname) in it. /etc/hosts is not applicable on Windows, unless that changed in recent versions.
The basic point is that all the hosts in the cluster need to be able to ping each other by hostname and IP, so just double-check that they are all able to do that. You client server (wherever you are running the app from) needs to also be able to resolve all the IPs and hostnames of the cluster machines.
Created 10-28-2013 12:41 AM
Hey Thanks for your reply.
It Works for both Centos as well as for Windows.
I have added all hosts IP's & their name in etc/hosts file.
In Windows hosts file is located at C:\Windows\System32\drivers\etc\hosts.
In Centos type vi /etc/hosts to access hosts file.
Thank U so much for helping me to solve out this problem.
Surbhi Singh
Created 09-15-2016 05:50 AM
hi ....... i am runnnig cloudera sandbox on Vmware . i want to connect from wiindow using java program want to create table in hbase.
Created 04-07-2014 12:53 PM
I used the same code as above but getting the below error.
exception=org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /hbase
I am connecting to a cdh cluster and to hbase master.I am running 5 zoo keeper instances.What would be my zoo keeper qourum in this case?