Hadoop集群安装HTTPS服务

Hadoop集群安装HTTPS服务安装说明 我是自己搭建的三台虚拟机 hadoop01 hadoop02 hadoop03 生成 CA 证书 hdfs ca key 和 hdfs ca cert 只需要在任意一台节点上完成即可 其他每个节点包括生成证书的节点都需要执行第四步以后的操作 且必须使用 root 用户执行以下操作 1 在 hadoop01 节点生成 CA 证书 需要输入两次密码 其中 CN 中国简称 ST 省份 L 城市 O 和 OU 公司或个人域

安装说明:我是自己搭建的三台虚拟机hadoop01/hadoop02/hadoop03,生成CA证书hdfs_ca_key和hdfs_ca_cert只需要在任意一台节点上完成即可,其他每个节点包括生成证书的节点都需要执行第四步以后的操作,且必须使用root用户执行以下操作:

1.在hadoop01节点生成CA证书,需要输入两次密码,其中CN:中国简称;ST:省份;L:城市;O和OU:公司或个人域名;hadoop01是生成CA证书主机名

openssl req -new -x509 -keyout hdfs_ca_key -out hdfs_ca_cert -days 9999 -subj /C=CN/ST=shanxi/L=xian/O=hlk/OU=hlk/CN=hadoop01

2.将hadoop01节点上生成的CA证书hdfs_ca_key、hdfs_ca_cert分发到每个节点上的/tmp目录下

scp hdfs_ca_key hdfs_ca_cert $host:/tmp

3.发送完成后删除hadoop01节点上CA证书

rm -rf hdfs_ca_key hdfs_ca_cert 
name="CN=$HOSTNAME, OU=hlk, O=hlk, L=xian, ST=shanxi, C=CN" #需要输入第一步输入的密码四次 keytool -keystore keystore -alias localhost -validity 9999 -genkey -keyalg RSA -keysize 2048 -dname "$name"

   4.2 添加CA到truststore,同样需要输入密码

keytool -keystore truststore -alias CARoot -import -file hdfs_ca_cert

   4.3 从keystore中导出cert

keytool -certreq -alias localhost -keystore keystore -file cert

   4.4 用CA对cert签名

openssl x509 -req -CA hdfs_ca_cert -CAkey hdfs_ca_key -in cert -out cert_signed -days 9999 -CAcreateserial

   4.5 将CA的cert和用CA签名之后的cert导入keystore

 keytool -keystore keystore -alias CARoot -import -file hdfs_ca_cert  keytool -keystore keystore -alias localhost -import -file cert_signed

   4.6 将最终keystore,trustores放入合适的目录,并加上后缀jks

 mkdir -p /etc/security/https && chmod 755 /etc/security/https  cp keystore /etc/security/https/keystore.jks  cp truststore /etc/security/https/truststore.jks

   4.7 删除/tmp目录下产生的垃圾数据文件

rm -f keystore truststore hdfs_ca_key hdfs_ca_cert.srl hdfs_ca_cert cert_signed cert

5.配置$HADOOP_HOME/etc/hadoop/ssl-server.xml和ssl-client.xml文件

  :这两个配置文件在一台节点配好,发送到其他节点对应位置下!

  5.1 配置$HADOOP_HOME/etc/hadoop/ssl-client.xml文件

 ssl-client.xml 
  
         
   
            
    
      ssl.client.truststore.location 
            
    
      /etc/security/https/truststore.jks 
            
    
      Truststore to be used by clients like distcp. Must be specified. 
          
              
   
            
    
      ssl.client.truststore.password 
            
    
      hadoop 
            
    
      Optional. Default value is "". 
          
         
   
            
    
      ssl.client.truststore.type 
            
    
      jks 
            
    
      Optional. The keystore file format, default value is "jks". 
          
         
   
            
    
      ssl.client.truststore.reload.interval 
            
    
      10000 
            
    
      Truststore reload check interval, in milliseconds.Default value is 10000 (10 seconds). 
          
         
   
            
    
      ssl.client.keystore.location 
            
    
      /etc/security/https/keystore.jks 
            
    
      Keystore to be used by clients like distcp. Must be specified. 
          
         
   
            
    
      ssl.client.keystore.password 
            
    
      hadoop 
            
    
      Optional. Default value is "". 
          
         
   
            
    
      ssl.client.keystore.keypassword 
            
    
      hadoop 
            
    
      Optional. Default value is "". 
          
         
   
            
    
      ssl.client.keystore.type 
            
    
      jks 
            
    
      Optional. The keystore file format, default value is "jks". 
          
    
  

  5.2 配置$HADOOP_HOME/etc/hadoop/ssl-server.xml文件

 ssl-server.xml 
   
    
    
      ssl.server.truststore.location 
     
    
      /etc/security/https/truststore.jks 
     
    
      Truststore to be used by NN and DN. Must be specified. 
     
    
    
    
      ssl.server.truststore.password 
     
    
      hadoop 
     
    
      Optional. Default value is "". 
     
    
    
    
      ssl.server.truststore.type 
     
    
      jks 
     
    
      Optional. The keystore file format, default value is "jks". 
     
    
    
    
      ssl.server.truststore.reload.interval 
     
    
      10000 
     
    
      Truststore reload check interval, in milliseconds. Default value is 10000 (10 seconds). 
     
    
    
    
      ssl.server.keystore.location 
     
    
      /etc/security/https/keystore.jks 
     
    
      Keystore to be used by NN and DN. Must be specified. 
     
    
    
    
      ssl.server.keystore.password 
     
    
      hadoop 
     
    
      Must be specified. 
     
    
    
    
      ssl.server.keystore.keypassword 
     
    
      hadoop 
     
    
      Must be specified. 
     
    
    
    
      ssl.server.keystore.type 
     
    
      jks 
     
    
      Optional. The keystore file format, default value is "jks". 
     
    
  

