Cloudera 6.x 手工配置TLS加密

Cloudera是用于管理Hadoop集群的利器。按照安全规范,相关Web界面需要使用HTTPS。如果不小心选择了auto-TLS,则会出现以下问题:

Installation failed. Failed to receive heartbeat from agent.
Ensure that the host’s hostname is configured properly.
Ensure that port 7182 is accessible on the Cloudera Manager Server (check firewall rules).
Ensure that ports 9000 and 9001 are not in use on the host being added.
Check agent logs in /var/log/cloudera-scm-agent/ on the host being added. (Some of the logs can be found in the installation details).
If Use TLS Encryption for Agents is enabled in Cloudera Manager (Administration -> Settings -> Security), ensure that /etc/cloudera-scm-agent/config.ini has use_tls=1 on the host being added. Restart the corresponding agent and click the Retry link here.

原因在于,auto-TLS需要license支持:

An Enterprise license is required to enable Auto-TLS.

虽然官方提供了手工设置的文档how_to_configure_cm_tls,但我实操下来发现问题非常多。本文将结合官方文档,手把手地教你如何配置。环境为CentOS 7 + Cloudera 6.3。

0. 搭建CA服务器

如果已有CA的,这一步可以忽略。如果没有,找一台服务器作为CA。
编辑/etc/pki/tls/openssl.cnf,修改以下内容:

basicConstraints=CA:TRUE
copy_extensions=copy
string_mask=pkix

第一行将本机变为CA;第二、三行如果没有,Cloudera生成证书请求在此会报错。
初始化:/etc/pki/tls/misc/CA -newca
过程中会提示输入CA根证书密码,要牢记此密码。

1. 生成证书

这部分对应官方文档Generate TLS Certificates

(1) 生成Java证书

在Cloudera集群的每台机器上执行。

mkdir -p /opt/cloudera/security/pki
$JAVA_HOME/bin/keytool\
	-genkeypair\
	-alias $(hostname -f)\
	-keyalg RSA\
	-keystore /opt/cloudera/security/pki/$(hostname -f).jks\
	-keysize 2048\
	-dname "CN=$(hostname -f),OU=Engineering,O=Cloudera,L=Palo Alto,ST=California,C=US"\
	-ext san=dns:$(hostname -f)\
	-keypass your_key_store_pass\
	-storepass your_key_store_pass

其中:

  • dname中OU/O/L/ST/C随便设置;
  • Cloudera规定keypass和storepass必须一样,记住这个密码,以后会多次使用。
(2) 将Java证书格式转为p12

在Cloudera集群的每台机器上执行。

$JAVA_HOME/bin/keytool\
   -importkeystore\
   -srckeystore /opt/cloudera/security/pki/$(hostname -f).jks\
   -destkeystore /opt/cloudera/security/pki/$(hostname -f).p12\
   -deststoretype pkcs12\
   -srcstorepass your_key_store_pass\
   -srckeypass your_key_store_pass\
   -destkeypass your_key_store_pass\
   -srcalias $(hostname -f)\
   -destalias $(hostname -f)
mv /opt/cloudera/security/pki/$(hostname -f).p12 /opt/cloudera/security/pki/$(hostname -f).jks

其中:your_key_store_pass即为1.1中设置的密码。

(3) 生成证书请求

在Cloudera集群的每台机器上执行。

$JAVA_HOME/bin/keytool\
	-certreq\
	-alias $(hostname -f)\
	-keystore  $(hostname -f).jks\
	-file /opt/cloudera/security/pki/$(hostname -f).csr\
	-ext san=dns:$(hostname -f)\
	-ext EKU=serverAuth,clientAuth

然后把生成的.csr传到CA服务器。

(4) 签发证书

在CA服务器上对每个.csr文件执行。以node0.csr为例:

openssl ca\
	-keyfile /etc/pki/CA/private/cakey.pem\
	-cert /etc/pki/CA/cacert.pem\
	-days 3650\
	-in node0.csr\
	-out node0.pem

其中:

  • days为证书有效期;
  • 签发时会要求输入CA根证书密码。
    完成后,将node0.pem和/etc/pki/CA/cacert.pem一起传到node0的/opt/cloudera/security/pki目录下。
(5) 合并完整的证书

这一步是官方文档里缺失的。在Cloudera集群的每台机器上执行。

cat /opt/cloudera/security/pki/cacert.pem /opt/cloudera/security/pki/$(hostname -f).pem >> /opt/cloudera/security/pki/$(hostname -f).crt
chown cloudera-scm:cloudera-scm /opt/cloudera/security/pki/$(hostname -f).crt
chown cloudera-scm:cloudera-scm /opt/cloudera/security/pki/$(hostname -f).pem
(6) 将根证书导入Java根证书存储

为了不影响机器上的其他Java应用,我们生成一个Cloudera专用的Java根证书存储,其路径在后续2的配置中会用到。在Cloudera集群的每台机器上执行。

cp $JAVA_HOME/jre/lib/security/cacerts /opt/cloudera/security/pki/cacerts
chown cloudera-scm:cloudera-scm /opt/cloudera/security/pki/cacerts
$JAVA_HOME/bin/keytool\
	-importcert\
	-alias rootca\
	-keystore /opt/cloudera/security/pki/cacerts\
	-file /opt/cloudera/security/pki/cacert.pem\
	-storepass your_ca_store_pass\
	-noprompt

其中:storepass若未修改过则为changeit。

(7) 将证书导入Java证书存储

在Cloudera集群的每台机器上执行。

$JAVA_HOME/bin/keytool\
	-importcert\
	-alias $(hostname -f)\
	-file /opt/cloudera/security/pki/$(hostname -f).crt\
	-keystore /opt/cloudera/security/pki/$(hostname -f).jks\
	-storepass your_key_store_pass\
	-noprompt
chown cloudera-scm:cloudera-scm /opt/cloudera/security/pki/$(hostname -f).jks
chmod 755 /opt/cloudera/security/pki/$(hostname -f).jks

至此,证书就制作好了。

2. 管理界面启用HTTPS

这一部分比较简单,参考官方文档Configure TLS for the Cloudera Manager Admin Console操作即可。

3. 服务器agent启用TLS

这一部分基本按照官方文档Configure TLS for Cloudera Manager Agents即可。只有一个地方需要注意:agent配置文件/etc/cloudera-scm-agent/config.ini中,必须使用

[General]
server_host=your_server_hostname

而不能使用

[General]
server_host=your_server_hostip

因为证书里我们使用的是主机名,这里使用IP会导致证书认证失败。
更奇怪的是,有时你已配置使用主机名,启动后也会被替换成IP。所以出现agent连接不上管理服务器时要关注这一配置项。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值