当前位置:   article > 正文

命令行运行Hbase: Session 0x0 for server null, unexpected error

hbase server=null

今天又重新看了下hbase的操作,以前虽说是运行过对Hbase的操作,比如直接的建表,导入数据,或者是使用MR操作Hbase,但是都是在单节点上做的,而且是用eclipse下操作的,不用担心一些包的问题。今天打算把代码拷贝到hadoop的lib下面,然后在命令行中运行,下午遇到的一个问题如下:

  1. 12/09/29 12:29:36 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=localhost:2181 sessionTimeout=180000 watcher=hconnection
  2. 12/09/29 12:29:36 INFO zookeeper.ClientCnxn: Opening socket connection to server /127.0.0.1:2181
  3. 12/09/29 12:29:36 INFO client.ZooKeeperSaslClient: Client will not SASL-authenticate because the default JAAS configuration section 'Client' could not be found. If you are not using SASL, you may ignore this. On the other hand, if you expected SASL to work, please fix your JAAS configuration.
  4. 12/09/29 12:29:36 INFO zookeeper.RecoverableZooKeeper: The identifier of this process is 6479@fansyPC
  5. 12/09/29 12:29:36 WARN zookeeper.ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
  6. java.net.ConnectException: 拒绝连接
  7. at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
  8. at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:692)
  9. at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:286)
  10. at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1035)
  11. 12/09/29 12:29:36 WARN zookeeper.RecoverableZooKeeper: Possibly transient ZooKeeper exception: org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /hbase/master
看到这个提示,第一次感觉是不是我配置错了?怎么显示的是127.0.0.1的机子呢?应该是其他节点机或者是本机的计算机名字才对的吧,这样就好像是单机启动一样。我的配置如下:
  1. <configuration>
  2. <property>
  3. <name>hbase.rootdir</name>
  4. <value>hdfs://fansyPC:9000/hbase</value>
  5. </property>
  6. <property>
  7. <name>hbase.cluster.distributed</name>
  8. <value>true</value>
  9. </property>
  10. <property>
  11. <name>hbase.zookeeper.quorum</name>
  12. <value>slave1</value>
  13. </property>
  14. <property>
  15. <name>hbase.zookeeper.property.dataDir</name>
  16. <value>/home/fansy/zookeeper</value>
  17. </property>
  18. </configuration>
看来感觉还是感觉没有配置错误,所以就又去看了官方文档,上面说要ubuntu的系统有点不同的,所以我就又改了下:

/etc/security/limits.conf :

添加这两句:

  1. hadoop - nofile 32768
  2. hadoop soft/hard nproc 32000
/etc/pam.d/common-session:
session required pam_limits.so
但还是不行,然后我就想 会不会是
hbase.zookeeper.quorum

配置 不能和slave节点机在一个上面?所以我就又改了这个值 ,全部改为 fansyPC了,同时我有看到官方文档上面说要用hbase/lib下面的hadoop-core-1.0.2.jar 去代替haoop/下面的hadoop-core-1.0.2.jar这个文件,然后我又照做了,然后就出现了说类找不到,好了,应该差不多 了。最后我把hbase/lib下面的JAR包都放在了hadoop/lib下面(重复的跳过),然后就Ok了。

