Ambari中添加新服务

官网:

https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=38571133

一、背景

栈的定义可以在源代码树中找到/ambari-server/src/main/resources/stacks。当你安装Ambari Server服务之后,栈的定义可以被发现/var/lib/ambari-server/resources/stacks

二、结构

一个栈的结构定义如下

|_ stacks

   |_ 

      |_ 

         metainfo.xml

         |_ hooks

         |_ repos

            repoinfo.xml

         |_ services

            |_ 

               metainfo.xml

               metrics.json

               |_ configuration

                  {configuration files}

               |_ package

                  {files, scripts, templates}

三、定义一个服务和组件

在service里的metainfo.xml文件描述这个服务,服务的组件和管理脚本用于执行命令。一个组件的服务可以是MASTER,SLAVECLIENT类别。这个告诉Ambari默认命令应该用于管理和监控组件。为每个组件指定< commandScript >执行命令时使用。有一个默认命令定义组件必须支持。

Ambari支持不同的命令脚本用PYTHON编写的。类型是用来知道如何执行命令脚本。你也可以创建自定义命令除了default lifecycle commands之外你的组件需要去支持。

 

例如,YARN Service描述ResourceManager组件配置metainfo.xml如下:

<component>
  <name>RESOURCEMANAGERname>
  <category>MASTERcategory>
  <commandScript>
    <script>scripts/resourcemanager.pyscript>
    <scriptType>PYTHONscriptType>
    <timeout>600timeout>
  commandScript>
  <customCommands>
    <customCommand>
      <name>DECOMMISSIONname>
      <commandScript>
        <script>scripts/resourcemanager.pyscript>
        <scriptType>PYTHONscriptType>
        <timeout>600timeout>
      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组件。

 

创建并且添加服务

1.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

2.创建一个目录/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

3.浏览到新创建的SAMPLESRV目录,创建一个metainfo.xml文件去描述一个新的服务。例如:

xml version="1.0"?>
<metainfo>
    <schemaVersion>2.0schemaVersion>
    <services>
        <service>
            <name>SAMPLESRVname>
            <displayName>New Sample ServicedisplayName>
            <comment>A New Sample Servicecomment>
            <version>1.0.0version>
            <components>
                <component>
                    <name>SAMPLESRV_MASTERname>
                    <displayName>Sample Srv MasterdisplayName>
                    <category>MASTERcategory>
                    <cardinality>1cardinality>
                    <commandScript>
                        <script>scripts/master.pyscript>
                        <scriptType>PYTHONscriptType>
                        <timeout>600timeout>
                    commandScript>
                component>
                <component>
                    <name>SAMPLESRV_SLAVEname>
                    <displayName>Sample Srv SlavedisplayName>
                    <category>SLAVEcategory>
                    <cardinality>1+cardinality>
                    <commandScript>
                        <script>scripts/slave.pyscript>
                        <scriptType>PYTHONscriptType>
                        <timeout>600timeout>
                    commandScript>
                component>
                <component>
                    <name>SAMPLESRV_CLIENTname>
                    <displayName>Sample Srv ClientdisplayName>
                    <category>CLIENTcategory>
                    <cardinality>1+cardinality>
                    <commandScript>
                        <script>scripts/sample_client.pyscript>
                        <scriptType>PYTHONscriptType>
                        <timeout>600timeout>
                    commandScript>
                component>
            components>
            <osSpecifics>
                <osSpecific>
                    <osFamily>anyosFamily>  
                osSpecific>
            osSpecifics>
        service>
    services>
metainfo>

4.在上面,我的服务名是"SAMPLESRV"它包含:

·一个MASTER组件“SAMPLESRV_MASTER”

·一个SLAVE组件“SAMPLESRV_SLAVE”

·一个CLIENT组件“SAMPLESRV_CLIENT”

5.接下来,我们创建命令脚本。为命令脚本创建一个目录/var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/SAMPLESRV/package/scripts我们制定的服务metainfo

1 mkdir -p /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/SAMPLESRV/package/scripts
2 cd /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/SAMPLESRV/package/scripts

6.进入目录并创建.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()

7.重启Ambari Server

ambari-server restart

参考网址:

https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=38571133

https://github.com/hortonworks-gallery/ambari-zeppelin-service#option-2-automated-deployment-of-a-fresh-hdp-cluster-that-includes-zeppelin-via-blueprints

https://github.com/Symantec/ambari-cassandra-service

 

转载于:https://www.cnblogs.com/zeppelin/p/5767966.html

你可能感兴趣的:(Ambari中添加新服务)