先附一个官方文档
有两种方式修改配置文件
1. 使用REST API
第一种方式
①步
curl --user admin:admin -H "X-Requested-By: ambari" -i -X POST -d '{"type": "capacity-scheduler", "tag": "version16", "properties" : {"yarn.scheduler.capacity.root.queues" : "default,aa","yarn.scheduler.capacity.root.aa.capacity":"10","yarn.scheduler.capacity.root.aa.maximum-capacity":"100","yarn.scheduler.capacity.root.aa.state":"RUNNING"}}' http://192.168.1.63:8080/api/v1/clusters/eds-cluster/configurations·enter code here
②步
curl --user admin:admin -H "X-Requested-By: ambari" -i -X PUT -d '{"Clusters":{"desired_config" : {"type": "capacity-scheduler", "tag": "version15"}}}' http://192.168.1.63:8080/api/v1/clusters/eds-cluster/configurations
第二种方式
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
2. 使用 configs.sh
其原理就是把命令传过来的字符串缓存到json文件中,然后再使用 REST API 进行修改。
官网文档,不做解释
/var/lib/ambari-server/resources/scripts/configs.shUsage: 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.
例子:
①/var/lib/ambari-server/resources/scripts/configs.sh get 192.168.1.68 eds-cluster capacity-scheduler
(返回的内容就是"properties" : {"yarn.scheduler.capacity.root.queues" : "default,aa","yarn.scheduler.capacity.root.aa.capacity":"10"}
)
②/var/lib/ambari-server/resources/scripts/configs.sh set localhost eds-cluster capacity-scheduler "yarn.scheduler.capacity.root.queues" "default,DataCanvas"
还有一个最重要的就是使用文件进行更新了,如果属性很多的话用单条命令执行就显得有点不合适,况且使用命令更新一次则配置文件对应的版本就会迭代一次,这样使用文件更新配置相对来说比较简单。
例子:
/var/lib/ambari-server/resources/scripts/configs.sh set 192.168.1.68 eds-cluster capacity-scheduler version16.json
这里的文件不一定必须是json文件,但是文件的内容格式是固定的,如下:
"properties" : { "yarn.scheduler.capacity.root.queues" : "default,aa", "yarn.scheduler.capacity.root.aa.capacity":"10", "yarn.scheduler.capacity.root.aa.maximum-capacity":"100", "yarn.scheduler.capacity.root.aa.state":"RUNNING" }
这样我们在更新配置时就可以先使用/var/lib/ambari-server/resources/scripts/configs.sh get 192.168.1.68 eds-cluster capacity-scheduler
获取当前配置,经过处理后再使用/var/lib/ambari-server/resources/scripts/configs.sh set 192.168.1.68 eds-cluster capacity-scheduler version16.json
进行更新配置。
网友评论