手机版
你好,游客 登录 注册
背景:
阅读新闻

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

[日期:2012-10-01] 来源:Linux社区  作者:fansy1990 [字体:大 中 小]

在编译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.  
  3. import java.io.IOException; 
  4.  
  5. import org.apache.hadoop.conf.Configuration; 
  6. import org.apache.hadoop.hbase.HBaseConfiguration; 
  7. import org.apache.hadoop.hbase.HColumnDescriptor; 
  8. import org.apache.hadoop.hbase.HTableDescriptor; 
  9. import org.apache.hadoop.hbase.client.HBaseAdmin; 
  10. import org.apache.hadoop.hbase.client.HTable; 
  11. import org.apache.hadoop.hbase.client.Put; 
  12.  
  13. public class TableOperation { 
  14.  
  15.     /** 
  16.      *  include all table operation like scan,input,create table,drop table, and so on 
  17.      *  date:15:12 
  18.      * @throws IOException  
  19.      */ 
  20.     public static void main(String[] args) throws IOException { 
  21.         // TODO Auto-generated method stub  
  22.     //  createTable("tabledemo","name");  
  23.         int status=Integer.parseInt(args[0]); 
  24.         if(status==1){ 
  25.             createTable(args[1],args[2]); 
  26.         }else if(status==2){ 
  27.             deleteTable(args[1]); 
  28.         } 
  29.     } 
  30.      
  31.     /* 
  32.      * create a table and its family 
  33.      */ 
  34.     public static void createTable(String tablename ,String family) throws IOException{ 
  35.         Configuration conf=HBaseConfiguration.create(); 
  36.         HBaseAdmin admin=new HBaseAdmin(conf); 
  37.         HTableDescriptor tableDesc=new HTableDescriptor(tablename); 
  38.         tableDesc.addFamily(new HColumnDescriptor(family)); 
  39.         admin.createTable(tableDesc); 
  40.         admin.close(); 
  41.     } 
  42.      
  43.     /* 
  44.      *  add data to table ,include row ,family,column,value,tablename 
  45.      */ 
  46.     public static void addData(String tablename,String family,String qualifier,String row,String value)throws IOException { 
  47.         Configuration conf=HBaseConfiguration.create(); 
  48.         HTable table=new HTable(conf,tablename); 
  49.         Put putrow=new Put(row.getBytes()); 
  50.         putrow.add(family.getBytes(), qualifier.getBytes(), value.getBytes()); 
  51.         table.put(putrow); 
  52.         table.close(); 
  53.     } 
  54.      
  55.     /* 
  56.      *  drop a table by the tablename given 
  57.      */ 
  58.     public static void deleteTable(String tablename)throws IOException{ 
  59.         Configuration conf=HBaseConfiguration.create(); 
  60.         HBaseAdmin admin=new HBaseAdmin(conf); 
  61.         admin.disableTable(tablename); 
  62.         admin.deleteTable(tablename); 
  63.         admin.close(); 
  64.     } 
  65. } 

命令行的测试结果如下:

  1. fansy@fansyPC:~/hadoop-1.0.2$ bin/hadoop TableOperation 1 testdemo name 
  2. Warning: $HADOOP_HOME is deprecated. 
  3.  
  4. 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 
  5. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:host.name=fansyPC 
  6. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:java.version=1.7.0_07 
  7. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:java.vendor=Oracle Corporation 
  8. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:java.home=/home/fansy/jdk1.7.0_07/jre 
  9.  
  10. 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 
  11. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:java.io.tmpdir=/tmp 
  12. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:java.compiler=<NA> 
  13. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:os.name=Linux 
  14. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:os.arch=amd64 
  15. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:os.version=3.2.0-31-generic 
  16. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:user.name=fansy 
  17. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:user.home=/home/fansy 
  18. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Client environment:user.dir=/home/fansy/hadoop-1.0.2 
  19. 12/09/29 15:28:03 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=localhost:2181 sessionTimeout=180000 watcher=hconnection 
  20. 12/09/29 15:28:04 INFO zookeeper.ClientCnxn: Opening socket connection to server /127.0.0.1:2181 
  21. 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. 
  22. 12/09/29 15:28:04 INFO zookeeper.RecoverableZooKeeper: The identifier of this process is 18076@bwa108 
  23. 12/09/29 15:28:04 INFO zookeeper.ClientCnxn: Socket connection established to localhost/127.0.0.1:2181, initiating session 
  24. 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 
  25. 12/09/29 15:28:05 INFO client.HConnectionManager$HConnectionImplementation: Closed zookeeper sessionid=0x13a10cf8247000e 
  26. 12/09/29 15:28:05 INFO zookeeper.ZooKeeper: Session: 0x13a10cf8247000e closed 
  27. create table:testdemo done 

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

linux
相关资讯       Hbase 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款