Hiveserver2 Beeline连接设置用户名和密码 您所在的位置:网站首页 line的用户名 Hiveserver2 Beeline连接设置用户名和密码

Hiveserver2 Beeline连接设置用户名和密码

2024-07-02 08:18| 来源: 网络整理| 查看: 265

目录 摘要一、自定义权限认证类1.JAVA端代码2.POM代码 二、Hive中进行相应配置三、Hadoop中进行相应配置四、重启HDFS五、重启Hiveserver2

摘要

你好! 本文将详细介绍如何在Hive中设置用户名和密码,从而保证连接的鉴权。基本思路是先自定义一个权限认证类接收用户名和密码,打成jar包后放到到HIVE的Lib目录下,然后配置Hive的配置文件和Hadoop的配置文件即可。

一、自定义权限认证类 1.JAVA端代码

下面展示的 代码段是完整的,可以直接复制使用.或者可以直接从本站点下载Jar包。

package org.jt; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hive.conf.HiveConf; import org.slf4j.Logger; import javax.security.sasl.AuthenticationException; public class CustomPasswdAuthenticator implements org.apache.hive.service.auth.PasswdAuthenticationProvider{ private Logger LOG = org.slf4j.LoggerFactory.getLogger(CustomPasswdAuthenticator.class); private static final String HIVE_JDBC_PASSWD_AUTH_PREFIX="hive.jdbc_passwd.auth.%s"; private Configuration conf=null; @Override public void Authenticate(String userName, String passwd) throws AuthenticationException { LOG.info("Hive2 login info... user: "+ userName +" is trying login."); String passwdConf = getConf().get(String.format(HIVE_JDBC_PASSWD_AUTH_PREFIX, userName)); if(passwdConf==null){ String message = "Hive2 login error! Configration null. user:"+userName; LOG.info(message); throw new AuthenticationException(message); } if(!passwd.equals(passwdConf)){ String message = "Hive2 login error! userName or password is error. user:"+userName; throw new AuthenticationException(message); } } public Configuration getConf() { if(conf==null){ this.conf=new Configuration(new HiveConf()); } return conf; } public void setConf(Configuration conf) { this.conf=conf; } } 2.POM代码

下面展示的 代码段是核心片段,您只需要复制到你的POM.XML中即可。

org.apache.hive hive-jdbc 3.1.2 二、Hive中进行相应配置

修改hive目录下的conf文件夹中的hive-site.xml文件

hive.server2.authentication CUSTOM hive.server2.custom.authentication.class jt.CustomPasswdAuthenticator hive.jdbc_passwd.auth.root admin hive.server2.thrift.port 10000 hive.server2.thrift.bind.host localhost hive.server2.enable.doAs false hive.server2.active.passive.ha.enable true Whether HiveServer2 Active/Passive High Availability be enabled when Hive Interactive sessions are enabled.This will also require hive.server2.support.dynamic.service.discovery to be enabled. 三、Hadoop中进行相应配置

进入到hadoop配置文件目录:hadoop/etc/hadoop,修改hadoop:core-site.xml,否则java连接hive没权限;

hadoop.proxyuser.root.hosts * hadoop.proxyuser.root.groups * 四、重启HDFS

配置完Hadoop后,一定要重启HDFS,不然不会生效。

五、重启Hiveserver2

Hadoop重启完成后,重启Hiveserver2,不然不会生效。进入Beeline终端进行连接即可。

以上就是本文的全部内容了,感谢支持,祝好!



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有