1 配置KDC之间的信任ticket
两个域分别登录kadmin.local,分别执行下面的语句创建principal
kadmin.local: addprinc -e "aes256-cts:normal aes128-cts:normal des3-hmac-sha1:normal arcfour-hmac:normal des-hmac-sha1:normal des-cbc-md5:normal des-cbc-crc:normal" krbtgt/HADOOP.COM@CMSERVER.COM
WARNING: no policy specified for krbtgt/HADOOP.COM@CMSERVER.COM; defaulting to no policy
Enter password for principal "krbtgt/HADOOP.COM@CMSERVER.COM": admin
Re-enter password for principal "krbtgt/HADOOP.COM@CMSERVER.COM": admin
Principal "krbtgt/HADOOP.COM@CMSERVER.COM" created.
kadmin.local: addprinc -e "aes256-cts:normal aes128-cts:normal des3-hmac-sha1:normal arcfour-hmac:normal des-hmac-sha1:normal des-cbc-md5:normal des-cbc-crc:normal" krbtgt/CMSERVER.COM@HADOOP.COM
WARNING: no policy specified for krbtgt/CMSERVER.COM@HADOOP.COM; defaulting to no policy
Enter password for principal "krbtgt/CMSERVER.COM@HADOOP.COM": admin
Re-enter password for principal "krbtgt/CMSERVER.COM@HADOOP.COM": admin
Principal "krbtgt/CMSERVER.COM@HADOOP.COM" created.
验证两个entries具有匹配的kvno和加密type,查看命令使用getprinc <principal_name>
```powershell
kadmin.local: getprinc krbtgt/CMSERVER.COM@HADOOP.COM
Principal: krbtgt/CMSERVER.COM@HADOOP.COM
Expiration date: [never]
Last password change: Wed May 15 09:00:25 CST 2019
Password expiration date: [none]
Maximum ticket life: 1 day 00:00:00
Maximum renewable life: 0 days 00:00:00
Last modified: Wed May 15 09:00:25 CST 2019 (hbase/admin@CMSERVER.COM)
Last successful authentication: [never]
Last failed authentication: [never]
Failed password attempts: 0
Number of keys: 6
Key: vno 1, aes256-cts-hmac-sha1-96, no salt
Key: vno 1, aes128-cts-hmac-sha1-96, no salt
Key: vno 1, des3-cbc-sha1, no salt
Key: vno 1, arcfour-hmac, no salt
Key: vno 1, des-hmac-sha1, no salt
Key: vno 1, des-cbc-md5, no salt
MKey: vno 1
Attributes:
Policy: [none]
kadmin.local: getprinc krbtgt/HADOOP.COM@CMSERVER.COM
Principal: krbtgt/HADOOP.COM@CMSERVER.COM
Expiration date: [never]
Last password change: Wed May 15 08:59:37 CST 2019
Password expiration date: [none]
Maximum ticket life: 1 day 00:00:00
Maximum renewable life: 0 days 00:00:00
Last modified: Wed May 15 08:59:37 CST 2019 (hbase/admin@CMSERVER.COM)
Last successful authentication: [never]
Last failed authentication: [never]
Failed password attempts: 0
Number of keys: 6
Key: vno 1, aes256-cts-hmac-sha1-96, no salt
Key: vno 1, aes128-cts-hmac-sha1-96, no salt
Key: vno 1, des3-cbc-sha1, no salt
Key: vno 1, arcfour-hmac, no salt
Key: vno 1, des-hmac-sha1, no salt
Key: vno 1, des-cbc-md5, no salt
MKey: vno 1
Attributes:
Policy: [none]
## 2 在core-site中配置principal和user的映射RULES
分别在两个hdfs配置文件中添加受信任的kerberos领域
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190619150913385.png)
设置hadoop.security.auth_to_local参数,该参数用于将principal转变为user,一个需要注意的问题是SASL RPC客户端需要远程Server的Kerberos principal在本身的配置中匹配该principal。相同的pricipal name需要分配给源和目标cluster的服务,例如Source Cluster中的NameNode的kerbeors principal name为nn/h@CMSERVER.COM,在Destination cluster中NameNode的pricipal设置为nn/h@HADOOP.COM(不能设置为nn2/h***@HADOOP.COM),例如:
在CMSERVER Cluster和 HADOOP Cluster的core-site中增加:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190619150942266.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM3Njg0NDgx,size_16,color_FFFFFF,t_70)
使用hadoop org.apache.hadoop.security.HadoopKerberosName <principal-name>来实现验证,例如:
hadoop org.apache.hadoop.security.HadoopKerberosName hdfs/linux1@CMSERVER.COM
Name: hdfs/linux1@CMSERVER.COM to hdfs
## 3 在krb5.conf中配置信任关系
**3.1 配置capaths**
第一种方式是配置shared hierarchy of names,这个是默认及比较简单的方式,第二种方式是在krb5.conf文件中改变capaths,复杂但是比较灵活,这里采用第二种方式。
在两个集群的节点的/etc/krb5.conf文件配置domain和realm的映射关系,例如:在CMSERVER cluster中配置:
**3.2 配置realms**
3.3 配置domain_realm
192.168.0.201的/etc/krb5.conf具体配置为
[libdefaults]
default_realm = CMSERVER.COM
dns_lookup_kdc = false
dns_lookup_realm = false
ticket_lifetime = 86400
renew_lifetime = 604800
forwardable = true
default_tgs_enctypes = rc4-hmac
default_tkt_enctypes = rc4-hmac
permitted_enctypes = rc4-hmac
udp_preference_limit = 1
kdc_timeout = 3000
[realms]
CMSERVER.COM = {
kdc = linux1
admin_server = linux1
default_domain = CMSERVER.COM
}
HADOOP.COM = {
kdc = linux5
admin_server = linux5
default_domain = HADOOP.COM
}
[domain_realm]
linux1 = CMSERVER.COM
linux3 = HADOOP.COM
linux4 = HADOOP.COM
linux5 = HADOOP.COM
linux6 = HADOOP.COM
[capaths]
CMSERVER.COM = {
HADOOP.COM = .
}
192.168.0.203, 192.168.0.204, 192.168.0.205, 192.168.0.206的配置为
[libdefaults]
default_realm = HADOOP.COM
dns_lookup_kdc = false
dns_lookup_realm = false
ticket_lifetime = 86400
renew_lifetime = 604800
forwardable = true
default_tgs_enctypes = rc4-hmac
default_tkt_enctypes = rc4-hmac
permitted_enctypes = rc4-hmac
udp_preference_limit = 1
kdc_timeout = 3000
[realms]
CMSERVER.COM = {
kdc = linux1
admin_server = linux1
default_domain = CMSERVER.COM
}
HADOOP.COM = {
kdc = linux5
admin_server = linux5
default_domain = HADOOP.COM
}
[domain_realm]
linux1 = CMSERVER.COM
linux3 = HADOOP.COM
linux4 = HADOOP.COM
linux5 = HADOOP.COM
linux6 = HADOOP.COM
[capaths]
HADOOP.COM = {
CMSERVER.COM = .
}
3.4 配置hdfs-site.xml
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190619150959566.png)
这个是客户端的匹配规则用于控制允许的认证realms,如果该参数不配置,会有下面的异常:
java.io.IOException: Failed on local exception: java.io.IOException:
java.lang.IllegalArgumentException:
Server has invalid Kerberosprincipal:nn/ HADOOP.COM@ XDF.COM;
Host Details : local host is: "host1.XDF.COM/10.181.22.130";
destination host is: "host2.HADOOP.COM":8020;
## 4 配置生效
4.1在cloudera manager监控页面关闭集群
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190619151010902.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM3Njg0NDgx,size_16,color_FFFFFF,t_70)
关闭监控页面
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190619151016580.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM3Njg0NDgx,size_16,color_FFFFFF,t_70)
4.2重新生成keytab
在上方导航栏点击管理-安全-kerberos凭据
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190619151023626.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM3Njg0NDgx,size_16,color_FFFFFF,t_70)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190619151030241.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM3Njg0NDgx,size_16,color_FFFFFF,t_70)
全选-重新生成所选项
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190619151035730.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM3Njg0NDgx,size_16,color_FFFFFF,t_70)
生成完成后启动服务器