PS:因为上述操作中需要不停的输入密码,有太多的人机交互,而且集群节点多了也太过于麻烦,所以本人写了一个shell脚本,可以直接运行安装HTTP服务,仅供需要的人参考!

#! /bin/bash #集群中安装https function make_CA(){ echo 'make_CA begin ...' cd ~ #删除之前可能产生的过期CA证书 rm -rf hdfs_ca* #hadoop01上生成CA,密码全部为hadoop /usr/bin/expect <<-EOF set timeout 30 spawn openssl req -new -x509 -keyout hdfs_ca_key -out hdfs_ca_cert -days 9999 -subj /C=CN/ST=shanxi/L=xian/O=hlk/OU=hlk/CN=hadoop01 expect { "*PEM pass phrase*" {send "hadoop\r"; exp_continue} "*Enter PEM pass phrase:*" { send "hadoop\r"; exp_continue} } EOF #将hadoop01节点上生成的CA证书hdfs_ca_key、hdfs_ca_cert分发到其他节点上 hosts=`sed -n 3,5p /etc/hosts | awk '{print $2}'` for host in $hosts; do echo "copy hadoop CA to $host:/tmp" scp hdfs_ca_* $host:/tmp done rm -rf hdfs_ca* echo 'make_CA end ...' } #在每一条机器上生成keystore和trustores function make_certificate(){ cd /tmp #keytool需要使用java环境 source /home/hadoop/.bashrc #生成keystore name="CN=$HOSTNAME, OU=hlk, O=hlk, L=xian, ST=shanxi, C=CN" /usr/bin/expect <<-EOF spawn keytool -keystore keystore -alias localhost -validity 9999 -genkey -keyalg RSA -keysize 2048 -dname "$name" expect { "*keystore password*" {send "hadoop\r"; exp_continue} "*new password:*" {send "hadoop\r"; exp_continue} "*as keystore password):*" {send "hadoop\r"; exp_continue} "*Re-enter new password:*" {send "hadoop\r"; exp_continue} } EOF #添加CA到truststore /usr/bin/expect <<-EOF spawn keytool -keystore truststore -alias CARoot -import -file hdfs_ca_cert expect { "*keystore password:*" {send "hadoop\r"; exp_continue} "*new password:*" {send "hadoop\r"; exp_continue} "*Trust this certificate*" {send "yes\r"; exp_continue} } EOF #从keystore中导出cert /usr/bin/expect <<-EOF spawn keytool -certreq -alias localhost -keystore keystore -file cert expect { "*keystore password:*" {send "hadoop\r"; exp_continue} } EOF #用CA对cert签名 /usr/bin/expect <<-EOF spawn openssl x509 -req -CA hdfs_ca_cert -CAkey hdfs_ca_key -in cert -out cert_signed -days 9999 -CAcreateserial expect { "*phrase for hdfs_ca_key:*" {send "hadoop\r"; exp_continue} } EOF #将CA的cert和用CA签名之后的cert导入keystore /usr/bin/expect <<-EOF spawn keytool -keystore keystore -alias CARoot -import -file hdfs_ca_cert expect { "*keystore password:*" {send "hadoop\r"; exp_continue} "*Trust this certificate*" {send "yes\r"; exp_continue} } EOF /usr/bin/expect <<-EOF spawn keytool -keystore keystore -alias localhost -import -file cert_signed expect { "*keystore password:*" {send "hadoop\r"; exp_continue} } EOF #将最终keystore,trustores放入合适的目录,并加上后缀jks rm -rf /etc/security/https && mkdir -p /etc/security/https chmod 755 /etc/security/https echo "install keystore、truststore to /etc/security/https/..." cp keystore /etc/security/https/keystore.jks cp truststore /etc/security/https/truststore.jks #删除产生的垃圾数据文件 rm -f keystore truststore hdfs_ca_key hdfs_ca_cert.srl hdfs_ca_cert cert_signed cert } function main(){ echo "[+] execute hlk_each_host_install_https.sh begin ..." #必须使用root用户执行 if [ "x$USER" != "xroot" ];then echo "[-] Installation of HTTPS must be performed with the root user ..." return fi if [ "x$HOSTNAME" == "xhadoop01" ];then #只在hadoop01节点上安装CA证书 make_CA fi #每个节点获取CA证书签照 make_certificate #配置$HADOOP_HOME/etc/hadoop/下的ssl-server.xml和ssl-client.xml配置文件 cp /home/hadoop/conf/hadoop/ssl-*.xml /home/hadoop/core/hadoop-2.7.6/etc/hadoop/ echo "[+] execute hlk_each_host_install_https.sh end ..." } main

     如果对你有过帮助,请记得留下你宝贵的赞,给我继续记录的动力!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/201317.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月20日 上午9:36