在编译java文件的时候我只用到了下面三个jar包:hadoop-core-1.0.2.jar,hbase-0.94.0.jar,zookeeper-3.4.3.jar,java代码如下:

  1. package org.fansy.date905;
  2. import java.io.IOException;
  3. import org.apache.hadoop.conf.Configuration;
  4. import org.apache.hadoop.hbase.HBaseConfiguration;
  5. import org.apache.hadoop.hbase.HColumnDescriptor;
  6. import org.apache.hadoop.hbase.HTableDescriptor;
  7. import org.apache.hadoop.hbase.client.HBaseAdmin;
  8. import org.apache.hadoop.hbase.client.HTable;
  9. import org.apache.hadoop.hbase.client.Put;
  10. public class TableOperation {
  11. /**
  12. * include all table operation like scan,input,create table,drop table, and so on
  13. * date:15:12
  14. * @throws IOException
  15. */
  16. public static void main(String[] args) throws IOException {
  17. // TODO Auto-generated method stub
  18. // createTable("tabledemo","name");
  19. int status=Integer.parseInt(args[0]);
  20. if(status==1){
  21. createTable(args[1],args[2]);
  22. }else if(status==2){
  23. deleteTable(args[1]);
  24. }
  25. }
  26. /*
  27. * create a table and its family
  28. */
  29. public static void createTable(String tablename ,String family) throws IOException{
  30. Configuration conf=HBaseConfiguration.create();
  31. HBaseAdmin admin=new HBaseAdmin(conf);
  32. HTableDescriptor tableDesc=new HTableDescriptor(tablename);
  33. tableDesc.addFamily(new HColumnDescriptor(family));
  34. admin.createTable(tableDesc);
  35. admin.close();
  36. }
  37. /*
  38. * add data to table ,include row ,family,column,value,tablename
  39. */
  40. public static void addData(String tablename,String family,String qualifier,String row,String value)throws IOException {
  41. Configuration conf=HBaseConfiguration.create();
  42. HTable table=new HTable(conf,tablename);
  43. Put putrow=new Put(row.getBytes());
  44. putrow.add(family.getBytes(), qualifier.getBytes(), value.getBytes());
  45. table.put(putrow);
  46. table.close();
  47. }
  48. /*
  49. * drop a table by the tablename given
  50. */
  51. public static void deleteTable(String tablename)throws IOException{
  52. Configuration conf=HBaseConfiguration.create();
  53. HBaseAdmin admin=new HBaseAdmin(conf);
  54. admin.disableTable(tablename);
  55. admin.deleteTable(tablename);
  56. admin.close();
  57. }
  58. }
命令行的测试结果如下:
  1. fansy@fansyPC:~/hadoop-1.0.2$ bin/hadoop TableOperation 1 testdemo name
  2. Warning: $HADOOP_HOME is deprecated.
  3. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:zookeeper.version=3.4.3-1240972, built on 02/06/2012 10:48 GMT
  4. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:host.name=fansyPC
  5. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:java.version=1.7.0_07
  6. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:java.vendor=Oracle Corporation
  7. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:java.home=/home/fansy/jdk1.7.0_07/jre
  8. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:java.library.path=/home/fansy/hadoop-1.0.2/libexec/../lib/native/Linux-amd64-64
  9. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:java.io.tmpdir=/tmp
  10. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:java.compiler=<NA>
  11. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:os.name=Linux
  12. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:os.arch=amd64
  13. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:os.version=3.2.0-31-generic
  14. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:user.name=fansy
  15. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:user.home=/home/fansy
  16. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:user.dir=/home/fansy/hadoop-1.0.2
  17. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=localhost:2181 sessionTimeout=180000 watcher=hconnection
  18. 12/09/29 15:28:04 INFO zookeeper.ClientCnxn: Opening socket connection to server /127.0.0.1:2181
  19. 12/09/29 15:28:04 INFO client.ZooKeeperSaslClient: Client will not SASL-authenticate because the default JAAS configuration section 'Client' could not be found. If you are not using SASL, you may ignore this. On the other hand, if you expected SASL to work, please fix your JAAS configuration.
  20. 12/09/29 15:28:04 INFO zookeeper.RecoverableZooKeeper: The identifier of this process is 18076@bwa108
  21. 12/09/29 15:28:04 INFO zookeeper.ClientCnxn: Socket connection established to localhost/127.0.0.1:2181, initiating session
  22. 12/09/29 15:28:04 INFO zookeeper.ClientCnxn: Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x13a10cf8247000e, negotiated timeout = 180000
  23. 12/09/29 15:28:05 INFO client.HConnectionManager$HConnectionImplementation: Closed zookeeper sessionid=0x13a10cf8247000e
  24. 12/09/29 15:28:05 INFO zookeeper.ZooKeeper: Session: 0x13a10cf8247000e closed
  25. create table:testdemo done

这样基本的命令行操作hbase就完成了。





分享,快乐,成长


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/724378
推荐阅读
相关标签
  

闽ICP备14008679号