一、Ambari基本架构

 
img016.jpg

Ambari Server 会读取 Stack 和 Service 的配置文件。当用 Ambari 创建服务的时候,Ambari Server 传送 Stack 和 Service 的配置文件以及 Service 生命周期的控制脚本到 Ambari Agent。Agent 拿到配置文件后,会下载安装公共源里软件包(Redhat,就是使用 yum 服务)。安装完成后,Ambari Server 会通知 Agent 去启动 Service。之后 Ambari Server 会定期发送命令到 Agent 检查 Service 的状态,Agent 上报给 Server,并呈现在 Ambari 的 GUI 上。

二、创建Ambari自定义Service

#AmbariServer资源文件在/var/lib/ambari-server/resources目录
#cd到Ambari Stack目录下 (目前最新版为2.6)
cd /var/lib/ambari-server/resources/stacks/HDP/2.6/services
#创建自定义Service目录 (以大写ServiceName命令,这里以My Service为例)
mkdir MYSERVICE
cd MYSERVICE

1.编辑metainfo.xml

<?xml version="1.0"?>
<metainfo>
<schemaVersion>2.0</schemaVersion>
<services>
<service>
<!-- -->
<!-- 编写Service名称和Service信息 -->
<name>MYSERVICE</name>
<displayName>My Service</displayName>
<comment>this is comment</comment>
<version>1.0</version>
<components>
<component>
<!-- 编写Master组件 -->
<name>MYMASTER</name>
<displayName>My Master</displayName>
<category>MASTER</category>
<cardinality>1</cardinality>
<commandScript>
<script>scripts/master.py</script>
<scriptType>PYTHON</scriptType>
<timeout>5000</timeout>
</commandScript>
</component>
<component>
<!-- 编写Slave组件 -->
<name>MYSALVE</name>
<displayName>My Slave</displayName>
<category>SLAVE</category>
<cardinality>1+</cardinality>
<commandScript>
<script>scripts/slave.py</script>
<scriptType>PYTHON</scriptType>
<timeout>5000</timeout>
</commandScript>
</component>
</components>
<osSpecifics>
<osSpecific>
<osFamily>any</osFamily>
</osSpecific>
</osSpecifics>
</service>
</services>
</metainfo>
  • components 下编写多个组件。
  • category 为组件的角色,支持Master、Slave、和Client
  • cardinality 为节点数量,可以为1、1+、或数值范围1-2
  • commandScript 为组件生命周期回调的脚本

2.编写Master组件生命周期回调脚本

mkdir -p package/scripts
vim package/scripts/master.py
import sys, os
from resource_management import *
from resource_management.core.exceptions import ComponentIsNotRunning
from resource_management.core.environment import Environment
from resource_management.core.logger import Logger class Master(Script):
def install(self, env):
print "Install My Master" def configure(self, env):
print "Configure My Master" def start(self, env):
print "Start My Master" def stop(self, env):
print "Stop My Master" def status(self, env):
print "Status..." if __name__ == "__main__":
Master().execute()

3.编写Slave组件生命周期回调脚本

package/scripts/slave.py
import sys, os
from resource_management import *
from resource_management.core.exceptions import ComponentIsNotRunning
from resource_management.core.environment import Environment
from resource_management.core.logger import Logger class Slave(Script):
def install(self, env):
print "Install My Slave" def configure(self, env):
print "Configure My Slave" def start(self, env):
print "Start My Slave" def stop(self, env):
print "Stop My Slave" def status(self, env):
print "Status..." if __name__ == "__main__":
Slave().execute()

4.重启AmbariServer

ambari-server restart

5.加入刚才添加的My Service服务

  • 在Ambari Web上。点击Actions-> Add Service 添加My Service服务

     
    WX20170728-150942@2x.png

三、丰富自定义Service功能

1.增加Service Check逻辑

在 Service 的 metainfo.xml 中,commandScript 字段就是用来配置 service check 脚本入口。如果一个 Service 的 metainfo.xml 有该字段,那么在 Service 的 Action 列表中就会出现“Run Service Check”这个命令。

