Hadoop Web 控制台安全认证


前言

Hadoop 2.x 版本,默认情况下,可以通过 http://ip地址:50070/explorer.html 访问HDFS页面,查看Namenode和Datanode状态,以及HDFS的相关文件等。但是这存在安全隐患,可能导致我们的文件信息的泄露,如果我们在页面里面添加个认证机制,只有验证之后的用户才可以进入页面里操作。

一、修改Hadoop的web.xml配置文件

文件路径: /usr/hdp/2.5.3.0-37/hadoop-hdfs/webapps/hdfs/WEB-INF
执行 cat web.xml 可查看原有配置如下
在这里插入图片描述
编辑web.xml,填入以下内容(这是我的配置, role-name 要根据自己的实际情况配置,我的hadoop用户是在rootgroup下的,所以填root):

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
 
     http://www.apache.org/licenses/LICENSE-2.0
 
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->
<web-app version="2.4" xmlns=" http://java.sun.com/xml/ns/j2ee ">
    <!-- Add this towards the bottom of the xml document. -->
    <security-constraint>
 

        <web-resource-collection>
            <web-resource-name>Protected</web-resource-name>
            <url-pattern>/*</url-pattern>    <!--  这是正在被保护的路径,当前设定的是root路径下的web ui -->
        </web-resource-collection>
        <auth-constraint>
            <role-name>root</role-name>   <!--  hadoop用户的组名 -->
        </auth-constraint>
    </security-constraint>
    <login-config>
        <auth-method>BASIC</auth-method>  <!-- HTTP规范,Base64 编码方式, 采用Base64编码具有不可读性,需要解码后才能阅读。-->
        <realm-name>jobtrackerRealm</realm-name>  <!-- 这个名称要和下面jetty里的name一致-->
      </login-config>
</web-app>

二、配置jetty-web.xml

和web.xml在同一个文件夹下,如果没有,则新增一个,填入以下内容

<Configure class="org.mortbay.jetty.webapp.WebAppContext">
  <Get name="securityHandler">
    <Set name="userRealm">
      <New class="org.mortbay.jetty.security.HashUserRealm">
        <Set name="name">jobtrackerRealm</Set>  <!-- 这个名称要和上面web里的realm-name一致-->
        <Set name="config">
                <SystemProperty name="hadoop.home.dir"/>/etc/hadoop/realm.properties  <!-- 存放用户和用户密码的地方-->
        </Set>
      </New>
    </Set>
  </Get>
</Configure>

/etc/hadoop/realm.properties是配置用户名密码的文件

三、配置realm.properties文件

在 jetty-web.xml 配置的路径下,/etc/hadoop/realm.properties ,这个文件是没有 的,要先创建。

cd /etc/hadoop
touch realm.properties

添加用户名,密码,用户组

vi /etc/hadoop/realm.properties

hadoop:hadoop,hadoop

在这里插入图片描述
一个用户密码一行,要配置多个,就多行,并将文件copy到/etc/hadoop/2.5.3.0-37/0/目录下,并修改文件权限。

cp /etc/hadoop/realm.properties /etc/hadoop/2.5.3.0-37/0/
chmod 755 /etc/hadoop/2.5.3.0-37/0/realm.properties

四、重启namenode,使认证生效

这里建议先重启standbynamenode,然后主从切换,重启切下来的standbynamenode,不要直接重启active的namenode

五、登录Hadoop Web页面验证

出现用户名和密码验证弹窗即设置成功!
在这里插入图片描述


大家好,我是徐小慧
📢 博客主页:徐小慧_Blog
📢 欢迎 点赞 👍 | 收藏 ⭐ | 留言 📝 如有错误敬请指正!

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值