借鉴:http://www.ibm.com/developerworks/cn/opensource/os-cn-bigdata-ambari3/index.html

Ambari 在启动的时候,会扫描 resource 目录下 Stack 下面的 service 配置。也就是每个 Service 的 metainfo.xml,同时会将这些配置信息放在自己的数据库中。当用户在 WEB 上面点击 “Add Service”的时候,WEB 就会加载这些配置信息到具体的页面里。在 Service 的 metainfo.xml 中,commandScript 字段就是用来配置 service check 脚本入口。如果一个 Service 的 metainfo.xml 有该字段,那么在 Service 的 Action 列表中就会出现“Run Service Check”这个命令。对于自定义的 Service,默认是没有这些配置项的。如果一个自定义的 Service 需要某些必须的参数时,就必须创建 Service 的配置目录(configuration)和对应的配置文件,让用户安装的时候输入。

在ambari的基础上,我们想要安装我们自己的软件,通过查找自己做了一下:

mkdir /var/lib/ambari-server/resources/stacks/HDP/2.4/services/DAXIONG

在/var/lib/ambari-server/resources/stacks/HDP/2.4/services下面有很多service目录,是ambari自己的安装软件组,我们可以自己建一个目录,目录名字最好大写,我是按照目录里写的;在每个service下的目录中都有metainfo.xml文件,上述也介绍了,下面是我的metainfo.xml内容;

<?xml version="1.0"?>
<metainfo>
    <schemaVersion>2.0</schemaVersion>
    <services>
        <service>
            <name>DAXIONG</name>
            <displayName>DAXIONG Service</displayName>
            <comment>A DAXIONG Service</comment>
            <version>1.0</version>
            <components>
                <component>
                    <name>DAXIONG_MASTER</name>
                    <category>MASTER</category>
                    <cardinality>1</cardinality>
                    <commandScript>
                        <script>scripts/master.py</script>
                        <scriptType>PYTHON</scriptType>
                        <timeout>600</timeout>
                    </commandScript>
                </component>
                <component>
                    <name>DAXIONG_SLAVE</name>
                    <category>SLAVE</category>
                    <cardinality>1+</cardinality>
                    <commandScript>
                        <script>scripts/slave.py</script>
                        <scriptType>PYTHON</scriptType>
                        <timeout>600</timeout>
                    </commandScript>
                </component>
                <component>
                    <name>DAXIONG_CLIENT</name>
                    <category>CLIENT</category>
                    <cardinality>1+</cardinality>
                    <commandScript>
                        <script>scripts/client.py</script>
                        <scriptType>PYTHON</scriptType>
                        <timeout>600</timeout>
                    </commandScript>
                </component>
            </components>
            <osSpecifics>
                <osSpecific>
                    <osFamily>any</osFamily>
                </osSpecific>
            </osSpecifics>
        </service>
    </services>
</metainfo>

创建命令脚本. 为命令脚本创建一个目录 /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/DAXIONG/package/scripts

[root@master scripts]# ls
master.py  client.py  slave.py

[root@master scripts]# cat master.py

import sys
from resource_management import *
class Master(Script):
  def install(self, env):
    print 'Install the Sample DAXIONG Master';
  def stop(self, env):
    print 'Stop the Sample DAXIONG Master';
  def start(self, env):
    print 'Start the Sample DAXIONG Master';
  def status(self, env):
    print 'Status of the Sample DAXIONG Master';
  def configure(self, env):
    print 'Configure the Sample DAXIONG Master';
if __name__ == "__main__":
  Master().execute()

[root@master scripts]# cat client.py

import sys
from resource_management import *
class Slave(Script):
  def install(self, env):
    print 'Install the Sample DAXIONG Slave';
  def stop(self, env):
    print 'Stop the Sample DAXIONG Slave';
  def start(self, env):
    print 'Start the Sample DAXIONG Slave';
  def status(self, env):
    print 'Status of the Sample DAXIONG Slave';
  def configure(self, env):
    print 'Configure the Sample DAXIONG Slave';
if __name__ == "__main__":
  Slave().execute()

[root@master scripts]# cat slave.py

import sys
from resource_management import *
class SampleClient(Script):
  def install(self, env):
    print 'Install the Sample DAXIONG Client';
  def configure(self, env):
    print 'Configure the Sample DAXIONG Client';
if __name__ == "__main__":
  SampleClient().execute()

上面的配置完后需要重新启动ambari,然后在web界面添加服务就可以了,这只是一个简单是事例,因为最近在做这一方面,所以简单的测试了一下。中间原来搭建的hbase出现了问题,只需要进入所在的机器(host),开启没有开启的服务即可。

下面是截图:

wKioL1eR2lWTi65rAAA86_pjQAY738.png-wh_50