Community Articles
Find and share helpful community-sourced technical articles
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.
Labels (2)
Contributor
  • 1.You can execute below api to get a list of hosts in your cluster in file hostcluster.txt

# curl -s -u admin:admin http://ambari:8080/api/v1/hosts|grep host_name|sed -n 's/.*"host_name" : "\([^\"]*\)".*/\1/p'>hostcluster.txt

2. In the loop you can write the api which need to run on the nodes :

~~~

while read line ;

do

j=$line

mkdir -p $j

done < hostcluster.txt

~~~

  • -admin:admin : username:password

- Above loop will take each entries from file hostcluster.txt and need to execute the.

3. In order to install the clients you can use below API’s. Below API’s will install only 5 clients as mentioned below :

####### Installing HDFS_CLIENT, YARN_CLIENT, ZOOKEEPER_CLIENT and MAPREDUCE2_CLIENT on "HOSTANAME" as following:

+++++++++++

# curl -u admin:admin -H "X-Requested-By:ambari" -i -X POST -d '{"RequestInfo":{"context":"Install HDFS Client"},"Body":{"host_components":[{"HostRoles":{"component_name":"HDFS_CLIENT"}}]}}' http://ambari-hostname:8080/api/v1/clusters/rest/hosts?Hosts/host_name=$j

# curl -u admin:admin -H "X-Requested-By:ambari" -i -X POST -d '{"RequestInfo":{"context":"Install YARN Client"},"Body":{"host_components":[{"HostRoles":{"component_name":"YARN_CLIENT"}}]}}' http://ambari-hostname:8080/api/v1/clusters/rest/hosts?Hosts/host_name=$j

# curl -u admin:admin -H "X-Requested-By:ambari" -i -X POST -d '{"RequestInfo":{"context":"Install MapReduce2 Client"},"Body":{"host_components":[{"HostRoles":{"component_name":"MAPREDUCE2_CLIENT"}}]}}' http://ambari-hostname:8080/api/v1/clusters/rest/hosts?Hosts/host_name=$j

# curl -u admin:admin -H "X-Requested-By:ambari" -i -X POST -d '{"RequestInfo":{"context":"Install ZooKeeper Client"},"Body":{"host_components":[{"HostRoles":{"component_name":"ZOOKEEPER_CLIENT"}}]}}' http://ambari-hostname:8080/api/v1/clusters/rest/hosts?Hosts/host_name=$j

+++++++++++

Where,

  • -admin:admin : Is username and password for ambary server.
  • -ambari-hostname : hostname of your ambari server
  • -$j : is the variable which will substitute each value from hostcluster.txt

NOTE :

If you want to add more clients such as spark/oozie etc you need to change below value from above command :

-"context":"Install ZooKeeper Client" <-- Modify as per the client

- component_name":"MAPREDUCE2_CLIENT" <-- Modify as per the client you want to install

3 Below API’s is to pull the configurations for all the clients which are installed in step 2 :

. ####### Initialize the HDFS_CLIENT, YARN_CLIENT, ZOOKEEPER_CLIENT and MAPREDUCE2_CLIENT clients on $j

+++++++++++

curl -u admin:admin -H "X-Requested-By:ambari" -i -X PUT -d '{"RequestInfo":{"context":"Install HDFS Client","operation_level":{"level":"HOST_COMPONENT","cluster_name":"rest","host_name":"$j","service_name":"HDFS"}},"Body":{"HostRoles":{"state":"INSTALLED"}}}' http://ambari-hostname:8080/api/v1/clusters/rest/hosts/$j/host_components/HDFS_CLIENT?HostRoles/stat...

curl -u admin:admin -H "X-Requested-By:ambari" -i -X PUT -d '{"RequestInfo":{"context":"Install YARN Client","operation_level":{"level":"HOST_COMPONENT","cluster_name":"rest","host_name":"$j","service_name":"YARN"}},"Body":{"HostRoles":{"state":"INSTALLED"}}}' http://ambari-hostname:8080/api/v1/clusters/rest/hosts/$j/host_components/YARN_CLIENT?HostRoles/stat...

curl -u admin:admin -H "X-Requested-By:ambari" -i -X PUT -d '{"RequestInfo":{"context":"Install MapReduce2 Client","operation_level":{"level":"HOST_COMPONENT","cluster_name":"rest","host_name":"$j","service_name":"MAPREDUCE2"}},"Body":{"HostRoles":{"state":"INSTALLED"}}}' http://ambari-hostname:8080/api/v1/clusters/rest/hosts/$j/host_components/MAPREDUCE2_CLIENT?HostRole...

# curl -u admin:admin -H "X-Requested-By:ambari" -i -X PUT -d '{"RequestInfo":{"context":"Install ZooKeeper Client","operation_level":{"level":"HOST_COMPONENT","cluster_name":"rest","host_name":"$j","service_name":"ZOOKEEPER"}},"Body":{"HostRoles":{"state":"INSTALLED"}}}' http://ambari-hostname:8080/api/v1/clusters/rest/hosts/$j/host_components/ZOOKEEPER_CLIENT?HostRoles...

