自顶向下——基于方法论下的Redis集成[二]
# 1.2 services/REDIS/metainfo.xml
文件详解
metainfo.xml
是 Ambari 自定义服务开发中的核心文件,它承担着“服务控制中枢”的角色,定义了 Redis
服务在集群中的角色结构、版本号、配置依赖、命令脚本路径以及平台适配范围等关键信息。
在 Redis 的集成中,整体结构分为 Master、Slave、Client 三种组件角色,并通过 commandScript
与 configFiles
精确绑定执行逻辑与配置模板。
下面是一个完整的 metainfo.xml
示例,并配以注释详解:
<?xml version="1.0"?>
<metainfo>
<schemaVersion>2.0</schemaVersion>
<services>
<service>
<!-- Redis 服务基本信息 -->
<name>REDIS</name>
<displayName>Redis</displayName>
<comment>
Component Redis Powered by JaneTTR
mail: 3832514048@qq.com
git: https://gitee.com/tt-bigdata/ambari-env
</comment>
<version>7.4.0</version>
<!-- Redis 各组件角色定义 -->
<components>
<!-- 🟥 Master 节点:负责槽位分配、写入操作 -->
<component>
<name>REDIS_MASTER</name>
<displayName>Redis Master</displayName>
<category>MASTER</category>
<cardinality>3+</cardinality> <!-- 集群至少需部署 3 个主节点 -->
<versionAdvertised>true</versionAdvertised>
<commandScript>
<script>scripts/redis_master.py</script>
<scriptType>PYTHON</scriptType>
</commandScript>
<configFiles>
<configFile>
<type>env</type>
<fileName>redis-site.xml</fileName>
<dictionaryName>redis-site</dictionaryName>
</configFile>
<configFile>
<type>env</type>
<fileName>redis-env.sh</fileName>
<dictionaryName>redis-env</dictionaryName>
</configFile>
</configFiles>
</component>
<!-- 🟦 Slave 节点:负责副本同步、读操作与容灾 -->
<component>
<name>REDIS_SLAVE</name>
<displayName>Redis Slave</displayName>
<category>SLAVE</category>
<cardinality>3+</cardinality>
<versionAdvertised>true</versionAdvertised>
<commandScript>
<script>scripts/redis_slave.py</script>
<scriptType>PYTHON</scriptType>
</commandScript>
<configFiles>
<configFile>
<type>env</type>
<fileName>redis-site.xml</fileName>
<dictionaryName>redis-site</dictionaryName>
</configFile>
<configFile>
<type>env</type>
<fileName>redis-env.sh</fileName>
<dictionaryName>redis-env</dictionaryName>
</configFile>
</configFiles>
</component>
<!-- 🟨 Client 客户端:主要用于命令行交互测试 -->
<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>
<scriptType>PYTHON</scriptType>
</commandScript>
</component>
</components>
<!-- 操作系统适配说明 -->
<osSpecifics>
<osSpecific>
<osFamily>any</osFamily> <!-- 可适配任意 Linux 发行版 -->
<packages>
<package>
<name>redis_${stack_version}</name> <!-- 支持动态替换 -->
</package>
</packages>
</osSpecific>
</osSpecifics>
<!-- 健康检查机制 -->
<commandScript>
<script>scripts/service_check.py</script>
<scriptType>PYTHON</scriptType>
<timeout>300</timeout> <!-- 超时设为 5 分钟 -->
</commandScript>
<!-- 声明配置依赖 -->
<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
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
延伸说明
cardinality
控制角色部署数量要求,例如"3+"
表示最少 3 台主机。commandScript
是组件执行的核心入口,会由 Ambari Agent 自动调用。dictionaryName
与configuration/
目录下的 XML 名字对应,用于参数渲染绑定。osSpecifics
允许你声明包依赖关系,在 RPM/DEB 安装模式中生效。
建议实践
在服务开发初期阶段,可只定义 MASTER + CLIENT
结构,待调通后再扩展 SLAVE
与集群逻辑,这样更易调试与版本迭代。