下一篇 2026年3月20日 上午9:37


相关推荐

  • oracle数据库的备份与恢复_数据库备份文件怎么恢复

    oracle数据库的备份与恢复_数据库备份文件怎么恢复Oracle的备份与恢复有三种标准的模式,大致分为两大类,备份恢复(物理上的)以及导入导出(逻辑上的),而备份恢复又可以根据数据库的工作模式分为非归档模式(Nonarchivelog-style)和归档模式(Archivelog-style),通常,我们把非归档模式称为冷备份,而相应的把归档模式称为热备份,他们的关系如下所示备份与恢复

    2025年6月14日
    4
  • java中Map的用法

    java中Map的用法Map是java中的接口,Map.Entry是Map的一个内部接口。Map提供了一些常用方法,如keySet()、entrySet()等方法。keySet()方法返回值是Map中key值的集合;entrySet()的返回值也是返回一个Set集合,此集合的类型为Map.Entry。Map.Entry是Map声明的一个内部接口,此接口为泛型,定义为Entry<K,V>。它表示Map中的一个实体(一个key-value对)。接口中有getKey(),getValue方法。Map<Stri

    2022年7月9日
    25
  • jsp el jstl_servlet还有人用吗

    jsp el jstl_servlet还有人用吗EL表达式EL表达式的作用:EL表达式主要是代替jsp页面中的表达式脚本在jsp页面中进行数据输出。因为EL表达式在输出数据的时候,要比jsp表达式脚本要简洁的多格式$(表达式)<%@ page import=”java.util.Map” %><%@ page import=”java.util.HashMap” %><%@ page contentType=”text/html;charset=UTF-8″ language=”java” %><h

    2022年8月8日
    11
  • u盘文件夹exe病毒彻底_u盘中病毒文件变成快捷方式怎么办

    u盘文件夹exe病毒彻底_u盘中病毒文件变成快捷方式怎么办笔者在使用U盘时,无意之间发现U盘所有文件的后缀名均变为“.exe”,经过查询相关资料,确认这是一种病毒(文件夹EXE病毒)一、简介:木马名称:Worm.Win32.AutoRun.soq,当把U盘插入到一台电脑后,U盘内生成了以原文件夹名字命名的文件,且扩展名为exe,其原理是把原来的文件隐藏,重新生成同名的exe文件。二、解决方案:百度下载USBCleaner,根据软件提示进行操作即可完…

    2025年7月29日
    5
  • Time Wait的作用、原因、影响和如何避免

    Time Wait的作用、原因、影响和如何避免TIME_WAIT示例图:1、time_wait的作用:TIME_WAIT状态存在的理由:1)可靠地实现TCP全双工连接的终止  在进行关闭连接四次挥手协议时,最后的ACK是由主动关闭端发出的,如果这个最终的ACK丢失,服务器将重发最终的FIN,因此客户端必须维护状态信息允许它重发最终的ACK。如果不维持这个状态信息,那么客户端将响应RST分节,服务器将此分节解释成一个错误(…

    2022年6月7日
    68
  • Python爬虫—-网页下载器和urllib2模块及对应的实例

    Python爬虫—-网页下载器和urllib2模块及对应的实例网页下载器:将互联网上URL对应的网页下载到本地的工具,是爬虫的核心组件未完。。。

    2022年5月8日
    41

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号