【问题标题】:HBase data entry program not running properlyHBase 数据录入程序运行不正常
【发布时间】:2016-04-26 14:33:13
【问题描述】:

以下是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>

可能的问题和解决方案是什么?

【问题讨论】:

    标签: hadoop hbase apache-zookeeper hadoop2


    【解决方案1】:

    日志中的错误表明 hbase-site.xml 未正确加载。检查您的 hbase-site.xml:它必须在您的类路径中,因为 HbaseConfiguration.create() 从您在类路径上设置的路径加载配置(并尝试将其添加到类路径的开头以防止从其他加载 hbase-site.xml jar 中嵌入了类似的配置文件) 此外,您似乎使用 Hbase 服务器中的 hbase-site.xml:除了 hbase.zookeeper.quorum 之外的所有配置键在客户端都是多余且无用的。

    【讨论】:

    • “检查您的 hbase-site.xml:它必须在您的类路径中”是什么意思?
    • 我的意思是必须将hbase-site.xml文件的路径添加到Java类路径中
    【解决方案2】:

    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")

    【讨论】:

    • 添加config.addResource("/home/hadoop1/hbase-1.1.4/conf/hbase-site.xml");时仍然出现同样的错误
    • 你可以试试config.set("hbase.zookeeper.property.clientPort", "2183");
    • @dorado, config.addResource(String) 也尝试从 Java 类路径加载配置文件。它等待类路径资源名称,而不是随机位置的文件路径。 hbase.zookeeper.property.clientPort 是客户端将在 Zookeeper 服务器端(而不是客户端)连接的端口。您必须在hbase.zookeeper.quorum(例如172.17.25.20:2183)中设置要连接的Zookeeper客户端端口
    • 关于:hbase.zookeeper.property.clientPort is the port at which the clients will connect at Zookeeper server side(not on client side). 这是 Zookeeper 在 HBase 服务器中运行时的服务器端属性(例如,不是独立的 ZK 服务器)。在客户端应用配置中它没用。
    猜你喜欢
    • 2014-10-04
    • 1970-01-01
    • 1970-01-01
    • 2020-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多