Ambari实现一个自定义的服务

在这个例子中,我们将创建一个称为“SAMPLESRV”的自定义的服务,将它添加到现有源里面。这服务包括MASTER, SLAVE和CLIENT 组件。

创建和添加服务
  1. 在Ambari服务器,进入/var/lib/ambari-server/resources/stacks/HDP/2.0.6/services目录。在这种情况下,我们将浏览到HDP-2源的。

    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.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>
  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里面配置。

    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
  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服务器

    ambari-server restart

安装服务
Icon

注意:通过web界面添加自定义服务是在1.7.0极以后版本上

  1. 在Ambari Web, 进入到服务界面并点击 操作 按钮(在左边的服务导航区域)。
  2. 打开"添加服务" 安装向导。 你可以看到包含"My Sample Service" 的选项(就是在服务的 metainfo.xml 文件里面定义的名称)。
  3. 选择 "My Sample Service" 并点击下一步。
  4. 分配  "Sample Srv Master" 并点击下一步。
  5. 选择主机安装 "Sample Srv Client" 并点击下一步。
  6. 一旦完成,该"My Sample Service" 将出现在服务的导航区域.
  7. 如果你想添加"Sample Srv Client"到任一主机,你可以进入到"主机"并进入到需要的主机,点击“+添加”。

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值