首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

大数据平台搭建利器 Ambari 之 Kerberos 集成之路(4)

大数据平台搭建利器 Ambari 之 Kerberos 集成之路(4)

为第三方的 Service 定义 Kerberos Descriptor这里我简要的实现了一个 Sample Service,其目录结果如下:
图 7. 示例 Sample 目录结构我们主要看下其中的 sample-env 和 Kerberos.json 文件。
清单 5. Kerberos.json 配置代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
{
"services": [
{
"name": "SAMPLE",
"identities": [
{
"name": "sample1",
"principal": {
"value": "sample1/_HOST@${realm}",
"type" : "user",
"configuration": "sample-env/sample1.principals",
"local_username" : "root"
},
"keytab": {
"file": "${keytab_dir}/sample1.keytab",
"owner": {
"name": "root",
"access": "r"
},
"group": {
"name": "${cluster-env/user_group}",
"access": ""
},
"configuration": "sample-env/sample1.keytab"
}
},
{
"name": "sample2",
"principal": {
"value": "sample2/_HOST@${realm}",
"type" : "service",
"configuration": "sample-env/sample2.principals",
"local_username" : "root"
},
"keytab": {
"file": "${keytab_dir}/sample2.keytab",
"owner": {
"name": "root",
"access": "r"
},
"group": {
"name": "${cluster-env/user_group}",
"access": ""
},
"configuration": "sample-env/sample2.keytab"
}
}

],
"configurations": [
{
"sample-env": {
"mysample.kerberos.enabled": "true"
}
}
],
"components": [
{
"name": "MY_MASTER",
"identities": [
{
"name": "my_master",
"principal": {
"value": "sample/master@${realm}",
"type" : "service",
"configuration": "sample-env/mymaster.principals",
"local_username" : "root"
},
"keytab": {
"file": "${keytab_dir}/mymaster.keytab",
"owner": {
"name": "root",
"access": "r"
},
"group": {
"name": "${cluster-env/user_group}",
"access": ""
},
"configuration": "sample-env/mymaster.keytab"
}
}
]
}
]
}
]
}




之上的配置中,我在 Service 级别定义了两个 identity,Component 级别只定义了一个,并且没有引用 Stack 和其他 Service 的配置。其中有一个 user 类型,两个 service 类型。对于 user 类型,Ambari 会将其配置显示在 Kerberos 配置的首页。在配置中,引用了“_HOST”这个变量,Ambari 会用对应得主机名替换掉该变量。使用 HOST 作为 Principal 的一部分,可以使 Principal 在集群范围内保持唯一性(如果多个机器在同一个集群中使用一个 Principal,并且同时去 KDC 认证,KDC 会以重复为由拒绝掉其他的链接)。接着我们看下 sample-env.xml 的默认配置,如下。
清单 6. Sample-env.xml 的配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<configuration supports_final="true"
xmlns:xi="http://www.w3.org/2001/XInclude">
<property>
<name>mymaster.principals</name>
<display-name>master principals</display-name>
<value>none</value>
</property>
<property>
<name>mymaster.keytab</name>
<value>none</value>
</property>
<property>
<name>sample1.principals</name>
<value>none</value>
</property>
<property>
<name>sample1.keytab</name>
<value>none</value>
</property>
<property>
<name>sample2.principals</name>
<value>none</value>
</property>
<property>
<name>sample2.keytab</name>
<value>none</value>
</property>
</configuration>




Sample 的 sample-env.xml 文件,只是为了让 Ambari Web 在 Sample 的 Config 页面显示这 6 个属性值而存在。虽然这 6 个参数,是以 Service 的配置项存在,却不需要用户在安装的时候修改。Ambari 目前的实现并不支持将 Kerberos.json 中的定义显示在 Config 页面,所以才间接使用 configuration 目录的配置文件。也就是说当启用 Automated Kerberization 的时候,Ambari 会将该配置中的 none 更新成 Kerberos.json 中关联的属性值,进而显示在 Config 页面。
当在 Ambari Server 中增添 Sample 的代码之后,需要重启 Ambari Server 来读取所有的配置。如果在 Ambari 中已经启用了 Kerberos 认证,这时候只需要在 Web 中增加该 Service,Ambari Server 便会对该 Service 调用 Automated Kerberization 机制。当成功部署 Sample 之后,Ambari 会在 Kerberos 的页面以及 Service 的 Config 页面显示对应值(由于更新的页面较多,这里只例举下 Service 的 Config 页面)。
图 8. Sample 的 Config 页面我们可以在机器的目录“/etc/security/keytab”中看到 Ambari 为 Sample Service 生成的三个 keytab 文件,sample1.keytab、sample2.keytab、mymaster.keytab。有兴趣的读者可以使用 klist 命令查看 keytab 文件中的 Principal 列表(需要指定参数-kt)。由于我并未在控制脚本中使用 kinit 文件,所以/tmp 目录中不存在该 Service 相关的 Confidential 文件。这时候,我们也可以使用 configs.sh 脚本查看 Sample Service 的 Kerberos 配置信息,这里就不再举例了。
结束语
返回列表