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+)
  • 使用configs.py编辑配置
  • 使用API编辑配置(1.4.1 / 1.2.5)
  • 使用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: , ,

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

|

使用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] [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.

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

: Server external host name

: Name given to cluster. Ex: ``'c1'

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

|

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

你可能感兴趣的:(Ambari RestAPI获取配置版本、修改配置)