Skip to content

Commit

Permalink
resize hadoop cluster size dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwenlau committed May 22, 2015
1 parent 7154b18 commit 8a0fb96
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
2 changes: 2 additions & 0 deletions hadoop-master/files/slaves
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
master.kiwenlau.com
slave1.kiwenlau.com
slave2.kiwenlau.com
slave3.kiwenlau.com
slave4.kiwenlau.com
33 changes: 33 additions & 0 deletions resize-cluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

tag="0.1.0"

# N is the node number of the cluster
N=$1

if [ $# = 0 ]
then
echo "Please use the node number of the cluster as the argument!"
exit 1
fi

cd hadoop-master

# change the slaves file
echo "master.kiwenlau.com" > files/slaves
i=1
while [ $i -lt $N ]
do
echo "slave$i.kiwenlau.com" >> files/slaves
((i++))
done

# delete master container
sudo docker rm -f master

# delete hadoop-master image
sudo docker rmi kiwenlau/hadoop-master:$tag

# rebuild hadoop-master image
pwd
sudo docker build -t kiwenlau/hadoop-master:$tag .
18 changes: 9 additions & 9 deletions start-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ then
fi


# start master container
sudo docker run -d -t --dns 127.0.0.1 -P --name master -h master.kiwenlau.com -w /root kiwenlau/hadoop-master:0.1.0
# delete old master container and start new master container
sudo docker rm -f master &> /dev/null
echo "start master container..."
sudo docker run -d -t --dns 127.0.0.1 -P --name master -h master.kiwenlau.com -w /root kiwenlau/hadoop-master:0.1.0 &> /dev/null

# get the IP address of master container
FIRST_IP=$(docker inspect --format="{{.NetworkSettings.IPAddress}}" master)

# delete old slave containers and start new slave containers
i=1
while [ $i -le $N ]
while [ $i -lt $N ]
do
sudo docker run -d -t --dns 127.0.0.1 -P --name slave$i -h slave$i.kiwenlau.com -e JOIN_IP=$FIRST_IP kiwenlau/hadoop-slave:0.1.0
sudo docker rm -f slave$i &> /dev/null
echo "start slave$i container..."
sudo docker run -d -t --dns 127.0.0.1 -P --name slave$i -h slave$i.kiwenlau.com -e JOIN_IP=$FIRST_IP kiwenlau/hadoop-slave:0.1.0 &> /dev/null
((i++))
done

# start slave1 container
#sudo docker run -d -t --dns 127.0.0.1 -P --name slave1 -h slave1.kiwenlau.com -e JOIN_IP=$FIRST_IP kiwenlau/hadoop-slave:0.1.0

# start slave2 container
#sudo docker run -d -t --dns 127.0.0.1 -P --name slave2 -h slave2.kiwenlau.com -e JOIN_IP=$FIRST_IP kiwenlau/hadoop-slave:0.1.0

# create a new Bash session in the master container
sudo docker exec -it master bash

0 comments on commit 8a0fb96

Please sign in to comment.