{"id":15677,"date":"2025-01-22T10:53:40","date_gmt":"2025-01-22T02:53:40","guid":{"rendered":"https:\/\/nj.transwarp.cn:8180\/?p=15677"},"modified":"2025-01-22T11:26:28","modified_gmt":"2025-01-22T03:26:28","slug":"tdh9-x%e7%89%88%e6%9c%ac%e5%bc%80%e5%90%afkerberos%e5%92%8c%e5%bc%ba%e8%ae%a4%e8%af%81%e4%b8%8b%ef%bc%8cobject-store%e4%bd%bf%e7%94%a8%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/kbwp.transwarp.cn\/?p=15677","title":{"rendered":"TDH9.x\u7248\u672c\u5f00\u542fkerberos\u548c\u5f3a\u8ba4\u8bc1\u4e0b\uff0cObject Store\u4f7f\u7528\u65b9\u6cd5"},"content":{"rendered":"<h3>\u6982\u8981\u63cf\u8ff0<\/h3>\n<hr \/>\n<p>TDH 9.3.1 \u7248\u672c\u4e0b\uff0c\u4f7f\u7528object store\u7684\u59ff\u52bf\u6709\u522b\u4e8e\u4e4b\u524d\u7684\u8001\u7248\u672c\uff0c\u62a5\u9519 <strong>\u65e0\u6cd5\u5c06\u7c7b org.apache.hadoop.hbase.client.HTable\u4e2d\u7684\u6784\u9020\u5668 HTable\u5e94\u7528\u5230\u7ed9\u5b9a\u7c7b<\/strong>\uff0c\u539f\u56e0\u662f HTable\u88ab\u6dd8\u6c70\uff0c\u53ea\u80fd\u7528Table \u6765\u5b9e\u73b0\uff0c\u672c\u6587\u7ed9\u51fa demo \u5b9e\u4f8b\u3002<\/p>\n<h3>\u8be6\u7ec6\u8bf4\u660e<\/h3>\n<hr \/>\n<h4>1\u3001\u83b7\u53d6Hbase api\u8fd0\u884c\u4f9d\u8d56\u7684jar\u5305<\/h4>\n<p>\u83b7\u53d6hyperbase pod\u4e2d \/usr\/lib\/hbase\/lib\u4e0b\u6240\u6709jar\u5305<\/p>\n<h4>2\u3001windows \u672c\u5730\u653e\u7f6e\u914d\u7f6e\u6587\u4ef6<\/h4>\n<p>\u4ece\u96c6\u7fa4\u4e0a\u83b7\u53d6\u8fd9\u4e9b\u914d\u7f6e\u6587\u4ef6\uff0c\u6bd4\u5982\u6211\u4eec\u653e\u5230C\u76d8\u7684tmp\u76ee\u5f55\u4e0b\uff1a<\/p>\n<p>C:\\tmp\\krb5.ini<br \/>\nC:\\tmp\\hyperbase.keytab<br \/>\nC:\\tmp\\jaas.conf<br \/>\nC:\\tmp\\hbase-site.xml<br \/>\nC:\\tmp\\hdfs-site.xml<br \/>\nC:\\tmp\\core-site.xml<\/p>\n<h4>3\u3001\u4fee\u6539 jaas.conf \u6587\u4ef6\u4e2d\u7684 keyTab \u8def\u5f84<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/nj.transwarp.cn:8180\/wp-content\/uploads\/2025\/01\/image-1737514450058.png\" alt=\"file\" \/><\/p>\n<h4>4\u3001Object Store API \u793a\u4f8b<\/h4>\n<p>\u53c2\u8003demo:<\/p>\n<pre><code class=\"language-java\">import static org.junit.Assert.assertTrue;\n\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.util.concurrent.TimeUnit;\n\nimport org.apache.hadoop.conf.Configuration;\nimport org.apache.hadoop.fs.Path;\nimport org.apache.hadoop.hbase.*;\nimport org.apache.hadoop.hbase.client.*;\nimport org.apache.hadoop.hbase.shaded.protobuf.generated.HyperbaseProtos;\nimport org.apache.hadoop.hbase.util.Bytes;\nimport org.apache.hadoop.hyperbase.client.HyperbaseAdmin;\nimport org.apache.hadoop.hyperbase.metadata.HyperbaseMetadata;\nimport org.apache.hadoop.hyperbase.secondaryindex.IndexedColumn;\nimport org.apache.hadoop.hyperbase.secondaryindex.LOBIndex;\nimport org.apache.hadoop.security.UserGroupInformation;\n\npublic class objectstore {\n    protected static HyperbaseAdmin admin = null;\n    private static Connection conn;\n    private static final String ZK_QUORUM = \"hbase.zookeeper.quorum\";\n    private static final String ZK_CLIENT_PORT = \"hbase.zookeeper.property.clientPort\";\n    private static final String ZK_POS = \"kv2:2181,kv3:2181,kv4:2181\";\n    private static final String ZK_PORT_VALUE = \"2181\";\n    private static Configuration conf;\n\n    static {\n        \/\/\u8fd9\u91cc\u9700\u8981\u5c06\u96c6\u7fa4\u4e0a\u7684\/etc\/krb5.conf\u6587\u4ef6\u653e\u7f6e\u5230windows\u672c\u673a\u4e0b\uff0c\u5e76\u91cd\u547d\u540d\u4e3akrb5.ini\n        System. setProperty(\"java.security.krb5.conf\", \"C:\\\\tmp\\\\krb5.ini\" );\n        System.setProperty(\"java.security.auth.login.config\", \"C:\\\\tmp\\\\jaas.conf\");\n        conf = HBaseConfiguration.create();\n        conf.set(ZK_CLIENT_PORT, ZK_PORT_VALUE);\n        conf.set(\"hadoop.security.authentication\", \"kerberos\");\n        conf.addResource(new Path(\"C:\\\\tmp\\\\hbase-site.xml\"));\n        conf.addResource(new Path(\"C:\\\\tmp\\\\hdfs-site.xml\"));\n        conf.addResource(new Path(\"C:\\\\tmp\\\\core-site.xml\"));\n    }\n\n    public static void main(String[] args) throws Exception {\n        UserGroupInformation.setConfiguration(conf);\n        UserGroupInformation.loginUserFromKeytab(\"hbase\/kv4@KTDH\", \"C:\\\\tmp\\\\hyperbase.keytab\");\n        \/\/\u521b\u5efa\u8fde\u63a5\u6c60\n        try {\n            conn = ConnectionFactory.createConnection(conf);\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n        admin = new HyperbaseAdmin(conf);\n        testLOBGet();\n    }\n\n    public static void testLOBGet() throws Exception {\n        byte[] row = Bytes.toBytes(\"rowkey01\");\n        byte[] tableName = Bytes.toBytes(\"SIMPLE_TEST_PUT_SCAN\" + System.nanoTime());\n        System.out.println(tableName);\n        byte[] indexName = Bytes.toBytes(\"IDX\");\n        byte[] family1 = Bytes.toBytes(\"f1\");\n        byte[] family2 = Bytes.toBytes(\"f2\");\n\n        createTable(TableName.valueOf(tableName), family1, family2);\n        addLOB(tableName, family1, indexName);\n        Connection connection = ConnectionFactory.createConnection(conf);\n        Table htable = connection.getHyperbaseTable(TableName.valueOf(tableName));\n        Put put = new Put(row);\n\n        String path = \"C:\\\\tmp\\\\1.jpg\";\n        byte[] value01 = getFileBytes(path);\n\n        put.addColumn(family1, Bytes.toBytes(\"q1\"), value01);\n        htable.put(put);\n        TimeUnit.SECONDS.sleep(1);\n\n        Get get = new Get(row);\n        Result rs = htable.get(get);\n        CellScanner cs = rs.cellScanner();\n        while (cs.advance()) {\n            if(cs.current().getFamilyArray().equals(\"v1\")){\n                assertTrue(Bytes.equals(CellUtil.cloneValue(cs.current()), value01));\n            }\n            System.out.println(Bytes.toString(CellUtil.cloneValue(cs.current())));\n        }\n        htable.close();\n\/\/        admin.deleteTable(TableName.valueOf(tableName));\n    }\n\n    public static byte[] getFileBytes(String path) throws IOException {\n        FileInputStream fis = new FileInputStream(new File(path));\/\/ \u65b0\u5efa\u4e00\u4e2aFileInputStream\u5bf9\u8c61\n        byte[] b = new byte[fis.available()];\/\/ \u65b0\u5efa\u4e00\u4e2a\u5b57\u8282\u6570\u7ec4\n        fis.read(b);\/\/ \u5c06\u6587\u4ef6\u4e2d\u7684\u5185\u5bb9\u8bfb\u53d6\u5230\u5b57\u8282\u6570\u7ec4\u4e2d\n        fis.close();\n        return b;\n    }\n\n    public static void createTable(TableName tableName, byte[]... families) throws Exception {\n        HTableDescriptor tableDescriptor = new HTableDescriptor(tableName);\n        for (byte[] family : families) {\n            tableDescriptor.addFamily(new HColumnDescriptor(family));\n        }\n\/\/ \u6ce8\u610f\uff0cobject store\u4e00\u5b9a\u8981\u9884\u5206\u914dregion\uff0c\u6bcf\u4e2aregion\u6700\u597d\u4e0d\u8981\u8d85\u8fc7500G\u7684\u6570\u636e\u3002\n        byte[][] splitKeys = new byte[5][];\n        for (int i = 0; i < 5; i++) {\n            splitKeys[i] = Bytes.toBytes(\"rowkey\" + i);\n        }\n\/\/ create table succ\n        admin.createTable(tableDescriptor, null, splitKeys);\n        HyperbaseMetadata metadata = admin.getTableMetadata(tableName);\n        assertTrue(metadata != null);\n\/\/ check metadata\n        assertTrue(metadata.getFulltextMetadata() == null);\n        assertTrue(metadata.getGlobalIndexes().isEmpty());\n        assertTrue(metadata.getLobs().isEmpty());\n        assertTrue(metadata.isTransactionTable() == false);\n    }\n\n    public static void addLOB(byte[] tableName, byte[] family, byte[] LOBFamily) throws IOException {\n        HyperbaseProtos.SecondaryIndex.Builder LOBBuilder = HyperbaseProtos.SecondaryIndex.newBuilder();\n        LOBBuilder.setClassName(LOBIndex.class.getName());\n        LOBBuilder.setUpdate(true);\n        LOBBuilder.setDcop(true);\n        IndexedColumn column = new IndexedColumn(family, Bytes.toBytes(\"v1\"));\n        LOBBuilder.addColumns(column.toPb());\n        admin.addLob(TableName.valueOf(tableName), new LOBIndex(LOBBuilder.build()), LOBFamily,false, 2);\n    }\n}<\/code><\/pre>\n<h4>5\u3001\u67e5\u770b\u751f\u6210\u7684hbase\u8868<\/h4>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u6267\u884c\u6210\u529f\u4e4b\u540e\uff0c\u5c06\u56fe\u7247\u5df2\u7ecf\u4fdd\u5b58\u5728\u5bf9\u5e94\u7684hbase\u8868\u4e2d\uff0c\u8fdb\u5165hbase shell \u67e5\u770b\u751f\u6210\u7684hbase\u8868\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/nj.transwarp.cn:8180\/wp-content\/uploads\/2025\/01\/image-1737514235797.png\" alt=\"file\" \/><\/p>\n<h4>6\u3001inceptor\u4e2d\u521b\u5efahbase\u5916\u8868<\/h4>\n<pre><code class=\"language-sql\">--hbase.columns.mapping \u662f\u5b9a\u4e49\u6620\u5c04\u8868\u548cHBase\u8868\u5217\u4e4b\u95f4\u7684\u6620\u5c04\u5173\u7cfb\uff1b\n--hbase.table.name \u662f\u5b9a\u4e49\u6620\u5c04\u8868\u5bf9\u5e94\u7684HBase\u8868\u7684\u8868\u540d\nDROP TABLE IF EXISTS objectstore_9;\nCREATE EXTERNAL TABLE objectstore_9(\nkey1 STRING,\next BLOB\n)\nSTORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'\nWITH SERDEPROPERTIES (\n'hbase.columns.mapping'=':key,f1:q1'\n)\nTBLPROPERTIES (\n'hbase.table.name'='SIMPLE_TEST_PUT_SCAN437876739999000');<\/code><\/pre>\n<p>\u6700\u540e\uff0c\u6211\u4eec\u5728inceptor\u4e2d\u67e5\u8be2\u4fdd\u5b58\u7684\u56fe\u7247<\/p>\n<pre><code class=\"language-sql\">SELECT * FROM objectstore_9;<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/nj.transwarp.cn:8180\/wp-content\/uploads\/2025\/01\/image-1737514275647.png\" alt=\"file\" \/><\/p>\n<h2><strong>FAQ:<\/strong><\/h2>\n<p><strong>1\u3001\u5982\u4f55\u67e5\u770b\u4ee3\u7801\u4e2dkerberos\u8ba4\u8bc1\u7684\u8be6\u7ec6\u62a5\u9519\uff1f<\/strong><\/p>\n<p>\u5efa\u8bae\u901a\u8fc7\u4fee\u6539jvm\u542f\u52a8\u53c2\u6570\uff0c\u6dfb\u52a0<code>-Dsun.security.krb5.debug=true<\/code>\u7684\u65b9\u5f0f\u6253\u5370\u8be6\u7ec6\u65e5\u5fd7\uff0c\u4ee5IDEA\u4e3a\u4f8b\uff1a<br \/>\n\u3010Run\u3011-\u3010Edit Configurations...\u3011<\/p>\n<p>Add VM options:<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2021\/09\/image-1631945705464.png\" alt=\"file\" \/><\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2021\/09\/image-1631945724966.png\" alt=\"file\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981\u63cf\u8ff0 TDH 9.3.1 \u7248\u672c\u4e0b\uff0c\u4f7f\u7528object store\u7684\u59ff\u52bf\u6709\u522b\u4e8e\u4e4b\u524d\u7684\u8001\u7248\u672c\uff0c\u62a5\u9519 \u65e0\u6cd5\u5c06\u7c7b o ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/kbwp.transwarp.cn\/?p=15677\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-15677","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"acf":[],"_links":{"self":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/15677","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=15677"}],"version-history":[{"count":2,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/15677\/revisions"}],"predecessor-version":[{"id":15686,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/15677\/revisions\/15686"}],"wp:attachment":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=15677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=15677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=15677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}