当用户在 WEB 中点击“Run Service Check”时,Ambari Server 会随机通知一个该 Service 所在机器上的 Agent 进程,然后由 Agent 执行该 Service check 脚本。

<commandScript>
<script>scripts/master/my_check.py</script>
<scriptType>PYTHON</scriptType> <timeout>300</timeout>
</commandScript>
 
WX20170728-152404@2x.png

2.增加Service 的配置项

这里需要在Service的metainfo.xml 中增加<configuration-dependencies>字段。该字段就是用来关联一个 Service 与配置项文件入口

每一行<config-type>字段,用来指定一个配置文件。一个 Service 可以同时指定多个配置文件。不过所有的配置文件必须放在 Service 的 configuration 目录中。

<!-- 以HDFS为例 -->
<metainfo>
<services>
<service>
<!-- 省略... -->
<configuration-dependencies>
<!-- 在下面指定配置文件 -->
<config-type>core-site</config-type>
<config-type>hdfs-site</config-type>
<config-type>hadoop-env</config-type>
<config-type>hadoop-policy</config-type>
<config-type>hdfs-log4j</config-type>
<config-type>ranger-hdfs-plugin-properties</config-type>
<config-type>ssl-client</config-type>
<config-type>ssl-server</config-type>
<config-type>ranger-hdfs-audit</config-type>
<config-type>ranger-hdfs-policymgr-ssl</config-type>
<config-type>ranger-hdfs-security</config-type>
</configuration-dependencies>
<restartRequiredAfterRackChange>true</restartRequiredAfterRackChange>
</service>
</services>
</metainfo>
#configuration目录下的文件:
[root@node1 2.1.0.2.0]# ll configuration/
total 84
-rwxr-xr-x 1 admin root 7948 May 27 10:11 core-site.xml
-rwxr-xr-x 1 admin root 16723 May 27 10:11 hadoop-env.xml
-rwxr-xr-x 1 admin root 6201 May 27 10:11 hadoop-policy.xml
-rwxr-xr-x 1 admin root 8879 May 27 10:11 hdfs-log4j.xml
-rwxr-xr-x 1 admin root 8192 May 27 10:11 hdfs-logsearch-conf.xml
-rwxr-xr-x 1 admin root 19139 May 27 10:11 hdfs-site.xml
-rwxr-xr-x 1 admin root 2627 May 27 10:11 ssl-client.xml
-rwxr-xr-x 1 admin root 2959 May 27 10:11 ssl-server.xml

配置文件中,其实就是指定了一些键值对的属性,以及一个描述。当在 Ambari 的 WEB 中增加这个 Service 时,Ambari Server 会读取这些信息,并显示到该 service 的配置页面中(Customize Service 和 config 页面)。默认情况下,如果一个配置项没有配置默认值,用户则必须输入。如果一个项允许为空,则需要在<property>中增加 require-input="false“的属性。

3.增加自定义Command

以RebalanceHDFS为例,在Service的metainfo.xml中增加以下内容
当点击RebalanceHDFS后 则触发scripts/namenode.py脚本

<customCommands>
<customCommand>
<name>REBALANCEHDFS</name>
<background>true</background>
<commandScript>
<script>scripts/namenode.py</script>
<scriptType>PYTHON</scriptType>
</commandScript>
</customCommand>
</customCommands>
 

