1.测试hbase:
a)cd hbase-0.90.4
b)bin/start-hbase.sh
c)bin/hbase shell
d)create ‘database’,’cf’
e)list
f) 如果成功则可以看到有下面的结果:
hbase(main):001:0>list TABLE database1 row(s)in 0.5910 seconds
2. 创建Java project, 将hbase-0.90.4下面的lib目录拷贝到工程,将其中的jar包加入classpath, 还有hbase-0.90.5.jar 和 test.jar
3. 创建类
public class HelloHBase {
public static void main(String[] args) throws IOException {
Configuration conf = HBaseConfiguration.create()
conf.set("hbase.zookeeper.quorum", "192.168.128.128")
HBaseAdmin admin = new HBaseAdmin(conf)
HTableDescriptor tableDescriptor = admin.getTableDescriptor(Bytes.toBytes("database"))
byte[] name = tableDescriptor.getName()
System.out.println(new String(name))
HColumnDescriptor[] columnFamilies = tableDescriptor.getColumnFamilies()
for (HColumnDescriptor d : columnFamilies) {
System.out.println(d.getNameAsString())
}
}
运行,此时应该打印出下面两行:
database cf
若没有,说明配置失败,请检查其他设置。
==============================================
问题1:
java.net.ConnectException: Connection refused: no further information
a. zookeeper.ClientCnxn: Session 0x0 for server null,
解决: zppkeeper未启动,或无法连接,从查看各节点zookeeper启动状态、端口占用、防火墙等方面查看原因
b. getMaster attempt 4 of 10 failedretrying after sleep of 2000
解决:查看 master log , 如果有信息org.apache.hadoop.hbase.regionserver.HRegionServer: Serving as BRDVM0240,43992,1373943529301, RPC listening on /127.0.0.1:43992, sessionid=0x13fe56a7d4b0001
则说明, HRegionServer
监听的端口是localhost 127.0.0.1, 需要修改 server端 /etc/hosts 文件, 127.0.0.1
servername localhost.localdomain localhost
去掉 servername, 然后重启hbase
第二种情况:
java.net.ConnectException: Connection refused: no further information
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1119)
12/09/03 15:37:15 INFO zookeeper.ClientCnxn: Opening socket connection to server /192.168.0.118:2181
12/09/03 15:37:16 INFO zookeeper.ClientCnxn: EventThread shut down
12/09/03 15:37:16 INFO zookeeper.ZooKeeper: Session: 0x0 closed
Exception in thread "main" org.apache.hadoop.hbase.ZooKeeperConnectionException: HBase is able to connect to ZooKeeper but the connection closes immediately. This could be a sign that the server has too many connections (30 is the default). Consider inspecting your ZK server logs for that error and then make sure you are reusing HBaseConfiguration as often as you can. See HTable's javadoc for more information.
at org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher.<init>(ZooKeeperWatcher.java:156)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getZooKeeperWatcher(HConnectionManager.java:1209)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.setupZookeeperTrackers(HConnectionManager.java:511)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.<init>(HConnectionManager.java:502)
at org.apache.hadoop.hbase.client.HConnectionManager.getConnection(HConnectionManager.java:172)
at org.apache.hadoop.hbase.client.HBaseAdmin.<init>(HBaseAdmin.java:92)
at com.biencloud.test.first_hbase.main(first_hbase.java:22)
Caused by: org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /hbase
at org.apache.zookeeper.KeeperException.create(KeeperException.java:90)
at org.apache.zookeeper.KeeperException.create(KeeperException.java:42)
at org.apache.zookeeper.ZooKeeper.exists(ZooKeeper.java:809)
at org.apache.zookeeper.ZooKeeper.exists(ZooKeeper.java:837)
at org.apache.hadoop.hbase.zookeeper.ZKUtil.createAndFailSilent(ZKUtil.java:931)
at org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher.<init>(ZooKeeperWatcher.java:134)
... 6 more
这个错误说明eclipse没有连接到zookeeper,在程序中添加zookeeper配置信息即可,具体如下:
Configuration conf=HBaseConfiguration.create()
conf.set("hbase.zookeeper.quorum","192.168.0.118, 192.168.0.186, 192.168.0.182")
conf.set("hbase.zookeeper.property.clientPort","2222")
附上出处链接:http://www.aboutyun.com/thread-5866-1-1.html
猜测您想问的是hbase无法创建数据库,什么原因?没有配置host映射,java找不到对应虚拟机。参考博客网站提供的资料显示hbase无法创建数据库原因是没有配置host映射,java找不到对应虚拟机,可以通过添加虚拟机ip地址、加虚拟机名进行解决。
HBase是一个分布式的、面向列的开源数据库。
先查看原节点间间致导致修改各结点间使其误差30s内或hbase-site.xml添加配置hbase.master.maxclockskew
180000
Time difference of regionserver from master
要配置服务器间同步需要用ntp能连接外网间服务器内网手改间再启
另外原
看看master否等于localhost master能等于localhost
集群每主机主机名修改regionservers文件应主机名问题解决
主机名修改
vi /etc/sysconfig/networks
HOSTNAME=主机名
重启network服务设置效
service network restart
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)