以下是在hbase中输入数据的代码:
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;
public class SimpleDataEntry {
public static void main(String[] args) throws IOException {
// Instantiating Configuration class
Configuration config = HBaseConfiguration.create();
// Instantiating HTable class
HTable hTable = new HTable(config, "emp");
// Instantiating Put class
// accepts a row name.
Put p = new Put(Bytes.toBytes("row1"));
// adding values using add() method
// accepts column family name, qualifier/row name ,value
p.add(Bytes.toBytes("personal"),
Bytes.toBytes("name"),Bytes.toBytes("raju"));
p.add(Bytes.toBytes("personal"),
Bytes.toBytes("city"),Bytes.toBytes("hyderabad"));
p.add(Bytes.toBytes("professional"),Bytes.toBytes("designation"),
Bytes.toBytes("manager"));
p.add(Bytes.toBytes("professional"),Bytes.toBytes("salary"),
Bytes.toBytes("50000"));
// Saving the put Instance to the HTable.
hTable.put(p);
System.out.println("data inserted");
// closing HTable
hTable.close();
}
}
运行此代码时出现的错误是:
16/04/24 14:07:58 INFO zookeeper.ZooKeeper: Client environment:java.library.path=/home/hadoop1/hadoop1/lib/native
16/04/24 14:07:58 INFO zookeeper.ZooKeeper: Client environment:java.io.tmpdir=/tmp
16/04/24 14:07:58 INFO zookeeper.ZooKeeper: Client environment:java.compiler=<NA>
16/04/24 14:07:58 INFO zookeeper.ZooKeeper: Client environment:os.name=Linux
16/04/24 14:07:58 INFO zookeeper.ZooKeeper: Client environment:os.arch=amd64
16/04/24 14:07:58 INFO zookeeper.ZooKeeper: Client environment:os.version=3.10.0-123.el7.x86_64
16/04/24 14:07:58 INFO zookeeper.ZooKeeper: Client environment:user.name=hadoop1
16/04/24 14:07:58 INFO zookeeper.ZooKeeper: Client environment:user.home=/home/hadoop1
16/04/24 14:07:58 INFO zookeeper.ZooKeeper: Client environment:user.dir=/home/hadoop1
16/04/24 14:07:58 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=localhost:2181 sessionTimeout=90000 watcher=hconnection-0x5542c4ed0x0, quorum=localhost:2181, baseZNode=/hbase
16/04/24 14:07:58 INFO zookeeper.ClientCnxn: Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
16/04/24 14:07:58 WARN zookeeper.ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1081)
16/04/24 14:07:58 WARN zookeeper.RecoverableZooKeeper: Possibly transient ZooKeeper, quorum=localhost:2181, exception=org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /hbase/hbaseid
16/04/24 14:07:59 INFO zookeeper.ClientCnxn: Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
16/04/24 14:07:59 WARN zookeeper.ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1081)
hbase-site.xml如下:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
//Here you have to set the path where you want HBase to store its files.
<property>
<name>hbase.rootdir</name>
<value>hdfs://hadoop-master:9000/hbase</value>
</property>
//Here you have to set the path where you want HBase to store its built in zookeeper files.
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/home/hadoop1/zookeeper</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.zookeeper.property.clientPort</name>
<value>2183</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>172.17.25.20</value>
</property>
</configuration>
可能的问题和解决方法是什么?
2条答案
按热度按时间6xfqseft1#
Configuration config = HBaseConfiguration.create();
只有在java找不到hbase-site.xml时,才会创建几乎为空的配置文件。要告诉java您的conf文件在哪里,您可以将hbase-site.xml直接放在类路径中,也可以调用
conf.addResource(**hbase-site path**)
编辑正如拉格朗日在评论中所说,试试看
conf.set("hbase.zookeeper.quorum","172.17.25.20:2183")
h7wcgrx32#
日志中的错误表明hbase-site.xml未正确加载。检查hbase-site.xml:它必须在类路径上,因为
HbaseConfiguration.create()
从您在类路径上设置的路径加载配置(并尝试将其添加到类路径的开头,以防止从嵌入了类似配置文件的其他jar加载hbase-site.xml)此外,您似乎从hbase服务器使用hbase-site.xml:除了hbase.zookeeper.quorum之外的所有配置键在客户机中都是多余和无用的。