Ambari RestAPI获取配置版本、修改配置

  • 最后修改于[三月01,2019]

配置更新涉及以下步骤:

  • 确定要更新的配置类型并记下应用的最新版本。更新配置类型时,需要更新整个属性集。因此,从最新和更新特定值复制值或根据需要添加/删除属性是最简单的选择。
  • 阅读群集资源并记下要更新的类型的版本
  • 使用标记读取配置类型并记下属性
  • 根据需要编辑属性,然后更新配置类型
    • 配置更新需要创建新版本(通常当前时间戳是一个不错的选择)
    • 必须添加新版本的配置类型并将其应用于群集
  • 重新启动受影响的服务/组件以使配置生效

您可以使用API或包装器脚本(/var/lib/ambari-server/resources/scripts/configs.py或/var/lib/ambari-server/resources/scripts/configs.sh)来编辑配置。

使用API编辑配置(2.4.0+)

已验证版本2.4.x(应与2.2.x一起使用)

  1. 找到需要更新的最新版本的配置类型

|

curl -u admin:admin -H "X-Requested-By: ambari" -X GET [http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME?fields=Clusters/desired_configs](http://ambari_server_host:8080/api/v1/clusters/CLUSTER_NAME?fields=Clusters/desired_configs)

Sample OUTPUT

{

"href" : "[http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME?fields=Clusters/desired_configs](http://ambari_server_host:8080/api/v1/clusters/CLUSTER_NAME?fields=Clusters/desired_configs)",

"Clusters" : {

"cluster_name" : "CLUSTER_NAME",

"version" : "HDP-2.0.6",

"desired_configs" : {

...

"mapred-site" : {

"user" : "admin",

"tag" : "version1384716039631"

}

...

}

}

}

|

  1. 使用正确的标记读取配置类型

|

curl -u admin:admin -H "X-Requested-By: ambari" -X GET "[http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/configurations?type=mapred-site&tag=version1384716039631](http://ambari_server_host:8080/api/v1/clusters/CLUSTER_NAME/configurations?type=mapred-site&tag=version1384716039631)"

Sample OUTPUT

{

"href" : "[http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/configurations?type=mapred-site&tag=version1384716039631](http://ambari_server_host:8080/api/v1/clusters/CLUSTER_NAME/configurations?type=mapred-site&tag=version1384716039631)",

"items" : [

{

"href" : "[http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/configurations?type=mapred-site&tag=version1384716039631](http://ambari_server_host:8080/api/v1/clusters/CLUSTER_NAME/configurations?type=mapred-site&tag=version1384716039631)",

"tag" : "version1384716039631",

"type" : "mapred-site",

"Config" : {

"cluster_name" : "CLUSTER_NAME"

},

"properties" : {

... THESE ARE THE PROPERTY KEY-VALUE PAIRS ...

}

}]

}

|

3 保存新版本的配置并将其应用为所需的配置

确保提供唯一标记 - 最佳选择是使用当前时间戳

|

curl -u admin:admin -H "X-Requested-By: ambari" -X PUT -d '[{"Clusters":{

"desired_config":[{

"type":"zoo.cfg",

"tag":"version1480557385509",

"properties":{

"autopurge.purgeInterval":"24",

"autopurge.snapRetainCount":"30",

"dataDir":"/hadoop/zookeeper",

"tickTime":"2000",

"initLimit":"11",

"syncLimit":"5",

"clientPort":"2181"},

"service_config_version_note":"New config version"}]}}]'

"[http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME](http://ambari_server_host:8080/api/v1/clusters/CLUSTER_NAME)"

|

  1. 重新启动所有组件或服务以使配置更改生效

例如停止并启动服务

|

curl --user admin:admin -i -X PUT -d ``'{"RequestInfo": {"context": "Stop HDFS"}, "ServiceInfo": {"state": "INSTALLED"}}' http:``//AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/services/HDFS

curl --user admin:admin -i -X PUT -d ``'{"RequestInfo": {"context": "Start HDFS"}, "ServiceInfo": {"state": "STARTED"}}' http:``//AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/services/HDFS

