Kerberos启动HDFS报错,java.io.FileNotFoundException: /etc/security/serverKeys/keystore.jks
因为配置了dfs.http.policy=HTTPS_ONLY,https要求集群中有一个CA,它会生成ca_key和ca_cert,想要加入这个集群的节点,需要拿到这2个文件,然后经过一连串的动作生成keystore,并在hadoop的ssl-server.xml和ssl-client.xml中指定这个keystore的路径和密码,这样各个节点间就可以使用https进行通信了
通过OpenSSL创建内部CA
1、在CA机器上创建CA(Certificate Authority)
openssl req -new -x509 -keyout ca-key -out ca-cert -days9999
将上面生成的ca-key和ca-cert丢到所有机器上,在各个机器上执行如下步骤:
1)、使用keytool命名创建key和certificate(each node in the cluster)
keytool -keystore keystore.jks -alias localhost -validity 9999 -genkey -keyalg RSA -keysize 2048
注意: -keyalg
RSA -keysize 2048
是必须的, 否则默认会生成 DSA 类型的. 而现在的浏览器一般不支持 DSA 类型, 当用浏览器访问 https 的 NameNode web 服务时, 可能不能访问.
2)、添加CA到server's truststore
keytool -keystore all.jks -alias CARoot -import -file ca-cert
3)、同上,添加CA到client's truststore,让客户端知道他们信任的CA
keytool -keystore all.jks -alias CARoot -import -file ca-cert
4)、签名所有证书
从keystore导出证书:
keytool -keystore keystore.jks -alias localhost -certreq -file cert-file
签名证书(带CA)
openssl x509 -req -CA ca-cert -CAkey ca-key -in cert-file -out cert-signed -days9999 -CAcreateserial -passin pass:<ca-password>
4、导入CA证书,签名证书到keystore
$ keytool -keystore keystore.jks -alias CARoot -import -file ca-cert
$ keytool -keystore keystore.jks -alias localhost -import -file cert-signed
最终在当前目录下会生成keystore.jks、all.jks文件。
在ssl-client机器上,新建/etc/security/clientKeys目录,将keystore.jks、all.jks移至此目录下(包括ssl-server机器);
在ssl-server机器上,将keystore.jks、all.jks移到/etc/security/serverKeys目录下,并且分发到其他机器上。
记住:在Ambari界面的HDFS配置ssl相关参数修改对应的密码,重启HDFS服务即可。
Comman Name非常重要,前后需保持一致(否则会出现https访问不了情况,上述仅举例,个人实际情况配置成CA服务器地址)。
有关CA服务器搭建参考:http://soysauce93.blog.51cto.com/7589461/1725318
其他可参考链接:
http://secfree.github.io/blog/2015/07/01/sasl-data-transfer-protocol.html
http://www.cnblogs.com/kisf/p/7573561.html