Ambari自定义Service的更多相关文章

  1. Ambari安装及自定义service初步实现

    Ambari安装 1 Ambari简介 Apache Ambari项目的目的是通过开发软件来配置.监控和管理hadoop集群,以使hadoop的管理更加简单.同时,ambari也提供了一个基于它自身R ...

  2. AngularJs创建自定义Service

    AngularJs可以创建自定义的service.下面的自定义service实现一个double倍数的服务: 参考下面语法: app.service('double', function () { t ...

  3. angular js自定义service的简单示例

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  4. Ambari 自定义服务集成原理介绍

    之前,在 github 上开源了 ambari-Kylin 项目,可离线部署,支持 hdp 2.6+ 及 hdp 3.0+ .github 地址为:https://github.com/8418090 ...

  5. Windows中使用cmd实现自定义Service的安装与卸载

    在项目中,有些时候我们需要自定义一些Service来定时处理一些业务逻辑,这时候就涉及到如何安装与卸载service的问题了,具体如何安装呢?在此整理一些解决方案供大家参考: 方案一: 1.运行--〉 ...

  6. 在linux下创建自定义service服务

    三个部分 这个脚本分为3个部分:[Unit] [Service] [Install]. Unit Unit表明该服务的描述,类型描述.我们称之为一个单元.比较典型的情况是单元A要求在单元B启动之后再启 ...

  7. 通过 systemctl 设置自定义 Service

    如果要在Linux 上设置一个开机自启,出现问题自动重启,并且有良好日志的程序,比较流行的方法有 supervisord.systemd,除此之外,还有 upstart.runit 等类似的工具. 但 ...

  8. angularJS 系列(三)- 自定义 Service

    参考:http://viralpatel.net/blogs/angularjs-service-factory-tutorial/ https://www.pluralsight.com/blog/ ...

  9. systemctl自定义service

    应用场景:开启自启动运行脚本/usr/local/manage.sh 一.服务介绍 CentOS 7的服务systemctl脚本存放在:/usr/lib/systemd/,有系统(system)和用户 ...

随机推荐

  1. java并发之CyclicBarrier

    一.CyclicBarrier简述 一个同步辅助类,它允许一组线程互相等待,直到到达某个公共屏障点 (common barrier point).在涉及一组固定大小的线程的程序中,这些线程必须不时地互 ...

  2. ZooKeeper的使用---Java程序

    一.导入库 以下库存放在目录lib中: audience-annotations-0.5.0.jar jline-0.9.94.jar log4j-1.2.17.jar netty-3.10.6.Fi ...

  3. ARM-Linux中断系统

    1.前言 了解Linux中断子系统,同时也需要了解ARM体系结构中断处理流程:在熟悉整个软硬件架构和流程基础上,才能对流程进行细化,然后找出问题的瓶颈.<2. 梳理中断处理子系统> 但是所 ...

  4. Linux kernel的中断子系统之(一):综述

    返回目录:<ARM-Linux中断系统>. 总结: 一从作为一名驱动工程师角度看,用好中断需要正确认识request_threaded_irq/request_irq关系.中断临界区保护. ...

  5. 手把手教你使用 netlify 实现前端的 自动部署 + HTTPS

    随着开源工具越来越多,特别是nodejs构建微服务器之快,实现前端自动化部署越来越简单了,有可能[10行js代码+10行sh脚本+设置github的webhook]就能实现,但是如果你和我一样,就是& ...

  6. Scrapy 1.4 文档 04 例子

    最好的学习方法是举例说明,Scrapy也不例外. 因此,我们有一个名为 quotesbot 的 Scrapy 项目,您可以通过它来学习更多关于 Scrapy 的知识. 它包含两个用于http://qu ...

  7. React从入门到放弃之前奏(2):React简介

    本系列将尽可能使用ES6(ES2015)语法.所以均在上节webpack的基础上做开发. React是Facebook开发的一款JS库,因为基于Virtual DOM,所以响应速度快,以及支持跨平台. ...

  8. 「JavaScript」JS四种跨域方式详解

    原文地址https://segmentfault.com/a/1190000003642057 超详细并且带 Demo 的 JavaScript 跨域指南来了! 本文基于你了解 JavaScript ...

  9. 获取input Date日期 时间,并得到前一天的Date值

    var endTime = time.substring(0, 10); var temp1 = new Date(endTime.replace(/-/g,"/")); temp ...

  10. 6.app架构基础

    app架构,一个听起来高大尚的名字,很多小伙伴听到这个词语感觉很迷茫,不知道架构具体说的是啥?在q群里,"app后端应该怎么架构"这个问题被问了无数次.通过阅读本文,根据本人提出的 ...