前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住给大家分享一下。点击跳转到网站:https://www.captainai.net/dongkelun
前言
记录一下Java API 连接 Hbase的代码,并记录遇到的异常及解决办法
代码
首先pom.xml里添加hbase-client依赖:
1 | <dependency> |
然后将hbase-site.xml,core-site.xml复制到本地(如果实在本地运行的话)
1 | package com.dkl.blog.hbase; |
异常及解决
java.net.ConnectException: Connection refused: no further information
1 | java.net.ConnectException: Connection refused: no further information |
解决方法:
1、
添加里添加
1 | config.set("hbase.zookeeper.quorum", "192.168.44.128"); //官网代码里没有这行 |
2、程序里用到的hbase-site.xml里添加 (如果hbase-site.xml没有下面的配置,我单机配置时没有添加)
1 | <property> |
Call to localhost/127.0.0.1:16201 failed on connection exception
1 | java.net.SocketTimeoutException: callTimeout=60000, callDuration=62839: Call to localhost/127.0.0.1:16201 failed on connection exception |
没有设置host 和 hostname
验证:
1 | netstat -nautlp|grep 16201 |
修改:
1 | vim /etc/hosts |
1 | 192.168.44.128 master |
1 | vim /etc/hostname |
1 | master |
然后重启hbase和程序,验证
1 | netstat -nautlp|grep 16201 |
java.net.SocketTimeoutException: callTimeout=60000, callDuration=79924: can not resolve master,16201,1597395570081
这个是本地运行程序且没有配置本地host时产生的,解决方法为编辑C:\Windows\System32\drivers\etc\hosts,添加
1 | 192.168.44.128 master |