如何避免使用api authoozieclient提示密码-authtype.kerberos

7z5jn7bk  于 2021-07-13  发布在  Hadoop
关注(0)|答案(0)|浏览(288)

我有下面的代码来获取当前正在运行的协调器的作业状态,这些协调器使用oozieclientapi从不同的框中获取,这些框不是集群的一部分。将authtype用作kerberos。当我调用对象authclient(如下所示)以获取协调器的状态时,它会一次又一次地提示输入用户名和密码。你能帮我避免用户名和密码提示吗

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.oozie.client.AuthOozieClient;
import org.apache.oozie.client.BulkResponse;
import org.apache.oozie.client.BundleJob;
import org.apache.oozie.client.CoordinatorJob;
import org.apache.oozie.client.OozieClient;
import org.apache.oozie.client.OozieClientException;
import org.apache.oozie.client.WorkflowJob;
import org.apache.oozie.client.WorkflowJob.Status;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.net.URL;
public class OozieJobClient {
    public static AuthOozieClient authClient = null;
    public static String OOZIE_SERVER_URL = "http://XAXAXA.XAXAXA.com:11000/oozie";
    public static String nameNode = "hdfs://XAXAXA.XAXAX.XAXAXA.XAXAXA.com:8020";
    public static OozieClient wc;
    public static void main(String[] args) throws IOException {
        try {           
            URL oozieUrl = new URL(OOZIE_SERVER_URL);
            //OozieJobClient client = new OozieJobClient(OOZIE_SERVER_URL);
            authClient = new AuthOozieClient(oozieUrl.toString(), AuthOozieClient.AuthType.KERBEROS.toString());            
            Properties conf = authClient.createConfiguration();
            Configuration config = new Configuration();
            config.set("fs.defaultFS", nameNode);
            config.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());
            config.set("fs.file.impl", org.apache.hadoop.fs.LocalFileSystem.class.getName());
            config.set("hadoop.security.authentication", "Kerberos");
            UserGroupInformation.setConfiguration(config);
            UserGroupInformation.loginUserFromKeytab("myusername@XAXAXA.COM", 
  "C:\\ici_fw\\Hadoop\\myusername.keytab");

            System.setProperty("java.security.krb5.realm", "XAXAXA.COM");
            System.setProperty("java.security.krb5.conf", "C:\\ici_fw\\krb5.ini");
            System.setProperty("java.security.krb5.kdc", "axaxaxax.com");           
            System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
            System.setProperty("java.security.auth.login.config", "C:\\ici_fw\\jaas.conf");         
            List<BundleJob> runningBundlesList = authClient.getBundleJobsInfo("user=jobsusername", 1, 4000);
            System.out.println(runningBundlesList);
            for (BundleJob obj1 : runningBundlesList) {
                System.out.println(obj1.getAppName() + ", " + obj1.getId() + ", " + obj1.getStatus() + ", "
                        + obj1.getCoordinators());

                System.out.println(authClient.getBundleJobInfo(obj1.getId()).getCoordinators());

            }
            System.exit(0);
        } catch (OozieClientException e) {
            e.printStackTrace();
        }   }}

输出:

log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/myusername/.m2/repository/org/slf4j/slf4j-simple/1.6.6/slf4j-simple-1.6.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/myusername/.m2/repository/org/slf4j/slf4j-log4j12/1.7.5/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/myusername/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.4.1/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
null
Kerberos username [MYUSERNAME]: myusername [PROMPT1]
Kerberos password for myusername: mypassword [PROMPT1]
Kerberos username [MYUSERNAME]: myusername [PROMPT2]
Kerberos password for myusername: mypassword [PROMPT2]
[Bundle id[0031119-201108094620631-oozie-oozi-B] status[<STATUS>], Bundle id[0013446-201108094923150-oozie-oozi-B] status[<STATUS>], Bundle id[0013436-201108094923150-oozie-oozi-B] status[<STATUS>], Bundle id[0029646-201108094620631-oozie-oozi-B] status[<STATUS>], Bundle id[0022880-201108094742175-oozie-oozi-B] status[<STATUS>], Bundle id[0022131-201108094620631-oozie-oozi-B] status[<STATUS>], Bundle id[0010296-201108094851999-oozie-oozi-B] status[<STATUS>], Bundle id[0004481-201108094923150-oozie-oozi-B] status[<STATUS>], Bundle id[0003595-201108094923150-oozie-oozi-B] status[<STATUS>], Bundle id[0033268-201011102512157-oozie-oozi-B] status[<STATUS>], Bundle id[0030233-201011102515944-oozie-oozi-B] status[<STATUS>], Bundle id[0025747-201011102515944-oozie-oozi-B] status[<STATUS>], Bundle id[0017968-201011102515944-oozie-oozi-B] status[<STATUS>], Bundle id[0019437-201011102512157-oozie-oozi-B] status[<STATUS>], Bundle id[0069111-200913110022211-oozie-oozi-B] status[<STATUS>], Bundle id[0057009-200913110022211-oozie-oozi-B] status[<STATUS>], Bundle id[0022712-200913110100677-oozie-oozi-B] status[<STATUS>], Bundle id[0010082-200913110022211-oozie-oozi-B] status[<STATUS>], Bundle id[0013891-200831170601093-oozie-oozi-B] status[<STATUS>], Bundle id[0013117-200831170600297-oozie-oozi-B] status[<STATUS>], Bundle id[0013110-200831170600297-oozie-oozi-B] status[<STATUS>], Bundle id[0007502-200831170606985-oozie-oozi-B] status[<STATUS>], Bundle id[0007034-200831170606985-oozie-oozi-B] status[<STATUS>], ]
ICXXX_XXXXXXXX_CCLOAD, 0043335-210117205952974-oozie-oozi-B, <STATUS>, []
Kerberos username [myusername]: XXXXXXXXXXXXX.......so on

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题