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

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

配置更新涉及以下步驟:

  • 確定要更新的配置類型并記下應(yīng)用的最新版本。更新配置類型時(shí),需要更新整個(gè)屬性集。因此,從最新和更新特定值復(fù)制值或根據(jù)需要添加/刪除屬性是最簡(jiǎn)單的選擇。
  • 閱讀群集資源并記下要更新的類型的版本
  • 使用標(biāo)記讀取配置類型并記下屬性
  • 根據(jù)需要編輯屬性,然后更新配置類型
    • 配置更新需要?jiǎng)?chuàng)建新版本(通常當(dāng)前時(shí)間戳是一個(gè)不錯(cuò)的選擇)
    • 必須添加新版本的配置類型并將其應(yīng)用于群集
  • 重新啟動(dòng)受影響的服務(wù)/組件以使配置生效

您可以使用API或包裝器腳本(/var/lib/ambari-server/resources/scripts/configs.py或/var/lib/ambari-server/resources/scripts/configs.sh)來(lái)編輯配置。

使用API編輯配置(2.4.0+)

已驗(yàn)證版本2.4.x(應(yīng)與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. 使用正確的標(biāo)記讀取配置類型

|

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 保存新版本的配置并將其應(yīng)用為所需的配置

確保提供唯一標(biāo)記 - 最佳選擇是使用當(dāng)前時(shí)間戳

|

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. 重新啟動(dòng)所有組件或服務(wù)以使配置更改生效

例如停止并啟動(dòng)服務(wù)

|

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是一個(gè)輔助腳本,可以安裝ambari-server,可以輕松地操作配置。使用腳本時(shí),它將編輯配置并將其應(yīng)用于群集。您仍然需要重新啟動(dòng)服務(wù)/組件才能使配置生效。

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)

已針對(duì)1.4.1 / 1.2.5版本進(jìn)行了驗(yàn)證

從1.4.2 / 1.4.3開(kāi)始,您必須在curl調(diào)用中添加-H選項(xiàng)。例如-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. 使用正確的標(biāo)記讀取配置類型

|

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。 保存配置的新版本并應(yīng)用它(使用一個(gè)調(diào)用執(zhí)行此操作,請(qǐng)參閱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。 保存新版本的配置并使用一個(gè)呼叫應(yīng)用它

|

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. 重新啟動(dòng)所有組件或服務(wù)以使配置更改生效
    例如停止并啟動(dòng)服務(wù)

|

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是一個(gè)輔助腳本,可以安裝ambari-server,可以輕松操作配置。使用腳本時(shí),它將編輯配置并將其應(yīng)用于群集。您仍然需要重新啟動(dòng)服務(wù)/組件才能使配置生效。

  1. 更新參數(shù)

|

/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(選項(xiàng)CONFIG_KEY)并從文件導(dǎo)入以編輯大量屬性。

  1. configs.sh用法
    注意:如果您有舊版本,則可能無(wú)法提供自定義userId和密碼。如果默認(rèn)admin:admin不適用,請(qǐng)編輯腳本以使用正確的密碼。

|

/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>來(lái)源: https://cwiki.apache.org/confluence/display/AMBARI/Modify+configurations#Modifyconfigurations-Editconfigurationusingconfigs.py</small>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容