Ambari自定义服务开发-服务组件启动顺序设置
[toc]
# 组件启动顺序设置
配置文件名为role_command_order.json
,位置在自定义服务的根目录下。
该配置文件主要实现功能就是组织各组件启动、安装、停止等执行的顺序,如启动A服务前必须启动B服务,停止B服务前必须停止A服务等。
在服务器位置
role_command_order.json 文件在 /var/lib/ambari-server/resources/common-services 目录的每个服务下面有,每个 Stack 目录下的服务下面也有 role_command_order.json 。相同的配置,Stack 下面的会覆盖全局的。不同的配置,Ambari 会拼接在一起。高版本的 Stack 会继承低版本的配置。相同的也会覆盖,不同的会合并 。
# 配置文件格式
拿Hbase的配置来举例
{
"general_deps" : {
"_comment" : "dependencies for HBase",
"HBASE_REGIONSERVER-START": ["HBASE_MASTER-START"], # 在启动 HBASE_REGIONSERVER 之前,启动HBASE_MASTER
"HBASE_SERVICE_CHECK-SERVICE_CHECK": ["HBASE_MASTER-START", "HBASE_REGIONSERVER-START"], # 执行HBASE_SERVICE_CHECK 服务检查前,需要启动HBASE_MASTER和HBASE_REGIONSERVER
"HBASE_MASTER-STOP": ["HBASE_REGIONSERVER-STOP"], # 在停止HBASE_MASTER服务前,停止HBASE_REGIONSERVER
"HBASE_MASTER-START": ["NAMENODE-START", "DATANODE-START", "ZOOKEEPER_SERVER-START", "RANGER_USERSYNC-START", "RANGER_KMS_SERVER-START"],
"PHOENIX_QUERY_SERVER-START": ["HBASE_MASTER-START"]
}
}
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
格式如下
{
"_comment": "Section 1 comment",
"section_name_1": {
"_comment": "Section containing role command orders",
"<DEPENDENT_COMPONENT_1>-<COMMAND>": ["<DEPENDS_ON_COMPONENT_1>-<COMMAND>", "<DEPENDS_ON_COMPONENT_1>-<COMMAND>"],
"<DEPENDENT_COMPONENT_2>-<COMMAND>": ["<DEPENDS_ON_COMPONENT_3>-<COMMAND>"],
...
},
"_comment": "Next section comment",
...
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
section_name_1 取值
general_deps | Command orders are applied in all situations |
---|---|
namenode_optional_ha | Command orders are applied when HDFS service is installed and JOURNALNODE component exists (HDFS HA is enabled) |
optional_glusterfs | Command orders are applied when cluster has instance of GLUSTERFS service |
optional_no_glusterfs | Command orders are applied when cluster does not have instance of GLUSTERFS service |
resourcemanager_optional_ha | Command orders are applied when YARN service is installed and multiple RESOURCEMANAGER host-components exist (YARN HA is enabled) |
<COMMAND>取值
- INSTALL
- UNINSTALL
- START
- RESTART
- STOP
- EXECUTE
- ABORT
- UPGRADE
- SERVICE_CHECK
- CUSTOM_COMMAND
- ACTIONEXECUTE
规则配置样例
"HIVE_METASTORE-START": ["MYSQL_SERVER-START", "NAMENODE-START"] | Start MySQL and NameNode components before starting Hive Metastore |
---|---|
"MAPREDUCE_SERVICE_CHECK-SERVICE_CHECK": ["NODEMANAGER-START", "RESOURCEMANAGER-START"], | MapReduce service check needs ResourceManager and NodeManagers started |
"ZOOKEEPER_SERVER-STOP" : ["HBASE_MASTER-STOP", "HBASE_REGIONSERVER-STOP", "METRICS_COLLECTOR-STOP"], | Before stopping ZooKeeper servers, make sure HBase Masters, HBase RegionServers and AMS Metrics Collector are stopped. |
# 验证
配置启动顺序如下:SPARK2_JOBHISTORYSERVER -> BACKEND -> FRONTEND
{
"general_deps" : {
"_comment" : "dependencies for DORIS",
"BACKEND-START": ["SPARK2_JOBHISTORYSERVER-START"],
"FRONTEND-START": ["BACKEND-START"],
"DORIS_SERVICE_CHECK-SERVICE_CHECK": ["FRONTEND-START"]
}
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
没有配置的时候安装完成默认启动顺序如下
单独启动Doirs服务是这样的
将自定义服务更新到服务器上,更新完配置再次安装服务可以看到顺序按照我们设置的运行
单独启动服务发现顺序也按照我们设置的运行
# 参考资料
https://cwiki.apache.org/confluence/display/AMBARI/How-To+Define+Stacks+and+Services#How-ToDefineStacksandServices-RoleCommandOrder
# 相关演示代码
https://download.csdn.net/download/zhangshenghang/88917467
上次更新: 2024/04/08, 10:55:49