+++++++++++

Where,

  • -ambari-hostname : hostname of your ambari server
  • -$j : is the variable which will take each value from hostcluster.txt

If you have added more clients in step 2 then you need to add more commands in step 3 based on the clients installed in step 2.

Below is the scrip to install : HDFS_CLIENT, YARN_CLIENT, ZOOKEEPER_CLIENT and MAPREDUCE2_CLIENT

  • 1.Create a .sh file and copy below contents:

# vi script.sh

~~~~

curl -s -u admin:admin http://ambari:8080/api/v1/hosts|grep host_name|sed -n 's/.*"host_name" : "\([^\"]*\)".*/\1/p'>hostcluster.txt

while read line ;

do

j=$line

mkdir -p $j

curl -u admin:admin -H "X-Requested-By:ambari" -i -X POST -d '{"RequestInfo":{"context":"Install HDFS Client"},"Body":{"host_components":[{"HostRoles":{"component_name":"HDFS_CLIENT"}}]}}' http://ambari-hostname:8080/api/v1/clusters/rest/hosts?Hosts/host_name=$j

curl -u admin:admin -H "X-Requested-By:ambari" -i -X POST -d '{"RequestInfo":{"context":"Install YARN Client"},"Body":{"host_components":[{"HostRoles":{"component_name":"YARN_CLIENT"}}]}}' http://ambari-hostname:8080/api/v1/clusters/rest/hosts?Hosts/host_name=$j

curl -u admin:admin -H "X-Requested-By:ambari" -i -X POST -d '{"RequestInfo":{"context":"Install MapReduce2 Client"},"Body":{"host_components":[{"HostRoles":{"component_name":"MAPREDUCE2_CLIENT"}}]}}' http://ambari-hostname:8080/api/v1/clusters/rest/hosts?Hosts/host_name=$j

curl -u admin:admin -H "X-Requested-By:ambari" -i -X POST -d '{"RequestInfo":{"context":"Install ZooKeeper Client"},"Body":{"host_components":[{"HostRoles":{"component_name":"ZOOKEEPER_CLIENT"}}]}}' http://ambari-hostname:8080/api/v1/clusters/rest/hosts?Hosts/host_name=$j

curl -u admin:admin -H "X-Requested-By:ambari" -i -X PUT -d '{"RequestInfo":{"context":"Install HDFS Client","operation_level":{"level":"HOST_COMPONENT","cluster_name":"rest","host_name":"$j","service_name":"HDFS"}},"Body":{"HostRoles":{"state":"INSTALLED"}}}' http://ambari-hostname:8080/api/v1/clusters/rest/hosts/$j/host_components/HDFS_CLIENT?HostRoles/stat...

curl -u admin:admin -H "X-Requested-By:ambari" -i -X PUT -d '{"RequestInfo":{"context":"Install YARN Client","operation_level":{"level":"HOST_COMPONENT","cluster_name":"rest","host_name":"$j","service_name":"YARN"}},"Body":{"HostRoles":{"state":"INSTALLED"}}}' http://ambari-hostname:8080/api/v1/clusters/rest/hosts/$j/host_components/YARN_CLIENT?HostRoles/stat...

curl -u admin:admin -H "X-Requested-By:ambari" -i -X PUT -d '{"RequestInfo":{"context":"Install MapReduce2 Client","operation_level":{"level":"HOST_COMPONENT","cluster_name":"rest","host_name":"$j","service_name":"MAPREDUCE2"}},"Body":{"HostRoles":{"state":"INSTALLED"}}}' http://ambari-hostname:8080/api/v1/clusters/rest/hosts/$j/host_components/MAPREDUCE2_CLIENT?HostRole...

curl -u admin:admin -H "X-Requested-By:ambari" -i -X PUT -d '{"RequestInfo":{"context":"Install ZooKeeper Client","operation_level":{"level":"HOST_COMPONENT","cluster_name":"rest","host_name":"$j","service_name":"ZOOKEEPER"}},"Body":{"HostRoles":{"state":"INSTALLED"}}}' http://ambari-hostname:8080/api/v1/clusters/rest/hosts/$j/host_components/ZOOKEEPER_CLIENT?HostRoles...

done < hostcluster.txt

  • 2.Make it execuable :
  • # chmod 755 script.sh
  • 3.Execute it.
  • # ./script.sh

NOTE: If any clients are already installed on few nodes you may see below messages, please don’t panic.

~~

}HTTP/1.1 409 Conflict

X-Frame-Options: DENY

X-XSS-Protection: 1; mode=block

Set-Cookie: AMBARISESSIONID=vam8jlo7ys401q0r5nm10bm71;Path=/;HttpOnly

Expires: Thu, 01 Jan 1970 00:00:00 GMT

User: admin

Content-Type: text/plain

Content-Length: 250

Server: Jetty(8.1.19.v20160209)

~~

1,021 Views
0 Kudos
Don't have an account?
Coming from Hortonworks? Activate your account here
Version history
Revision #:
1 of 1
Last update:
‎09-13-2017 02:56 PM
Updated by:
 
Contributors
Top Kudoed Authors