Added install script for zookeeper
This script installs zookeeper. The script expects a unique ID for the node being provisioned and a list of IPs for all zookeeper nodes. The script has been tested on Ubuntu 14.04 (trusty) and Debian 7 (wheezy). The included Vagrantfile can be used to bring up a 3 node test cluster. Change-Id: Ie0e75a71601546f47d55e25c6889efd3c034bedb
This commit is contained in:
parent
5bf925e449
commit
32e0624d57
|
@ -0,0 +1,40 @@
|
|||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
$vm_count = 3
|
||||
$hostname = File.basename(File.dirname(__FILE__))
|
||||
$domain = "localdomain"
|
||||
$ip_prefix = "10.250.250"
|
||||
#$pkg_mirror = "http://localhost/mirror"
|
||||
|
||||
|
||||
$ip_list = ""
|
||||
(1..$vm_count).each do |i|
|
||||
$ip_list += "#{$ip_prefix}.#{100+i} "
|
||||
end
|
||||
|
||||
VAGRANTFILE_API_VERSION = "2"
|
||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
config.vm.box = "sputnik13/wheezy64"
|
||||
if Vagrant.has_plugin?("vagrant-hostmanager")
|
||||
config.hostmanager.enabled = true
|
||||
config.hostmanager.manage_host = false
|
||||
config.hostmanager.ignore_private_ip = false
|
||||
config.hostmanager.include_offline = true
|
||||
end
|
||||
|
||||
config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'"
|
||||
|
||||
(1..$vm_count).each do |i|
|
||||
config.vm.define "#{$hostname}#{i}" do |node|
|
||||
node.vm.hostname = "#{$hostname}#{i}"
|
||||
node.vm.network :private_network, ip: "#{$ip_prefix}.#{100+i}", :netmask => "255.255.255.0"
|
||||
node.hostmanager.aliases = ["#{$hostname}#{i}.#{$domain}", "#{$hostname}#{i}"]
|
||||
|
||||
if $pkg_mirror then
|
||||
node.vm.provision "shell", inline: "sed -e 's/http:\/\/.*.archive.ubuntu.com/http:\/\/#{$pkg_mirror}/' -i /etc/apt/sources.list ; apt-get update"
|
||||
end
|
||||
node.vm.provision "shell", inline: "/vagrant/install.sh -n #{$vm_count} #{i} #{$ip_list}"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,87 @@
|
|||
#!/bin/bash
|
||||
|
||||
ZOOKEEPER_COUNT=1
|
||||
|
||||
if [[ -f '/etc/issue' ]]; then
|
||||
LINUX_DISTRO=`cat /etc/issue | egrep 'Amazon|Ubuntu|CentOS|RedHat|Debian' | awk -F' ' '{print $1}'`
|
||||
elif [[ -f '/etc/debian_version' ]]; then
|
||||
LINUX_DISTRO='Debian'
|
||||
fi
|
||||
|
||||
function usage {
|
||||
echo "usage: $0 [-n count] [-h] MYID IP_1 ... IP_N"
|
||||
exit -1
|
||||
}
|
||||
|
||||
while getopts n:h opt; do
|
||||
case $opt in
|
||||
n)
|
||||
ZOOKEEPER_COUNT=$OPTARG
|
||||
;;
|
||||
h)
|
||||
usage
|
||||
esac
|
||||
done
|
||||
|
||||
# Pop processed options from the option stack
|
||||
OPTIND=$OPTIND-1
|
||||
shift $OPTIND
|
||||
|
||||
if [[ ! $# -gt $ZOOKEEPER_COUNT ]]; then
|
||||
echo "Invalid number of arguments"
|
||||
echo ""
|
||||
usage
|
||||
fi
|
||||
|
||||
ZK_MYID=$1
|
||||
shift
|
||||
|
||||
for i in `seq 1 $ZOOKEEPER_COUNT`; do
|
||||
ZK_SERVER_IP[$i]=$1
|
||||
shift
|
||||
done
|
||||
|
||||
# Check for root permissions
|
||||
if [ "$(id -u)" != "0" ]; then
|
||||
SUDO='sudo'
|
||||
echo ""
|
||||
echo "This script is not being run as root, you may be asked for a password in order to execute sudo.."
|
||||
echo ""
|
||||
else
|
||||
SUDO=
|
||||
fi
|
||||
|
||||
# Set distro specific values
|
||||
case "$LINUX_DISTRO" in
|
||||
'Ubuntu'|'Debian')
|
||||
UPDATE_PKG='apt-get update'
|
||||
INSTALL_PKG='apt-get install -y'
|
||||
PKG_NAME='zookeeper zookeeper-bin zookeeperd'
|
||||
CONFIG_FILE='/etc/zookeeper/conf/zoo.cfg'
|
||||
SERVICE_NAME='zookeeper'
|
||||
MYID_FILE='/var/lib/zookeeper/myid'
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Only Ubuntu and Debian are supported at this time"
|
||||
exit -1
|
||||
esac
|
||||
|
||||
# Update package cache if necessary
|
||||
if $UPDATE_PKG; then
|
||||
$SUDO $UPDATE_PKG
|
||||
fi
|
||||
|
||||
# Install package
|
||||
$SUDO $INSTALL_PKG $PKG_NAME
|
||||
|
||||
# Generate configuration
|
||||
$SUDO sed -i.bak -e '/^#.*$/d' -e '/^$/d' -e '/^server\..*=.*/d' $CONFIG_FILE
|
||||
for i in `seq 1 $ZOOKEEPER_COUNT`; do
|
||||
echo "server.${i}=${ZK_SERVER_IP[$i]}:2888:3888" >> $CONFIG_FILE
|
||||
done
|
||||
|
||||
echo $ZK_MYID > $MYID_FILE
|
||||
|
||||
# Restart service
|
||||
$SUDO service $SERVICE_NAME restart
|
Loading…
Reference in New Issue