hbase的安装和配置请看
http://hunray.iteye.com/admin/blogs/1774583
使用shell建表
create 'gpsinfo','gpsdata'
gpsinfo为表名
gpsdata为columnfamily
import java.io.IOException;
import java.util.Date;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;
public class HbaseSave {
public static void main(String[] args) throws Exception {
//建表 create 'gpsinfo','gpsdata'
Configuration HBASE_CONFIG = new Configuration();
HBASE_CONFIG.set("hbase.zookeeper.quorum", "192.168.3.206");
Configuration configuration = HBaseConfiguration.create(HBASE_CONFIG);
try {
HBaseAdmin admin =new HBaseAdmin(configuration);
if (admin.tableExists("gpsinfo")) {
System.out.println("表已经存在!");
HTable table = new HTable(configuration, "gpsinfo");
Put put = new Put(Bytes.toBytes("0800025364"+new Date().getTime()));
put.add(Bytes.toBytes("gpsdata"),Bytes.toBytes("unitid"),Bytes.toBytes("0800025364"));
put.add(Bytes.toBytes("gpsdata"),Bytes.toBytes("lon"),Bytes.toBytes(111.321f));
put.add(Bytes.toBytes("gpsdata"),Bytes.toBytes("lat"),Bytes.toBytes(23.4687f));
put.add(Bytes.toBytes("gpsdata"),Bytes.toBytes("direction"),Bytes.toBytes(180));
put.add(Bytes.toBytes("gpsdata"),Bytes.toBytes("speed"),Bytes.toBytes(62.2f));
put.add(Bytes.toBytes("gpsdata"),Bytes.toBytes("locationstatus"),Bytes.toBytes(1));
put.add(Bytes.toBytes("gpsdata"),Bytes.toBytes("vehiclestatus"),Bytes.toBytes("点火"));
put.add(Bytes.toBytes("gpsdata"),Bytes.toBytes("gpstime"),Bytes.toBytes(new Date().getTime()));
put.add(Bytes.toBytes("gpsdata"),Bytes.toBytes("referenceposition"),Bytes.toBytes("意隆路22号"));
put.add(Bytes.toBytes("gpsdata"),Bytes.toBytes("rawdata"),Bytes.toBytes("7b334673124545711133447852217d"));
table.put(put);
table.close();
}else{
System.out.println("表不存在");
}
configuration.clear();
} catch (IOException e) {
e.printStackTrace();
}
}
}
在此过程中碰到的一些问题:
1. [root@localhost bin]# hadoop namenode -format
-bash: hadoop: command not found
将hadoop/bin路径加入PATH,需要重启机器
[root@localhost bin]# vi /etc/profile
export PATH=$JAVA_HOME/bin:$PATH:/root/Desktop/hadoop-1.1.1/bin
2. myeclipse连接报错:
警告: Possibly transient ZooKeeper exception: org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /hbase/master
2013-1-22 10:22:36 org.apache.hadoop.hbase.util.RetryCounter sleepUntilNextRetry
确保hbase正常启动了
禁用IPV6,将/etc/hosts文件里面的::1 localhost那一行删掉重启
关闭防火墙
3. hadoop启动,namenode日志文件中
org.apache.hadoop.hdfs.server.common.InconsistentFSStateException: Directory /var/log/hadoop_data/dfs/name is in an inconsistent state: storage directory does not exist or is not accessible.
at org.apache.hadoop.hdfs.server.namenode.FSImage.recoverTransitionRead(FSImage.java:303)
at org.apache.hadoop.hdfs.server.namenode.FSDirectory.loadFSImage(FSDirectory.java:100)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.initialize(FSNamesystem.java:411)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.<init>(FSNamesystem.java:379)
at org.apache.hadoop.hdfs.server.namenode.NameNode.initialize(NameNode.java:277)
at org.apache.hadoop.hdfs.server.namenode.NameNode.<init>(NameNode.java:529)
at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:1403)
at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:1412)
格式化namenode
$ hadoop namenode –format
4. 客户端连接hbase报错:
java.net.UnknownHostException: unknown host: xiekang-pc
在本地配置host
192.168.3.206 xiekang-pc
5. java.net.ConnectException: Connection refused: no further information
org.apache.hadoop.hbase.ipc.HBaseClient$FailedServerException: This server is in the failed servers list: localhost/127.0.0.1:60000
服务器上master地址和localhost/127.0.0.1:60000对不上。
查看http://192.168.3.206:60010/master-status的master地址。
分享到:
相关推荐
使用本地Java客户端,或者通过提供了REST、Avro和Thrift应用编程接口的网关服务器来访问HBase;了解HBase架构的细节,包括存储格式、预写日志、后台进程等;在HBase中集成MapReduce框架;了解如何调节集群、设计模式...
使用本地Java客户端,或者通过提供了REST、Avro和Thrift应用编程接口的网关服务器来访问HBase;了解HBase架构的细节,包括存储格式、预写日志、后台进程等;在HBase中集成MapReduce框架;了解如何调节集群、设计模式...
使用本地Java客户端,或者通过提供了REST、Avro和Thrift应用编程接口的网关服务器来访问HBase;让你了解HBase架构的细节,包括存储格式、预写日志、后台进程等等;在HBase中集成用于海量并行数据处理任务的Hadoop的...
使用本地Java客户端,或者通过提供了REST、Avro和Thrift应用编程接口的网关服务器来访问HBase;了解HBase架构的细节,包括存储格式、预写日志、后台进程等;在HBase中集成MapReduce框架;了解如何调节集群、设计模式...
使用本地Java客户端,或者通过提供了REST、Avro和Thrift应用编程接口的网关服务器来访问HBase;了解HBase架构的细节,包括存储格式、预写日志、后台进程等;在HBase中集成MapReduce框架;了解如何调节集群、设计模式...
■使用本地java客户端,或者通过提供了rest、avro和thrift应用编程接口的网关服务器来访问hbase ■了解hbase架构的细节,包括存储格式、预写日志、后台进程等等 ■在hbase中集成用于海量并行数据处理任务的...
8.1. 安全客户端访问 HBase 8.2. 访问控制 9. 架构 9.1. 概述 9.2. Catalog Tables 9.3. 客户端 9.4. Client Request Filters 9.5. Master 9.6. RegionServer 9.7. Regions 9.8. Bulk Loading 9.9. HDFS 10. 外部 ...
使用本地Java客户端,或者通过提供了REST、Avro和Thrift应用编程接口的网关服务器来访问HBase;了解HBase架构的细节,包括存储格式、预写日志、后台进程等;在HBase中集成MapReduce框架;了解如何调节集群、设计模式...
使用本地java客户端,或者通过提供了rest、avro和thrift应用编程接口的网关服务器来访问hbase;了解hbase架构的细节,包括存储格式、预写日志、后台进程等;在hbase中集成mapreduce框架;了解如何调节集群、设计模式...