兩個hadoop集羣開啓Kerberos驗證後,集羣間不可以相互訪問,須要實現Kerberos之間的互信,使用hera集羣A的客戶端訪問hera集羣B的服務(實質上是使用Kerberos Realm A上的Ticket實現訪問Realm B的服務)。
先決條件:
1)兩個集羣hera.com和yoga.com均開啓Kerberos認證
2)Kerberos的REALM分別設置爲hera.com和yoga.com
步驟以下:java
實現hera.com和yoga.com之間的跨域互信,例如使用hera.com的客戶端訪問yoga.com中的服務,兩個REALM須要共同擁有名爲krbtgt/yoga.com@hera.com的principal,兩個Keys須要保證密碼,version number和加密方式一致。默認狀況下互信是單向的, yoga.com的客戶端訪問hera.com的服務,兩個REALM須要有krbtgt/hera.com@yoga.com的principal。
向兩個集羣中添加krbtgt principalnode
#hera CLUSTER
kadmin.
local
: addprinc –e
"aes128-cts:normal des3-hmac-sha1:normal arcfour-hmac:normal camellia256-cts:normal camellia128-cts:normal des-hmac-sha1:normal des-cbc-md5:normal"
krbtgt
/hera
.com@yoga.com
kadmin.
local
: addprinc –e
"aes128-cts:normal des3-hmac-sha1:normal arcfour-hmac:normal camellia256-cts:normal camellia128-cts:normal des-hmac-sha1:normal des-cbc-md5:normal"
krbtgt
/yoga
.com@hera.com
#yoga CLUSTER
kadmin.
local
: addprinc –e
"aes128-cts:normal des3-hmac-sha1:normal arcfour-hmac:normal camellia256-cts:normal camellia128-cts:normal des-hmac-sha1:normal des-cbc-md5:normal"
krbtgt
/hera
.com@yoga.com
kadmin.
local
: addprinc –e
"aes128-cts:normal des3-hmac-sha1:normal arcfour-hmac:normal camellia256-cts:normal camellia128-cts:normal des-hmac-sha1:normal des-cbc-md5:normal"
krbtgt
/yoga
.com@hera.com
|
要驗證兩個entries具備匹配的kvno和加密type,查看命令使用getprincapache
kadmin.
local
: getprinc krbtgt
/yoga
.com@hera.com
Principal: krbtgt
/yoga
.com@hera.com
Expiration
date
: [never]
Last password change: Wed Jul 05 14:18:11 CST 2017
Password expiration
date
: [none]
Maximum ticket life: 1 day 00:00:00
Maximum renewable life: 30 days 00:00:00
Last modified: Wed Jul 05 14:18:11 CST 2017 (admin
/admin
@yoga.com)
Last successful authentication: [never]
Last failed authentication: [never]
Failed password attempts: 0
Number of keys: 7
Key: vno 1, aes128-cts-hmac-sha1-96
Key: vno 1, des3-cbc-sha1
Key: vno 1, arcfour-hmac
Key: vno 1, camellia256-cts-cmac
Key: vno 1, camellia128-cts-cmac
Key: vno 1, des-hmac-sha1
Key: vno 1, des-cbc-md5
MKey: vno 1
Attributes:
Policy: [none]
kadmin.
local
: getprinc addprinc krbtgt
/hera
.com@yoga.com
usage: get_principal [-terse] principal
kadmin.
local
: getprinc krbtgt
/hera
.com@yoga.com
Principal: krbtgt
/hera
.com@yoga.com
Expiration
date
: [never]
Last password change: Wed Jul 05 14:17:47 CST 2017
Password expiration
date
: [none]
Maximum ticket life: 1 day 00:00:00
Maximum renewable life: 30 days 00:00:00
Last modified: Wed Jul 05 14:17:47 CST 2017 (admin
/admin
@yoga.com)
Last successful authentication: [never]
Last failed authentication: [never]
Failed password attempts: 0
Number of keys: 7
Key: vno 1, aes128-cts-hmac-sha1-96
Key: vno 1, des3-cbc-sha1
Key: vno 1, arcfour-hmac
Key: vno 1, camellia256-cts-cmac
Key: vno 1, camellia128-cts-cmac
Key: vno 1, des-hmac-sha1
Key: vno 1, des-cbc-md5
MKey: vno 1
Attributes:
Policy: [none]
|
設置hera.security.auth_to_local參數,該參數用於將principal轉變爲user,一個須要注意的問題是SASL RPC客戶端須要遠程Server的Kerberos principal在自己的配置中匹配該principal。相同的pricipal name須要分配給源和目標cluster的服務,例如Source Cluster中的NameNode的kerbeors principal name爲nn/h@yoga.com,在Destination cluster中NameNode的pricipal設置爲nn/h@hera.com(不能設置爲nn2/h***@hera.com),例如:
在yoga Cluster和 hera Cluster的core-site中增長:跨域
<property>
<name>hera.security.auth_to_local<
/name
>
<value>
RULE:[1:$1@$0](^.*@yoga\.com$)s/^(.*)@yoga\.com$/$1
/g
RULE:[2:$1@$0](^.*@yoga\.com$)s/^(.*)@yoga\.com$/$1
/g
RULE:[1:$1@$0](^.*@hera\.com$)s/^(.*)@hera\.com$/$1
/g
RULE:[2:$1@$0](^.*@hera\.com$)s/^(.*)@hera\.com$/$1
/g
DEFAULT
<
/value
>
<
/property
>
|
用hera org.apache.hera.security.heraKerberosName 來實現驗證,例如:bash
[root@node1a141 ~]
# hera org.apache.hera.security.heraKerberosName hdfs/nodea1a141@yoga.com
Name: hdfs
/nodea1a141
@yoga.com to hdfs
|
第一種方式是配置shared hierarchy of names,這個是默認及比較簡單的方式,第二種方式是在krb5.conf文件中改變capaths,複雜可是比較靈活,這裏採用第二種方式。
在兩個集羣的節點的/etc/krb5.conf文件配置domain和realm的映射關係,例如:在yoga cluster中配置:app
[capaths]
yoga.com = {
hera.com = .
}
|
在hera Cluster中配置:dom
[capaths]
hera.com = {
yoga.com = .
}
|
配置成'.'是表示沒有intermediate realmside
爲了是yoga 能夠訪問hera的KDC,須要將hera的KDC Server配置到yoga cluster中,以下,反之相同:oop
[realms]
yoga.com = {
kdc = {host}.yoga.com:88
admin_server = {host}.yoga.com:749
default_domain = yoga.com
}
hera.com = {
kdc = {host}.hera.com:88
admin_server = {host}.hera.com:749
default_domain = hera.com
}
|
在domain_realm中,通常配置成'.yoga.com'和'yoga.com'的格式,'.'前綴保證kerberos將全部的yoga.com的主機均映射到yoga.com realm。可是若是集羣中的主機名不是以yoga.com爲後綴的格式,那麼須要在domain_realm中配置主機與realm的映射關係,例yoga.nn.local映射爲yoga.com,須要增長yoga.nn.local = yoga.com。測試
[domain_realm]
dc07-daily-bigdata-yoga-cdh-bj01host-
748167
.host.idcvdian.com = yoga.com
dc07-daily-bigdata-yoga-cdh-bj01host-
748168
.host.idcvdian.com = yoga.com
dc07-daily-bigdata-yoga-cdh-bj01host-
748169
.host.idcvdian.com = yoga.com
dc07-daily-bigdata-yoga-cdh-bj01host-
748170
.host.idcvdian.com = yoga.com
dc07-daily-bigdata-yoga-cdh-bj01host-
748171
.host.idcvdian.com = yoga.com
dc05-prod-bigdata-apollo-bj01host-
614146
.host.idcvdian.com = hera.com
dc05-prod-bigdata-apollo-bj01host-
614147
.host.idcvdian.com = hera.com
idc05-guoyu-hbase-
22172
.host.idcvdian.com = hera.com
idc05-shunyi-bigdata-
0333
.host.idcvdian.com = hera.com
idc05-shunyi-bigdata-
0393
.host.idcvdian.com = hera.com
idc05-shunyi-bigdata-
0502
.host.idcvdian.com = hera.com
idc05-shunyi-bigdata-
0503
.host.idcvdian.com = hera.com
idc07-prod-guoyu-
101614145
.host.idcvdian.com = hera.com
idc07-prod-guoyu-
101620135
.host.idcvdian.com = hera.com
idc07-prod-guoyu-
101622148
.host.idcvdian.com = hera.com
|
重啓kerberos服務
在hdfs-site.xml,設置容許的realms
在hdfs-site.xml中設置dfs.namenode.kerberos.principal.pattern爲"*"
這個是客戶端的匹配規則用於控制容許的認證realms,若是該參數不配置,會有下面的異常:
java.io.IOException: Failed on local exception: java.io.IOException:
java.lang.IllegalArgumentException:
Server has invalid Kerberosprincipal:nn/ hera.com@ yoga.com;
Host Details : local host is:
"host1.yoga.com/10.181.22.130"
;
destination host is:
"host2.hera.com"
:
8020
;
|
1)使用hdfs命令測試yoga 和hera 集羣間的數據訪問
例如在yoga Cluster中kinit admin@yoga.com,而後運行hdfs命令,查看本機羣和對方集羣得hdfs目錄:
若是未開啓跨域互信,訪問對方hdfs目錄時會報認證錯誤
[root
@node1a141
~]# kdestroy
在本機羣客戶端登錄admin用戶,經過kerberos認證
[root
@node1a141
~]# kinit admin
Password
for
admin
@yoga
.com:
訪問本集羣hdfs
#hdfs dfs -ls /
Found
11
items
drwxrwxrwt - yarn hadoop
0
2021
-
03
-
08
15
:
26
/app-logs
drwxr-xr-x - yarn hadoop
0
2021
-
03
-
03
20
:
28
/ats
drwxr-xr-x - hdfs hdfs
0
2021
-
03
-
08
19
:
16
/atsv2
drwxr-xr-x - root hdfs
0
2021
-
03
-
17
17
:
12
/benchmarks
drwxr-xr-x - hdfs hdfs
0
2021
-
03
-
03
20
:
28
/hdp
drwxr-xr-x - mapred hdfs
0
2021
-
03
-
03
20
:
30
/mapred
drwxrwxrwx - mapred hadoop
0
2021
-
03
-
03
20
:
30
/mr-history
drwxr-xr-x - hdfs hdfs
0
2021
-
03
-
03
20
:
24
/services
drwxr-xr-x - hdfs hdfs
0
2021
-
03
-
18
15
:
00
/test
drwxrwxrwx - hdfs hdfs
0
2021
-
03
-
15
14
:
12
/tmp
drwxr-xr-x - hdfs hdfs
0
2021
-
03
-
04
14
:
42
/user
訪問對方集羣hdfs
[
14
:
19
:40root
@idc05
-shunyi-bigdata-
0393
/root]
#hdfs dfs -ls hdfs:
//dc07-daily-bigdata-yoga-cdh-bj01host-748169.host.idcvdian.com:8020/
Found
8
items
drwxrwxr-x+ - noops supergroup
0
2020
-
11
-
18
22
:
35
hdfs:
//dc07-daily-bigdata-yoga-cdh-bj01host-748169.host.idcvdian.com:8020/backup
drwxrwxr-x+ - hdfs supergroup
0
2020
-
12
-
08
17
:
50
hdfs:
//dc07-daily-bigdata-yoga-cdh-bj01host-748169.host.idcvdian.com:8020/benchmarks
drwxrwxrwx+ - mars supergroup
0
2020
-
07
-
10
10
:
41
hdfs:
//dc07-daily-bigdata-yoga-cdh-bj01host-748169.host.idcvdian.com:8020/data
-rw-r-xr--+
1
mars supergroup
1550
2020
-
11
-
18
17
:
35
hdfs:
//dc07-daily-bigdata-yoga-cdh-bj01host-748169.host.idcvdian.com:8020/derby.log
drwxrwxr-x+ - hdfs supergroup
0
2020
-
08
-
24
20
:
26
hdfs:
//dc07-daily-bigdata-yoga-cdh-bj01host-748169.host.idcvdian.com:8020/system
drwxrwxr-x+ - noops supergroup
0
2020
-
11
-
12
08
:
39
hdfs:
//dc07-daily-bigdata-yoga-cdh-bj01host-748169.host.idcvdian.com:8020/temp
drwxrwxrwt+ - hdfs supergroup
0
2021
-
03
-
04
11
:
16
hdfs:
//dc07-daily-bigdata-yoga-cdh-bj01host-748169.host.idcvdian.com:8020/tmp
dr-xrwxrwx+ - hdfs supergroup
0
2021
-
03
-
19
00
:
54
hdfs:
//dc07-daily-bigdata-yoga-cdh-bj01host-748169.host.idcvdian.com:8020/user
|