云服务器内容精选

  • 配置安全登录 请根据实际情况,在“com.huawei.bigdata.hbase.examples”包的“TestMain”类中修改“userName”为实际用户名,例如“developuser”。 private static void login() throws IOException { if (User.isHBaseSecurityEnabled(conf)) { userName = "developuser"; //In Windows environment String userdir = TestMain.class.getClassLoader().getResource("conf").getPath() + File.separator; //In Linux environment //String userdir = System.getProperty("user.dir") + File.separator + "conf" + File.separator; /* * if need to connect zk, please provide jaas info about zk. of course, * you can do it as below: * System.setProperty("java.security.auth.login.config", confDirPath + * "jaas.conf"); but the demo can help you more : Note: if this process * will connect more than one zk cluster, the demo may be not proper. you * can contact us for more help */ LoginUtil.setJaasConf(ZOOKEEPER_DEFAULT_ LOG IN_CONTEXT_NAME, userName, userKeytabFile); LoginUtil.login(userName, userKeytabFile, krb5File, conf); } }
  • 场景说明 在安全集群环境下,各个组件之间的相互通信不能够简单的互通,而需要在通信之前进行相互认证,以确保通信的安全性。HBase应用开发需要进行ZooKeeper和Kerberos安全认证。用于ZooKeeper认证的文件为“jaas.conf”,用于Kerberos安全认证文件为keytab文件和krb5.conf文件。具体使用方法在样例代码的“README.md”中会有详细说明。 安全认证主要采用代码认证方式。支持Oracle JAVA平台和IBM JAVA平台。 以下代码在“com.huawei.bigdata.hbase.examples”包的“TestMain”类中。
  • 场景说明 当不同的多个Manager系统下安全模式的集群需要互相访问对方的资源时,管理员可以设置互信的系统,使外部系统的用户可以在本系统中使用。每个系统用户安全使用的范围定义为“域”,不同的Manager系统需要定义唯一的 域名 。跨Manager访问实际上就是用户跨域使用。集群配置互信具体操作步骤请参考集群互信管理章节。 多集群互信场景下,以符合跨域访问的用户身份,使用从其中一个manager系统中获取到的用于Kerberos安全认证的keytab文件和principal文件,以及多个Manager系统各自的客户端配置文件,可实现一次认证登录后访问调用多集群的HBase服务。 以下代码在hbase-example样例工程的“com.huawei.bigdata.hbase.examples”包的“TestMultipleLogin”类中。
  • 配置安全登录 请根据实际情况,在hbase-example样例工程的“com.huawei.bigdata.hbase.examples”包的“TestMultipleLogin”类中修改“userName”为实际用户名,例如“developuser”。 private static void login(Configuration conf, String confDir) throwsIOException { if (User.isHBaseSecurityEnabled(conf)) { userName = " developuser "; //In Windows environment String userdir = TestMain.class.getClassLoader().getResource(confDir).getPath() + File.separator; //In Linux environment //String userdir = System.getProperty("user.dir") + File.separator + confDir + File.separator; userKeytabFile = userdir + "user.keytab"; krb5File = userdir + "krb5.conf"; /* * if need to connect zk, please provide jaas info about zk. of course, * you can do it as below: * System.setProperty("java.security.auth.login.config",confDirPath + * "jaas.conf"); but the demo can help you more : Note: if this process * will connect more than one zk cluster, the demo may be not proper. you * can contact us for more help */ LoginUtil.setJaasConf(ZOOKEEPER_DEFAULT_LOGIN_CONTEXT_NAME, userName,userKeytabFile); LoginUtil.login(userName, userKeytabFile, krb5File, conf); } }
  • 操作场景 HBase把Thrift结合起来可以向外部应用提供HBase服务。在HBase服务安装时可选部署ThriftServer实例,ThriftServer系统可访问HBase的用户,拥有HBase所有NameSpace和表的读、写、执行、创建和管理的权限。访问ThriftServer服务同样需要进行Kerberos认证。HBase实现了两套Thrift Server服务,此处“hbase-thrift-example”为ThriftServer实例服务的调用实现。
  • 操作场景 HBase把Thrift结合起来可以向外部应用提供HBase服务。在HBase服务安装时可选部署ThriftServer实例,ThriftServer系统可访问HBase的用户,拥有HBase所有NameSpace和表的读、写、执行、创建和管理的权限。访问ThriftServer服务同样需要进行Kerberos认证。HBase实现了两套Thrift Server服务,此处“hbase-thrift-example”为ThriftServer实例服务的调用实现。
  • 样例代码 代码认证 以下代码在“hbase-thrift-example”样例工程的“com.huawei.bigdata.hbase.examples”包的“TestMain”类中。 private static void init() throws IOException { // Default load from conf directory conf = HBaseConfiguration.create(); String userdir = TestMain.class.getClassLoader().getResource("conf").getPath() + File.separator;[1] //In Linux environment //String userdir = System.getProperty("user.dir") + File.separator + "conf" + File.separator; conf.addResource(new Path(userdir + "core-site.xml"), false); conf.addResource(new Path(userdir + "hdfs-site.xml"), false); conf.addResource(new Path(userdir + "hbase-site.xml"), false); } [1]userdir获取的是编译后资源路径下conf目录的路径。初始化配置用到的core-site.xml、hdfs-site.xml、hbase-site.xml文件和用于安全认证的用户凭证文件,需要放置到"src/main/resources/conf"的目录下。 安全登录 请根据实际情况,修改“userName”为实际用户名,例如“developuser”。 private static void login() throws IOException { if (User.isHBaseSecurityEnabled(conf)) { userName = " developuser "; //In Windows environment String userdir = TestMain.class.getClassLoader().getResource("conf").getPath() + File.separator; //In Linux environment //String userdir = System.getProperty("user.dir") + File.separator + "conf" + File.separator; userKeytabFile = userdir + "user.keytab"; krb5File = userdir + "krb5.conf"; /* * if need to connect zk, please provide jaas info about zk. of course, * you can do it as below: * System.setProperty("java.security.auth.login.config", confDirPath + * "jaas.conf"); but the demo can help you more : Note: if this process * will connect more than one zk cluster, the demo may be not proper. you * can contact us for more help */ LoginUtil.setJaasConf(ZOOKEEPER_DEFAULT_LOGIN_CONTEXT_NAME, userName, userKeytabFile); LoginUtil.login(userName, userKeytabFile, krb5File, conf); } } 连接ThriftServer实例 try { test = new ThriftSample(); test.test("10.120.16.170", THRIFT_PORT, conf);[2] } catch (TException | IOException e) { LOG.error("Test thrift error", e); } [2]test.test()传入参数为待访问的ThriftServer实例所在节点ip地址,需根据实际运行集群情况进行修改,且该节点ip需要配置到运行样例代码的本机hosts文件中。 “THRIFT_PORT”为ThriftServer实例的配置参数"hbase.regionserver.thrift.port"对应的值。
  • 场景说明 当不同的多个Manager系统下安全模式的集群需要互相访问对方的资源时,管理员可以设置互信的系统,使外部系统的用户可以在本系统中使用。每个系统用户安全使用的范围定义为“域”,不同的Manager系统需要定义唯一的域名。跨Manager访问实际上就是用户跨域使用。集群配置互信具体操作步骤请参考集群互信管理章节。 多集群互信场景下,以符合跨域访问的用户身份,使用从其中一个manager系统中获取到的用于Kerberos安全认证的keytab文件和principal文件,以及多个Manager系统各自的客户端配置文件,可实现一次认证登录后访问调用多集群的HBase服务。 以下代码在hbase-example样例工程的“com.huawei.bigdata.hbase.examples”包的“TestMultipleLogin”类中。
  • 场景说明 在同一个客户端进程内同时访问 FusionInsight ZooKeeper和第三方的ZooKeeper时,为了避免访问连接ZooKeeper认证冲突,提供了样例代码使HBase客户端访问FusionInsight ZooKeeper和客户应用访问第三方ZooKeeper。 以下为“src/main/resources”目录下提供的与认证相关的配置文件。 zoo.cfg # The configuration in jaas.conf used to connect fi zookeeper.zookeeper.sasl.clientconfig=Client_new[1] # Principal of fi zookeeper server side. zookeeper.server.principal=zookeeper/hadoop.hadoop.com[2] # Set true if the fi cluster is security mode. # The other two parameters doesn't work if the value is false. zookeeper.sasl.client=true[3] [1] zookeeper.sasl.clientconfig:指定使用jaas.conf文件中的对应配置访问FusionInsight ZooKeeper; [2] zookeeper.server.principal:指定ZooKeeper服务端使用principal; [3] zookeeper.sasl.client:如果 MRS 集群是安全模式,该值设置为“true”,否则设置为“false”,设置为“false”的情况下,“zookeeper.sasl.clientconfig”和“zookeeper.server.principal”参数不生效。 jaas.conf Client_new { [4] com.sun.security.auth.module.Krb5LoginModule required useKeyTab=true keyTab="D:\\work\\sample_project\\src\\hbase-examples\\hbase-zk-example\\target\\classes\\conf\\user.keytab" [5] principal="hbaseuser1" useTicketCache=false storeKey=true debug=true; }; Client { [6] org.apache.zookeeper.server.auth.DigestLoginModule required username="bob" password="xxxxxx"; [7] }; [4] Client_new:zoo.cfg中指定的读取配置,当该名称修改时,需要同步修改zoo.cfg中对应配置。 [5] keyTab :指明工程使用的“user.keytab”在运行样例的主机上的保存路径,使用绝对路径便于更好定位文件位置。在Windows环境和Linux环境下配置时需注意区分不同操作系统路径书写方式,即“\\”与“\”差异。 [6] Client:第三方ZooKeeper使用该配置进行访问连接,具体连接认证配置由第三方ZooKeeper版本决定。 [7] password:密码明文存储存在安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全。
  • 场景说明 在安全集群环境下,各个组件之间的相互通信不能够简单的互通,而需要在通信之前进行相互认证,以确保通信的安全性。HBase应用开发需要进行ZooKeeper和Kerberos安全认证。用于ZooKeeper认证的文件为“jaas.conf”,用于Kerberos安全认证文件为keytab文件和krb5.conf文件。具体使用方法在样例代码的“README.md”中会有详细说明。 jaas.conf文件请参考获取MRS应用开发样例工程,进入“src/hbase-examples/hbase-zk-example/src/main/resources/”路径下获取。 keytab和krb5.conf文件获取方法请参考准备MRS应用开发用户。 安全认证主要采用代码认证方式。支持Oracle JAVA平台和IBM JAVA平台。 以下代码在“com.huawei.bigdata.hbase.examples”包的“TestMain”类中。