ambari之api安装组件

Ambari Blueprints 是用来自动化安装hdp组件的配置文件,它告诉ambari:要安装什么service/component,安装在哪里。
ambari之api安装组件_第1张图片

导出蓝图

curl -H "X-Requested-By:ambari" --user admin:admin -X GET http://localhost:8080/api/v1/clusters/BFD_test?format=blueprint > export_blueprint.json

BFD_test导出的集群
下面就是这个配置文件的简化版,介绍它的框架结构

{
  "configurations" : [
        ### 定义hdp里面各个组件的配置,也可以不写,使用默认配置。
  ],
  "host_groups" : [
     {
       "components" : [
          { "name": "NODEMANAGER" },
          { "name": "DATANODE" },
          { "name" : "METRICS_MONITOR" }
        ],
       "configurations" : [ ],
       "name" : "host_group_1",
       "cardinality" : "1"
     },
      {
       ###   定义哪个host group 安装什么component。
      }  ...
  ],
  "settings" : [
    ### 其它设置,比如component自启动。可以不写。
  ],
  "Blueprints" : {
    "stack_name" : "HDP",
    "stack_version" : "2.6"
      ### Blueprint and stack information
  }
}

一、 向ambari注册blueprint

三集群,自己定义的,也可以拿自己导出的蓝图
创建蓝图cluster.json

{
  "configurations" : [

  ],
  "host_groups" : [
    {
      "components" : [
        {
          "name" : "SPARK_CLIENT"
        },
        {
          "name" : "YARN_CLIENT"
        },
        {
          "name" : "HDFS_CLIENT"
        },
        {
          "name" : "HIVE_SERVER"
        },
        {
          "name" : "HISTORYSERVER"
        },
        {
          "name" : "METRICS_MONITOR"
        },
        {
          "name" : "HIVE_METASTORE"
        },
        {
          "name" : "TEZ_CLIENT"
        },
        {
          "name" : "ZOOKEEPER_CLIENT"
        },
        {
          "name" : "PIG"
        },
        {
          "name" : "WEBHCAT_SERVER"
        },
        {
          "name" : "SECONDARY_NAMENODE"
        },
        {
          "name" : "HST_AGENT"
        },
        {
          "name" : "MAPREDUCE2_CLIENT"
        },
        {
          "name" : "SLIDER"
        },
        {
          "name" : "ZOOKEEPER_SERVER"
        },
        {
          "name" : "APP_TIMELINE_SERVER"
        },
        {
          "name" : "HIVE_CLIENT"
        },
        {
          "name" : "MYSQL_SERVER"
        },
        {
          "name" : "RESOURCEMANAGER"
        }
      ],
      "configurations" : [ ],
      "name" : "host_group_2",
      "cardinality" : "1"
    },
    {
      "components" : [
        {
          "name" : "YARN_CLIENT"
        },
        {
          "name" : "HDFS_CLIENT"
        },
        {
          "name" : "HST_SERVER"
        },
        {
          "name" : "METRICS_MONITOR"
        },
        {
          "name" : "NAMENODE"
        },
        {
          "name" : "TEZ_CLIENT"
        },
        {
          "name" : "ACTIVITY_ANALYZER"
        },
        {
          "name" : "ACTIVITY_EXPLORER"
        },
        {
          "name" : "HST_AGENT"
        },
        {
          "name" : "MAPREDUCE2_CLIENT"
        },
        {
          "name" : "ZOOKEEPER_SERVER"
        },
        {
          "name" : "AMBARI_SERVER"
        },
        {
          "name" : "SPARK_JOBHISTORYSERVER"
        },
        {
          "name" : "METRICS_GRAFANA"
        }
      ],
      "configurations" : [ ],
      "name" : "host_group_1",
      "cardinality" : "1"
    },
    {
      "components" : [
        {
          "name" : "NODEMANAGER"
        },
        {
          "name" : "SPARK_CLIENT"
        },
        {
          "name" : "YARN_CLIENT"
        },
        {
          "name" : "HDFS_CLIENT"
        },
        {
          "name" : "METRICS_MONITOR"
        },
        {
          "name" : "TEZ_CLIENT"
        },
        {
          "name" : "ZOOKEEPER_CLIENT"
        },
        {
          "name" : "HCAT"
        },
        {
          "name" : "PIG"
        },
        {
          "name" : "HST_AGENT"
        },
        {
          "name" : "MAPREDUCE2_CLIENT"
        },
        {
          "name" : "SLIDER"
        },
        {
          "name" : "ZOOKEEPER_SERVER"
        },
        {
          "name" : "DATANODE"
        },
        {
          "name" : "HIVE_CLIENT"
        },
        {
          "name" : "METRICS_COLLECTOR"
        }
      ],
      "configurations" : [ ],
      "name" : "host_group_3",
      "cardinality" : "1"
    }
  ],
  "settings" : [
    {
      "recovery_settings" : [
        {
          "recovery_enabled" : "true"
        }
      ]
    },
    {
      "service_settings" : [
        {
          "name" : "HIVE",
          "credential_store_enabled" : "true"
        },
        {
          "recovery_enabled" : "true",
          "name" : "AMBARI_METRICS"
        }
      ]
    },
    {
      "component_settings" : [
        {
          "recovery_enabled" : "true",
          "name" : "METRICS_COLLECTOR"
        }
      ]
    }
  ],
  "Blueprints" : {
    "stack_name" : "HDP",
    "stack_version" : "2.6"
  }
}
curl -H "X-Requested-By: ambari" -X POST \
  -u admin:admin \
  http://localhost:8080/api/v1/blueprints/roycluster?validate_topology=false \
  -d @cluster.json

二、创建集群模板host_map.json,并安装

把 host 和 blueprint 中的 host_group 对应起来,让ambari安装hdp组件

{
  "blueprint" : "roycluster",   ###蓝图名
  "default_password" : "admin",
  "configurations" : [
  ],
  "host_groups" :[
    {
      "name" : "host_group_1",     ###把 host 和 blueprint file 中的 host_group 对应起来
      "hosts" : [
        {
          "fqdn" : "node1"
        }
      ]
    },
    {
      "name" : "host_group_2",   
      "hosts" : [
        {
          "fqdn" : "node2"
        }
      ]
    },
    {
      "name" : "host_group_3",
      "hosts" : [
        {
          "fqdn" : "node3"
        }
      ]
    }
  ]
}

运行是去掉文件中文

curl -H "X-Requested-By: ambari" -X POST -u admin:admin  http://localhost:8080/api/v1/clusters/roycluster -d@host_map.json

基础操作

查看集群

curl -u admin:admin -H "X-Requested-By: ambari" -X  GET http://localhost:8080/api/v1/clusters

查看组件

curl -u admin:admin -H "X-Requested-By: ambari" -X  GET http://localhost:8080/api/v1/clusters/roycluster/services

删除组件

curl -u admin:admin -H "X-Requested-By: ambari" -X  DELETE  http://localhost:8080/api/v1/clusters/roycluster/services/ZOOKEEPER

删除集群

curl -u admin:admin -H "X-Requested-By: ambari" -X DELETE http://localhost:8080/api/v1/clusters/roycluster

roycluster删除的ambari集群名

我个人感觉ambari blueprint 首先通过host_map在ambari创建集群模板,到blueprint里注册,并配置配置文件

你可能感兴趣的:(ambari,kafka,分布式,hdfs)