我遇到了关于通过HBase v1.0客户端API获取数据的问题。
以下是我的HBase和自定义Zookeeper设置:
HMaster主持人:
172.17.0.2 master
127.0.0.1 localhost
192.168.1.32 master2
HBase的-site.xml中:
<configuration>
<property>
<name>hbase.rootdir</name>
<value>hdfs://master:9000/hbase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.zookeeper.property.clientPort</name>
<value>2181</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/home/hduser/zookeeper/data</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>master</value>
</property>
<property>
<name>dfs.support.append</name>
<value>true</value>
</property>
</configuration>
zoo.cfg :
dataDir=/home/hduser/zookeeper/data
clientPort=2181
server.1=master:2888:3888
运行我的客户端代码连接到zookeeper后,看起来此连接成功。
2015-04-09 08:51:37,901 [myid:] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@197] - Accepted socket connection from /192.168.1.30:56295
2015-04-09 08:51:37,906 [myid:] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@868] - Client attempting to establish new session at /192.168.1.30:56295
2015-04-09 08:51:37,939 [myid:] - INFO [SyncThread:0:ZooKeeperServer@617] - Established session 0x14c9d46501d000b with negotiated timeout 40000 for client /192.168.1.30:56295
2015-04-09 08:52:04,000 [myid:] - INFO [SessionTracker:ZooKeeperServer@347] - Expiring session 0x14c9d46501d000a, timeout of 40000ms exceeded
2015-04-09 08:52:04,000 [myid:] - INFO [ProcessThread(sid:0 cport:-1)::PrepRequestProcessor@494] - Processed session termination for sessionid: 0x14c9d46501d000a
但是,当我尝试将数据放入表格时,我在zookeeper.out
在这种情况下可能出现的问题是什么?
以下代码是我尝试通过scala连接到HBase的代码
main.scala :
object Main {
def main(args: Array[String]): Unit = {
val con = new HBaseUtils().getConnection
try {
val table = con.getTable(TableName.valueOf("TimeIndexTable"))
val put = new Put(Bytes.toBytes("r2")).addColumn(Bytes.toBytes("post_info"), Bytes.toBytes("abc"), Bytes.toBytes("value"))
table.put(put)
println("Success")
}
catch {
case e: Exception => e.printStackTrace()
}
finally {
con.close()
}
}
}
HBaseUtils.scala :
class HBaseUtils {
private val hbaseURL = "192.168.1.31"
def getConnection = ConnectionFactory.createConnection(setConf)
def setConf = {
val config = HBaseConfiguration.create()
config.set("hbase.zookeeper.quorum",hbaseURL)
config
}
}