【Ambari】ambari中添加新服务
背景
栈的定义可以在源代码树中找到/ambari-server/src/main/resources/stacks。当你安装Ambari Server服务之后,栈的定义可以被发现/var/lib/ambari-server/resources/stacks。
结构
一个栈的结构定义如下
|_ stacks
|_ <stack_name>
|_ <stack_version>
metainfo.xml
|_ hooks
|_ repos
repoinfo.xml
|_ services
|_ <service_name>
metainfo.xml
metrics.json
|_ configuration
{configuration files}
|_ package
{files, scripts, templates}
定义一个服务和组件
在service里的metainfo.xml文件描述这个服务,服务的组件和管理脚本用于执行命令。一个组件的服务可以是MASTER,SLAVE或CLIENT类别。这个告诉Ambari默认命令应该用于管理和监控组件。为每个组件指定< commandScript >执行命令时使用。有一个默认命令定义组件必须支持。
Ambari支持不同的命令脚本用PYTHON编写的。类型是用来知道如何执行命令脚本。你也可以创建自定义命令除了default lifecycle commands之外你的组件需要去支持。
例如,YARN Service描述ResourceManager组件配置metainfo.xml如下:
<component>
<name>RESOURCEMANAGER</name>
<category>MASTER</category>
<commandScript>
<script>scripts/resourcemanager.py</script>
<scriptType>PYTHON</scriptType>
<timeout>600</timeout>
</commandScript>
<customCommands>
<customCommand>
<name>DECOMMISSION</name>
<commandScript>
<script>scripts/resourcemanager.py</script>
<scriptType>PYTHON</scriptType>
<timeout>600</timeout>
</commandScript>
</customCommand>
</customCommands>
</component>
ResourceManager是一个MASTER组件,并且命令脚本是scripts/resourcemanager.py,可以被找到services/YARN/package目录,PYTHON命令脚本,脚本作为PYTHON方法实现default lifecycle commands。这是默认的安装方法安装命令:
class Resourcemanager(Script):
def install(self, env):
self.install_packages(env)
self.configure(env)
你也可以看到一个自定义的命令定义DECOMMISSION,这意味着还有一个DECOMMISSION方法在python命令脚本:
def decommission(self, env):
import params
...
Execute(yarn_refresh_cmd,
user=yarn_user
)
pass
使用堆栈继承
栈可以扩展其他堆栈为了分享命令脚本和配置。这样可以减少重复的代码在栈使用以下:
- 为子栈定义存储库
- 在子栈添加新的服务(不是在父栈)
- 覆盖父服务命令脚本
- 覆盖父服务的配置
实现一个自定义服务
在本例中,我们将创建一个名为“SAMPLESRV”的定制服务,将其添加到现有的栈的定义。
此服务包括MASTER,SLAVE,CLIENT组件。
创建并且添加服务
- Ambari Server上,浏览到/var/lib/ambari-server/resources/stacks/HDP/2.0.6/services这个目录。在这种情况下,我们将浏览到HDP 2.0的定义。
cd /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services
- 创建一个目录/var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/SAMPLESRV将包含SAMPLESRV的服务定义。
mkdir /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/SAMPLESRV
cd /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/SAMPLESRV
- 浏览到新创建的SAMPLESRV目录,创建一个metainfo.xml文件去描述一个新的服务。例如:
<?xml version="1.0"?>
<metainfo>
<schemaVersion>2.0</schemaVersion>
<services>
<service>
<name>SAMPLESRV</name>
<displayName>New Sample Service</displayName>
<comment>A New Sample Service</comment>
<version>1.0.0</version>
<components>
<component>
<name>SAMPLESRV_MASTER</name>
<displayName>Sample Srv Master</displayName>
<category>MASTER</category>
<cardinality>1</cardinality>
<commandScript>
<script>scripts/master.py</script>
<scriptType>PYTHON</scriptType>
<timeout>600</timeout>
</commandScript>
</component>
<component>
<name>SAMPLESRV_SLAVE</name>
<displayName>Sample Srv Slave</displayName>
<category>SLAVE</category>
<cardinality>1+</cardinality>
<commandScript>
<script>scripts/slave.py</script>
<scriptType>PYTHON</scriptType>
<timeout>600</timeout>
</commandScript>
</component>
<component>
<name>SAMPLESRV_CLIENT</name>
<displayName>Sample Srv Client</displayName>
<category>CLIENT</category>
<cardinality>1+</cardinality>
<commandScript>
<script>scripts/sample_client.py</script>
<scriptType>PYTHON</scriptType>
<timeout>600</timeout>
</commandScript>
</component>
</components>
<osSpecifics>
<osSpecific>
<osFamily>any</osFamily> <!-- note: use osType rather than osFamily for Ambari 1.5.0 and 1.5.1 -->
</osSpecific>
</osSpecifics>
</service>
</services>
</metainfo>
- 在上面,我的服务名是"SAMPLESRV"它包含:
- 一个MASTER组件“SAMPLESRV_MASTER”
- 一个SLAVE组件“SAMPLESRV_SLAVE”
- 一个CLIENT组件“SAMPLESRV_CLIENT”
- 接下来,我们创建命令脚本。为命令脚本创建一个目录/var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/SAMPLESRV/package/scripts我们制定的服务metainfo
mkdir -p /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/SAMPLESRV/package/scripts
cd /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/SAMPLESRV/package/scripts
- 进入目录并创建.py的命令脚本文件。
例如master.py文件:
import sys
from resource_management import *
class Master(Script):
def install(self, env):
print 'Install the Sample Srv Master';
def stop(self, env):
print 'Stop the Sample Srv Master';
def start(self, env):
print 'Start the Sample Srv Master';
def status(self, env):
print 'Status of the Sample Srv Master';
def configure(self, env):
print 'Configure the Sample Srv Master';
if __name__ == "__main__":
Master().execute()
例如slave.py文件:
import sys
from resource_management import *
class Slave(Script):
def install(self, env):
print 'Install the Sample Srv Slave';
def stop(self, env):
print 'Stop the Sample Srv Slave';
def start(self, env):
print 'Start the Sample Srv Slave';
def status(self, env):
print 'Status of the Sample Srv Slave';
def configure(self, env):
print 'Configure the Sample Srv Slave';
if __name__ == "__main__":
Slave().execute()
例如sample_client.py文件:
import sys
from resource_management import *
class SampleClient(Script):
def install(self, env):
print 'Install the Sample Srv Client';
def configure(self, env):
print 'Configure the Sample Srv Client';
if __name__ == "__main__":
SampleClient().execute()
- 重启Ambari Server
ambari-server restart
参考
https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=38571133
相关文章
- 服务器搭建:手把手教你配置web服务之tomcat7
- 添加nginx为系统服务(service nginx start/stop/restart)
- EasyDarwin添加自定义的服务模块EasyMyModule
- REDHAT5.5 下配置httpd服务
- Linux Ubuntu 20.04 —添加开机启动(服务/脚本)
- linux根据端口查pid、根据pid查端口、根据pid查服务路径
- CDH6.3.2添加Hue服务时,验证数据库连接报错 Unexpected error. Unable to verify database connection.
- IIS 服务或万维网发布服务,或者依赖这 服务可能在启动期间发生错误或者已禁用
- 微服务扩展新途径:Messaging
- 26. SAP UI5 应用里 OData 服务配合 Mock 服务器的使用步骤详解
- 金庸和古龙,Netweaver和微服务,以及SAP Hybris Revenue Cloud
- 如何在SAP云平台的Cloud Foundry环境下添加新的Service(服务)
- 给nodejs应用的package.json添加Redis服务的依赖
- 华为OD机试 - 微服务的集成测试(Java & JS & Python)
- android 11添加自定义系统服务,编译成jar包供上层使用
- Cloud Computing:云计算的简介之云计算的三层服务类型(从服务的层次)——IaaS、PaaS、SaaS的简介、核心技术之详细攻略
- Android 11.0 12.0添加自定义服务,并生成jar给第三方app调用
- android 9.0 系统Services(自定义服务) 添加jni方法
- Spring4 MVC REST服务使用@RestController实例
- CentOS7安装CDH(八):CDH中对服务和机器的添加与删除操作
- 时间同步 | chrony 服务