|

使用configs.py编辑配置

configs.py是一个辅助脚本,可以安装ambari-server,可以轻松地操作配置。使用脚本时,它将编辑配置并将其应用于群集。您仍然需要重新启动服务/组件才能使配置生效。

configs.sh用法

|

/var/lib/ambari-server/resources/scripts/configs.py --help

Usage: configs.py [options]

Options:

-h, --help show this help message and exit

-t PORT, --port=PORT Optional port number for Ambari server. Default is

'8080'. Provide empty string to not use port.

-s PROTOCOL, --protocol=PROTOCOL

Optional support of SSL. Default protocol is 'http'

-a ACTION, --action=ACTION

Script action: <get>, <set>, <delete>

-l HOST, --host=HOST Server external host name

-n CLUSTER, --cluster=CLUSTER

Name given to cluster. Ex: 'c1'

-c CONFIG_TYPE, --config-type=CONFIG_TYPE

One of the various configuration types in Ambari. Ex:

core-site, hdfs-site, mapred-queue-acls, etc.

To specify credentials please use "-e" OR "-u" and "-p'":

-u USER, --user=USER

Optional user ID to use for authentication. Default is

'admin'

-p PASSWORD, --password=PASSWORD

Optional password to use for authentication. Default

is 'admin'

-e CREDENTIALS_FILE, --credentials-file=CREDENTIALS_FILE

Optional file with user credentials separated by new

line.

To specify property(s) please use "-f" OR "-k" and "-v'":

-f FILE, --file=FILE

File where entire configurations are saved to, or read

from. Supported extensions (.xml, .json>)

-k KEY, --key=KEY Key that has to be set or deleted. Not necessary for

'get' action.

-v VALUE, --value=VALUE

Optional value to be set. Not necessary for 'get' or

'delete' actions.

|

<wiz_tmp_tag class="wiz-block-scroll" style="height: 17px; width: 806px; overflow-x: scroll; overflow-y: hidden; position: fixed; bottom: 0px; z-index: 999; background-color: rgba(255, 255, 255, 0.2);"></wiz_tmp_tag>

使用API编辑配置(1.4.1 / 1.2.5)

已针对1.4.1 / 1.2.5版本进行了验证

从1.4.2 / 1.4.3开始,您必须在curl调用中添加-H选项。例如-H“X-Requested-By:ambari”

  1. 找到需要更新的最新版本的配置类型

|

curl -u admin:admin -X GET http:``//AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME?fields=Clusters/desired_configs

Sample OUTPUT

{

"href" : ``"[http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME?fields=Clusters/desired_configs](http://ambari_server_host:8080/api/v1/clusters/CLUSTER_NAME?fields=Clusters/desired_configs)"``,

"Clusters" : {

"cluster_name" : ``"CLUSTER_NAME"``,

"version" : ``"HDP-2.0.6"``,

"desired_configs" : {

...

"mapred-site" : {

"user" : ``"admin"``,

"tag" : ``"version1384716039631"

}

...

}

}

}

|

  1. 使用正确的标记读取配置类型

|

curl -u admin:admin ``"[http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/configurations?type=mapred-site&tag=version1384716039631](http://ambari_server_host:8080/api/v1/clusters/CLUSTER_NAME/configurations?type=mapred-site&tag=version1384716039631)"

Sample OUTPUT

{

"href" : ``"[http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/configurations?type=mapred-site&tag=version1384716039631](http://ambari_server_host:8080/api/v1/clusters/CLUSTER_NAME/configurations?type=mapred-site&tag=version1384716039631)"``,

"items" : [

{

"href" : ``"[http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/configurations?type=mapred-site&tag=version1384716039631](http://ambari_server_host:8080/api/v1/clusters/CLUSTER_NAME/configurations?type=mapred-site&tag=version1384716039631)"``,

"tag" : ``"version1384716039631"``,

"type" : ``"mapred-site"``,

"Config" : {

"cluster_name" : ``"CLUSTER_NAME"

},

"properties" : {

... THESE ARE THE PROPERTY KEY-VALUE PAIRS ...

}

}]

}

