Last active
December 7, 2015 11:51
-
-
Save azurecube/6fe941e7297c64c73ec2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# !!Note Please execute this on more than 4 node cluster!! | |
# Setting HA as following | |
# node1: Active NN zk1 | |
# Node2: Standby NN jn1 zk2 | |
# Node3: jn2 zk3 | |
# Node4: jn3 | |
# Initialize | |
USERNAME="admin" | |
USERPASS="admin" | |
CMNODE=`hostname -A | cut -d' ' -f1` | |
BASE=http://$CMNODE:7180/api/v8 | |
CDH_MAJOR=`echo $CDH_VER | cut -d'.' -f1` | |
CLUSTER=$(curl -X GET -s -u "$USERNAME:$USERPASS" $BASE/clusters | grep '"name"' | awk -F'"' '{print $4}') | |
nodes=$(curl -X GET -s -u "$USERNAME:$USERPASS" $BASE/hosts | grep hostname | awk -F'"' '{print $4}') | |
cluster_wait () { | |
while [ 1 ]; do | |
sleep 5 | |
curl -s -u "$USERNAME:$USERPASS" $BASE/clusters/$CLUSTER/commands | grep id > /dev/null | |
if [ $? -ne 0 ]; then break; fi | |
done | |
} | |
service_wait() { | |
while [ 1 ]; do | |
sleep 5 | |
curl -s -u "$USERNAME:$USERPASS" $BASE/clusters/$CLUSTER/services/$1/commands | grep id > /dev/null | |
if [ $? -ne 0 ]; then break; fi | |
done | |
} | |
# Adding ZooKeeper Server | |
ZK=$(curl -X GET -s -u "$USERNAME:$USERPASS" $BASE/clusters/$CLUSTER/services | grep -b1 '"type" : "ZOOKEEPER"' | grep '"name"' | awk -F'"' '{print $4}') | |
zk2=`curl -X GET -s -u "admin:admin" $BASE/hosts | grep hostId | awk -F'"' '(NR==2){print $4}'` | |
zk3=`curl -X GET -s -u "admin:admin" $BASE/hosts | grep hostId | awk -F'"' '(NR==3){print $4}'` | |
curl -X POST -s -u "$USERNAME:$USERPASS" \ | |
-H "content-type:application/json" \ | |
-d '{ "items": [ | |
{"type": "SERVER", | |
"hostRef": {"hostId": "'$zk2'"}}, | |
{"type": "SERVER", | |
"hostRef": {"hostId": "'$zk3'"}}] | |
}' \ | |
$BASE/clusters/$CLUSTER/services/$ZK/roles | |
service_wait $ZK | |
curl -X POST -s -u "$USERNAME:$USERPASS" \ | |
-H "content-type:application/json" \ | |
-d '{ }' \ | |
$BASE/clusters/$CLUSTER/commands/restart | |
cluster_wait | |
# HDFS HA | |
HDFS=$(curl -X GET -s -u "$USERNAME:$USERPASS" $BASE/clusters/$CLUSTER/services | grep -b1 '"type" : "HDFS"' | grep '"name"' | awk -F'"' '{print $4}') | |
actName=`curl -X GET -s -u "admin:admin" $BASE/clusters/$CLUSTER/services/$HDFS/roles | grep "${HDFS}-NAMENODE-" | grep name | awk -F'"' '{print $4}'` | |
stdName=`curl -X GET -s -u "admin:admin" $BASE/hosts | grep hostId | awk -F'"' '(NR==2){print $4}'` | |
jn1=`curl -X GET -s -u "admin:admin" $BASE/hosts | grep hostId | awk -F'"' '(NR==2){print $4}'` | |
jn2=`curl -X GET -s -u "admin:admin" $BASE/hosts | grep hostId | awk -F'"' '(NR==3){print $4}'` | |
jn3=`curl -X GET -s -u "admin:admin" $BASE/hosts | grep hostId | awk -F'"' '(NR==4){print $4}'` | |
curl -X POST -s -u "$USERNAME:$USERPASS" \ | |
-H "content-type:application/json" \ | |
-d '{ "activeNnName": "'$actName'", | |
"standbyNnHostId": "'$stdName'", | |
"nameservice": "nameservice1", | |
"jns" : [{"jnHostId": "'$jn1'", "jnEditsDir": "/dfs/edits"}, | |
{"jnHostId": "'$jn2'", "jnEditsDir": "/dfs/edits"}, | |
{"jnHostId": "'$jn3'", "jnEditsDir": "/dfs/edits"}] | |
}' \ | |
$BASE/clusters/$CLUSTER/services/$HDFS/commands/hdfsEnableNnHa | |
service_wait $HDFS | |
curl -X POST -s -u "$USERNAME:$USERPASS" $BASE/clusters/$CLUSTER/commands/deployClientConfig | |
cluster_wait | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment