This is a two function, all very simple to write a piece of it.
Simple to what extent, simple to paste code on it ...
HBase
PackageCom.miras.data;Importorg.apache.hadoop.conf.Configuration;Importorg.apache.hadoop.hbase.HBaseConfiguration;ImportOrg.apache.hadoop.hbase.TableName;Importorg.apache.hadoop.hbase.client.Connection;Importorg.apache.hadoop.hbase.client.ConnectionFactory;ImportOrg.apache.hadoop.hbase.client.Put;Importorg.apache.hadoop.hbase.client.Table;Importorg.apache.hadoop.hbase.util.Bytes;Importorg.apache.hadoop.security.UserGroupInformation;Importjava.io.IOException;/** * @authorSUNZQ *@since2017/8/30*/ Public classHbasemain { Public Static voidMain (string[] args)throwsIOException {system.setproperty ("Java.security.krb5.conf", "/app/conf/krb5.conf"); Configuration conf=hbaseconfiguration.create (); Conf.set ("Hadoop.security.authentication", "Kerberos"); Usergroupinformation.setconfiguration (conf); Usergroupinformation.loginuserfromkeytab ("Storm-miras", "/app/conf/storm.headless.keytab"); Connection Connection=connectionfactory.createconnection (conf); Table Table= Connection.gettable (tablename.valueof ("HBASE_KRB")); Put put=NewPut (Bytes.tobytes (2)); Put.addcolumn (Bytes.tobytes ("CF"), Bytes.tobytes ("name"), Bytes.tobytes ("World")); Table.put (Put); Table.close (); Connection.close (); }}
Hdfs
PackageCom.miras.data;Importorg.apache.hadoop.conf.Configuration;ImportOrg.apache.hadoop.fs.FileStatus;ImportOrg.apache.hadoop.fs.FileSystem;ImportOrg.apache.hadoop.fs.Path;Importorg.apache.hadoop.security.UserGroupInformation;Importjava.io.IOException;/** * @authorSUNZQ *@since2017/8/30*/ Public classHdfsmain { Public Static voidMain (string[] args)throwsIOException {system.setproperty ("Java.security.krb5.conf", "/app/conf/krb5.conf"); Configuration conf=NewConfiguration (); Conf.set ("Fs.defaultfs", "hdfs://node1:8020"); Conf.set ("Hadoop.security.authentication", "Kerberos"); Usergroupinformation.setconfiguration (conf); Usergroupinformation.loginuserfromkeytab ("Storm-miras", "/app/conf/storm.headless.keytab"); FileSystem FS=filesystem.get (conf); Filestatus[] Fsstatus= Fs.liststatus (NewPath ("/")); for(inti = 0; i < fsstatus.length; i++) {System.out.println (Fsstatus[i].getpath (). toString ()); } }}
A piece of water
Java Connection for Kerberos-certified HBase and HDFS