|

3A。 保存配置的新版本并应用它(使用一个调用执行此操作,请参阅3b)

|

curl --user admin:admin -i -X POST -d ``'{"type": "mapred-site", "tag": "version1384716041120", "properties" : {"mapreduce.admin.map.child.java.opts" : "-Djava.net.preferIPv4Stack=true -Dhadoop.metrics.log.level=WARN",...}}' http:``//AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/configurations

curl --user admin:admin -i -X PUT -d ``'{"Clusters":{"desired_config" : {"type": "mapred-site", "tag": "version1384716041120"}}}' http:``//AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME

|

3B。 保存新版本的配置并使用一个呼叫应用它

|

curl --user admin:admin -i -X PUT -d ``'{"Clusters":{"desired_config" : {"type": "mapred-site", "tag": "version1384716041120", "properties" : {...}}}}' http:``//AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME

|

  1. 重新启动所有组件或服务以使配置更改生效
    例如停止并启动服务

|

curl --user admin:admin -i -X PUT -d ``'{"RequestInfo": {"context": "Stop HDFS"}, "ServiceInfo": {"state": "INSTALLED"}}' http:``//AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/services/HDFS

curl --user admin:admin -i -X PUT -d ``'{"RequestInfo": {"context": "Start HDFS"}, "ServiceInfo": {"state": "STARTED"}}' http:``//AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/services/HDFS

|

使用configs.sh编辑配置

configs.sh是一个辅助脚本,可以安装ambari-server,可以轻松操作配置。使用脚本时,它将编辑配置并将其应用于群集。您仍然需要重新启动服务/组件才能使配置生效。

  1. 更新参数

|

/var/lib/ambari-server/resources/scripts/configs.sh set localhost c1 mapred-site ``"mapreduce.map.memory.mb" "512"

|

  1. 阅读更新的配置

|

/var/lib/ambari-server/resources/scripts/configs.sh get localhost c1 mapred-site

|

提示:使用export to file(选项CONFIG_KEY)并从文件导入以编辑大量属性。

  1. configs.sh用法
    注意:如果您有旧版本,则可能无法提供自定义userId和密码。如果默认admin:admin不适用,请编辑脚本以使用正确的密码。

|

/var/lib/ambari-server/resources/scripts/configs.sh

Usage: configs.sh [-u userId] [-p password] [-port port] <ACTION> <AMBARI_HOST> <CLUSTER_NAME> <CONFIG_TYPE> [CONFIG_FILENAME | CONFIG_KEY [CONFIG_VALUE]]

[-u userId]: Optional user ID to use ``for authentication. Default is ``'admin'``.

[-p password]: Optional password to use ``for authentication. Default is ``'admin'``.

[-port port]: Optional port number ``for Ambari server. Default is ``'8080'``. Provide empty string to not use port.

<ACTION>: One of ``'get'``, ``'set'``, ``'delete'``. ``'Set' adds/updates as necessary.

<AMBARI_HOST>: Server external host name

<CLUSTER_NAME>: Name given to cluster. Ex: ``'c1'

<CONFIG_TYPE>: One of the various configuration types in Ambari. Ex:global, core-site, hdfs-site, mapred-queue-acls, etc.

[CONFIG_FILENAME]: File where entire configurations are saved to, or read from. Only applicable to ``'get' and ``'set' actions

[CONFIG_KEY]: Key that has to be set or deleted. Not necessary ``for 'get' action.

[CONFIG_VALUE]: Optional value to be set. Not necessary ``for 'get' or ``'delete' actions.

|

<small>来源: https://cwiki.apache.org/confluence/display/AMBARI/Modify+configurations#Modifyconfigurations-Editconfigurationusingconfigs.py</small>

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,185评论 6 503
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,652评论 3 393
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,524评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,339评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,387评论 6 391
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,287评论 1 301
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,130评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,985评论 0 275
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,420评论 1 313
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,617评论 3 334
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,779评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,477评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,088评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,716评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,857评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,876评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,700评论 2 354

推荐阅读更多精彩内容