HBase Java API remote Access Kerberos authentication

Source: Internet
Author: User
Tags zookeeper

Hbaseconnker.java

1  PackageBigdata.conn;2 3 ImportBigData.utils.resource.ResourcesUtils;4 Importorg.apache.hadoop.conf.Configuration;5 Importorg.apache.hadoop.hbase.HBaseConfiguration;6 Importorg.apache.hadoop.hbase.client.Connection;7 Importorg.apache.hadoop.hbase.client.ConnectionFactory;8 Importorg.apache.hadoop.security.UserGroupInformation;9 Ten Importjava.io.IOException; One ImportJava.io.InputStream; A ImportJava.nio.file.Files; - Importjava.nio.file.Paths; - Importjava.util.Properties; the  -  Public classHbaseconnker { -  -     Private StaticConnection Connectionker =NULL; +  -     Private Static volatileHbaseconnker Instanceker; +  A     PrivateHbaseconnker () { at         Try { -Properties Pro = Resourcesutils.getresourceasproperties ("Kerberos/hbaseconfigker.properties"); -  -         /*This configuration file mainly records the relevant configuration information of Kerberos, such as which IP is the KDC? Which realm is the default?  - This file was copied from the remote server.*/ -System.setproperty ("java.security.krb5.conf", Pro.getproperty ("java.security.krb5.conf")); in  -Configuration conf =hbaseconfiguration.create (); to  +             //-----Kerberos Configuration----- -InputStream Hbasesiteinputstream = Files.newinputstream (Paths.get (Pro.getproperty ("Hbase.site")))); the             if(Hbasesiteinputstream = =NULL) { *System.out.println ("The Hbase-site.xml is null!"); $             }Panax Notoginseng Conf.addresource (hbasesiteinputstream); -Conf.set ("Hadoop.security.authentication", Pro.getproperty ("Hadoop.security.authentication")); the  +             //This can be understood as user name information, which is principal AConf.set ("Kerberos.principal", Pro.getproperty ("Kerberos.principal")); the  + usergroupinformation.setconfiguration (conf); -Usergroupinformation.loginuserfromkeytab (Pro.getproperty ("Kerberos.principal"), $Pro.getproperty ("Kerberos.keytab")); $             // ---------- -  -             //Show connected Servers theSYSTEM.OUT.PRINTLN ("Connect server:" +conf.get ("Hbase.zookeeper.quorum"))); - WuyiConnectionker =connectionfactory.createconnection (conf); theSYSTEM.OUT.PRINTLN ("Create connection Success! "); -}Catch(IOException e) { Wu e.printstacktrace (); -         } About  $     } -  -      Public StaticConnection getconnection () { -         returnConnectionker; A     } +  the      Public StaticHbaseconnker getistance () { -         //defines a common static method that returns an instance of the type $         if(Instanceker = =NULL) { the             //when an object is instantiated (without using a synchronous block of code, instance is not equal to NULL, the object is returned directly, improving operational efficiency) the             synchronized(Hbaseconnker.class) { the                 //Synchronizing code blocks (when an object is not initialized, use a synchronous block of code to guarantee that the object will not be created again after the first creation of the multi-threaded access) the                 if(Instanceker = =NULL) { -                     //Uninitialized , the initial instance variable inInstanceker =NewHbaseconnker (); the                 } the             } About         } the         returnInstanceker; the     } the}

Hbaseconfigker.properties

# HBase Confighbase.zookeeper.quorum=20.1.1.93hbase.zookeeper.property.clientport=2181java.security.krb5.conf= src/main/resources/kerberos/krb5.confhadoop.security.authentication=kerberoshbase.site=src/main/resources/ Kerberos/hbase-site.xmlkerberos.keytab=src/main/resources/kerberos/xxx.keytab[email protected]

HBase Java API remote Access Kerberos authentication

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.