最最經常使用的指令:java
1.查看hbase有什麼表 listnode
2.建立一個表: create '表名', ‘字段1’, ‘字段二’,。。。session
3.往表中插入一條數據:put '表名',‘rowkey’,‘字段一:’,‘字段一欄目一名稱’,‘字段一欄目一’,.....spa
4.查看整個表某列的內容:scan '表名',‘行名稱’,‘列名稱’server
5.得到某行記錄:get ‘表名’,'rowkey'xml
6.查看錶中記錄總數:count '表名'接口
調用hbase接口應該注什麼?get
1.初始化配置(如):string
Configuration conf = new Configuration();it
conf.set("hbase.zookeeper.quorum", "10.XXX.1.XXX,10.XXX.XXX.43,10.XXX.XXX.44");
conf.set("hbase.rootdir", "hdfs://10.XXX.4.XXX:9000/user/hbase");
conf.set("hbase.cluster.distributed", "true");
conf.set("hbase.zookeeper.property.clientPort", "XXX");
conf.set("hbase.master.port", "XXX");
conf.set("hbase.master.info.port", "XXX");
conf.set("hbase.client.write.buffer", "52428800");
conf.set("hbase.zookeeper.property.dataDir", "/data/home/zookeeper");
conf.set("hbase.tmp.dir", "/data/home/hbase_tmp");
conf.set("zookeeper.znode.parent", "/hbase");
conf.set("hbase.hregion.max.filesize", "1073741824");
conf.set("hbase.regionserver.handler.count", "20");
conf.set("zookeeper.session.timeout", "180000");
這個至關於hbase客戶端程序的site.xml配置文件
讀寫注意事項:
讀寫接口中傳的參數都是二進制數據流,調用的時候注意轉換
public static void readHbase(String table, String rowKey, String outfile, Configuration conf) throws IOException { byte[] ret = null; HTable htable = new HTable(conf, table); Get g = new Get(Bytes.toBytes(rowKey)); System.out.println(g.toString()); Result m = htable.get(g); ret = m.getValue("tarj_value".getBytes(), "Candy".getBytes()); File out_file = new File(outfile); OutputStream out = null; try { out = new FileOutputStream(out_file); out.write(ret); out.close(); } catch (IOException e) { e.printStackTrace(); return; } } public static void writeHbase(String table, String rowKey, String infile, Configuration conf) throws IOException { File file = new File(infile); InputStream in = null; long filelength = file.length(); byte[] filecontent = null; try { in = new FileInputStream(file); filecontent = new byte[(int)filelength]; in.read(filecontent); in.close(); } catch (IOException e) { e.printStackTrace(); return; } Put put_rows = new Put(rowKey.getBytes()); put_rows.add("tarj_value".getBytes(), "Candy".getBytes(), filecontent); HTable htable = new HTable(conf, table); htable.put(put_rows); }