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

   |_ <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,SLAVECLIENT類別。這個<category>告訴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組件。

 

創建並且添加服務

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

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM