Step11-Stacks-组件编排
# 1. 组件编排元信息基础
Redis 组件在 Ambari Stacks/Bigtop 体系中,需要通过 metainfo.xml
来实现集群角色划分、部署约束、脚本入口、健康检查等元信息编排。下图展示了
Redis 服务在 stacks 下的基本路径:
ambari-server/src/main/resources/stacks/BIGTOP/3.2.0/services/REDIS/metainfo.xml
1
# 2. metainfo.xml 结构详解
# 2.1 服务与组件角色定义
Redis 集群通常采用主从结构,每种角色通过 <components>
节点独立声明:
角色名 | 类型 | 数量约束 | 启动脚本 | 说明 |
---|---|---|---|---|
REDIS_MASTER | MASTER | 3+ | scripts/redis_master.py | 至少3个主节点 |
REDIS_SLAVE | SLAVE | 3+ | scripts/redis_slave.py | 推荐主从等量 |
REDIS_CLIENT | CLIENT | 0+ | scripts/redis_client.py | 可选客户端,支持多 |
<components>
<component>
<name>REDIS_MASTER</name>
<displayName>Redis Master</displayName>
<category>MASTER</category>
<cardinality>3+</cardinality>
<commandScript>
<script>scripts/redis_master.py</script>
<scriptType>PYTHON</scriptType>
</commandScript>
</component>
<component>
<name>REDIS_SLAVE</name>
<displayName>Redis Slave</displayName>
<category>SLAVE</category>
<cardinality>3+</cardinality>
<commandScript>
<script>scripts/redis_slave.py</script>
<scriptType>PYTHON</scriptType>
</commandScript>
</component>
<component>
<name>REDIS_CLIENT</name>
<displayName>Redis Client</displayName>
<category>CLIENT</category>
<cardinality>0+</cardinality>
<commandScript>
<script>scripts/redis_client.py</script>
<scriptType>PYTHON</scriptType>
</commandScript>
<!-- 客户端角色专属配置下载声明 -->
<configFiles>
<configFile>
<type>xml</type>
<fileName>redis-site.xml</fileName>
<dictionaryName>redis-site</dictionaryName>
</configFile>
<configFile>
<type>xml</type>
<fileName>redis-env.sh</fileName>
<dictionaryName>redis-env</dictionaryName>
</configFile>
</configFiles>
</component>
</components>
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
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
# 2.2 操作系统适配与包声明
<osSpecifics>
<osSpecific>
<osFamily>any</osFamily>
<packages>
<package>
<name>redis_${stack_version}</name>
</package>
</packages>
</osSpecific>
</osSpecifics>
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
- 支持主流 Linux 发行版。
<package>
名称自动适配 Bigtop 构建的 Redis 包。
# 2.3 健康检查脚本
每个服务都建议实现健康检查脚本,确保首次安装及日常运维时自动检测集群状态。
<commandScript>
<script>scripts/service_check.py</script>
<scriptType>PYTHON</scriptType>
<timeout>300</timeout>
</commandScript>
1
2
3
4
5
6
2
3
4
5
6
# 2.4 配置依赖声明
配置依赖用于描述服务启动、重载等操作时需要动态加载的参数类型。
<configuration-dependencies>
<config-type>redis-site</config-type>
<config-type>redis-env</config-type>
</configuration-dependencies>
1
2
3
4
5
2
3
4
5
# 3. configFiles 节点与页面下载配置的关系
# 3.1 configFiles 的真正用途
提示
<configFiles>
节点不是用来指定服务启动时加载哪些配置,而是专门为 Ambari 页面“下载配置”按钮提供导出文件声明
。每次点击后端会按照这里定义的 fileName,动态渲染、打包生成配置文件,便于一键导出和备份。
举例:
<configFiles>
<configFile>
<type>xml</type>
<fileName>redis-site.xml</fileName>
<dictionaryName>redis-site</dictionaryName>
</configFile>
<configFile>
<type>xml</type>
<fileName>redis-env.sh</fileName>
<dictionaryName>redis-env</dictionaryName>
</configFile>
</configFiles>
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
fileName
是最终下载文件的名字。dictionaryName
对应配置表单的数据来源类型。
# 4.完整的metainfo.xml
<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<metainfo>
<schemaVersion>2.0</schemaVersion>
<services>
<service>
<!-- Redis 集群服务的基本信息 -->
<name>REDIS</name>
<displayName>Redis</displayName>
<comment>
Component Redis Power By JaneTTR . mail: 3832514048@qq.com ,git: https://gitee.com/tt-bigdata/ambari-env
</comment>
<version>7.4.0</version>
<!-- Redis 集群组件定义 -->
<components>
<!-- Redis 主节点组件 -->
<component>
<name>REDIS_MASTER</name>
<displayName>Redis Master</displayName>
<category>MASTER</category>
<cardinality>3+</cardinality> <!-- Redis 集群至少需要 3 个主节点 -->
<versionAdvertised>true</versionAdvertised>
<commandScript>
<script>scripts/redis_master.py</script> <!-- Python 脚本 -->
<scriptType>PYTHON</scriptType>
</commandScript>
</component>
<!-- Redis 从节点组件 -->
<component>
<name>REDIS_SLAVE</name>
<displayName>Redis Slave</displayName>
<category>SLAVE</category>
<cardinality>3+</cardinality> <!-- 从节点可以是 0 或多个 -->
<versionAdvertised>true</versionAdvertised>
<commandScript>
<script>scripts/redis_slave.py</script> <!-- Python 脚本 -->
<scriptType>PYTHON</scriptType>
</commandScript>
</component>
<!-- Redis 客户端组件 -->
<component>
<name>REDIS_CLIENT</name>
<displayName>Redis Client</displayName>
<category>CLIENT</category>
<cardinality>0+</cardinality> <!-- 客户端是可选的,可以部署多个 -->
<versionAdvertised>true</versionAdvertised>
<commandScript>
<script>scripts/redis_client.py</script> <!-- Python 脚本 -->
<scriptType>PYTHON</scriptType>
</commandScript>
<configFiles>
<configFile>
<type>xml</type>
<fileName>redis-site.xml</fileName>
<dictionaryName>redis-site</dictionaryName>
</configFile>
<configFile>
<type>xml</type>
<fileName>redis-env.sh</fileName>
<dictionaryName>redis-env</dictionaryName>
</configFile>
</configFiles>
</component>
</components>
<!-- 操作系统相关 -->
<osSpecifics>
<osSpecific>
<osFamily>any</osFamily> <!-- 支持任何操作系统 -->
<packages>
<package>
<name>redis_${stack_version}</name>
</package>
</packages>
</osSpecific>
</osSpecifics>
<!-- Redis 服务健康检查 -->
<commandScript>
<script>scripts/service_check.py</script> <!-- 健康检查 Python 脚本 -->
<scriptType>PYTHON</scriptType>
<timeout>300</timeout>
</commandScript>
<!-- Redis 服务不依赖其他服务 -->
<!-- 如果有其他依赖项,可以在这里定义 -->
<!-- 配置依赖 -->
<configuration-dependencies>
<config-type>redis-site</config-type>
<config-type>redis-env</config-type>
</configuration-dependencies>
</service>
</services>
</metainfo>
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
- 01
- bigtop-select 打包缺 compat 报错修复 deb07-16
- 02
- bigtop-select 打包缺 control 文件报错修复 deb07-16
- 03
- 首次编译-环境初始化 必装07-16