Appendix A. Hadoop Component Start and Stop Scripts
Some Hadoop components, like HDFS and YARN, ship with management scripts that let you start and stop all of their component daemons or servers in one command. Others do not. The scripts here fill those gaps.
Tip
Code is available at this bookâs code repository.
Apache ZooKeeper
The script in Example A-1 starts and stops Apache ZooKeeper servers, assuming each one is running on a worker instance in the cluster. It should be installed on the manager instance and run under the âzkâ account, or any account that has passwordless SSH access to an account on each worker that may control ZooKeeper.
Example A-1. Control script for Apache ZooKeeper
#!/usr/bin/env bash
if
[[
-z$1
]]
;
then
echo
"Syntax:
$0
(start|stop|status)"
exit
fi
# Assumption is that each "slave" hosts a ZooKeeper server
SLAVES
=(
$(
cat /etc/hadoop/slaves)
)
case
"
$1
"
in start)
echo
Starting ZooKeeperfor
s in"
${
SLAVES
[@]
}
"
;
do
ssh"
$s
"
/opt/zookeeper/bin/zkServer.sh startdone
;;
stop)
echo
Stopping ZooKeeperfor
s in"
${
SLAVES
[@]
}
"
;
do
ssh"
$s
"
/opt/zookeeper/bin/zkServer.sh stopdone
;;
status)
echo
Checking ZooKeeper statusfor
s in"
${
SLAVES
[@]
}
"
;
do
ssh"
$s
"
/opt/zookeeper/bin/zkServer.sh statusdone
;;
esac
Get Moving Hadoop to the Cloud now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.