Bootstrap

zookeeper+kafka集群一键安装脚本

1. zookeeper_kafka_install.sh

#!/bin/bash

read -p "is need to deploy cluster environment[yes|no]: " booleanResult
if [ $booleanResult = "yes" ] || [ $booleanResult = "no" ];then
	echo "input is: "$booleanResult
else
	echo "only input [yes|no]"
	exit
fi
## root path
INSTALL_BESE_URL=/home/bigdata/app
## deployment template path
TGZ_PACKEGER_URL=/home/bigdata/app/base/dev
## install path
INSTALL_PACKEGER_URL=/home/bigdata/app/base/install
## zookeeper tgz name
ZOOKEEPER_TGZ=Auto.BigData.SystemBase.zookeeper.tgz
## kafka tgz name
KAFKA_TGZ=Auto.BigData.SystemBase.kafka.tgz
## zookeeper name
ZOOKEEPER_NAME=zookeeper-3.4.14
## kafka name
KAFKA_NAME=kafka_2.11-1.1.1
## kafka config file path
KAFKA_CONFIG_FILE_PATH=$TGZ_PACKEGER_URL/$KAFKA_NAME/config/server.properties
## remove old file
rm -rf /home/bigdata/app/base
PID=$(ps aux | grep kafka | grep -v grep | awk '{print $2}' )
echo "kafka runnig id is "$PID
## get local ip 
LOCAL_IP=$(ifconfig | grep  inet | grep netmask | grep broadcast | awk '{print $2}' | sed -n '1p')
echo "local ip is "$LOCAL_IP	
LOCAL_PATH=$(pwd)
echo "local path pwd:"$LOCAL_PATH
if [ ! -d $TGZ_PACKEGER_URL ];then
	echo "$TGZ_PACKEGER_URL is not create"
	mkdir -p $TGZ_PACKEGER_URL
else
	echo "$TGZ_PACKEGER_URL is exist"
fi
if [ -e $LOCAL_PATH/$ZOOKEEPER_TGZ ];then
	tar -zxvf $LOCAL_PATH/$ZOOKEEPER_TGZ -C $TGZ_PACKEGER_URL
else 
	echo "zookeeper tgz is not exist,path=$INSTALL_BESE_URL/$ZOOKEEPER_TGZ"
	exit
fi

if [ -e $LOCAL_PATH/$KAFKA_TGZ ];then
	tar -zxvf $LOCAL_PATH/$KAFKA_TGZ -C $TGZ_PACKEGER_URL
else 
	echo "kafka tgz is not exist,path=$INSTALL_BESE_URL/$KAFKA_TGZ"
	exit
fi

if [ ! -d $TGZ_PACKEGER_URL/$ZOOKEEPER_NAME/data ];then
	mkdir $TGZ_PACKEGER_URL/$ZOOKEEPER_NAME/data
fi
START_ZOOKEEPER_FILE_NAME=zookeeper_start.sh
START_KAFKA_FILE_NAME=kafka_start.sh
KILL_ZK_KF_PID_FILE_NAME=kill_zk_kf_pid.sh
cp $LOCAL_PATH/$START_ZOOKEEPER_FILE_NAME $TGZ_PACKEGER_URL
cp $LOCAL_PATH/$START_KAFKA_FILE_NAME $TGZ_PACKEGER_URL
cp $LOCAL_PATH/$KILL_ZK_KF_PID_FILE_NAME $TGZ_PACKEGER_URL
chmod -R 777 $TGZ_PACKEGER_URL/*
echo "end tar tgz!!!!!"


## check user input ip
input_ip_list=""
function check_input_ip_info {
	echo "========start vail ip is it repeated========"
	for ip in $input_ip_list;do
		echo "-------for ip="$ip",inputIpInfo="$inputIpInfo"-----------"
		if [ $ip = $inputIpInfo ]; then
			echo "input ip is already exist: "$input_ip_list
			return 1
		fi
	done
	echo "========end vail ip is it repeated========"
	ping -c 1  -w 100 $inputIpInfo
	if [ $? -eq 0 ];then
		echo "input ip is right"
		input_ip_list=$input_ip_list" $inputIpInfo"
	else
		echo "input ip is error,please reinput"     
	fi
}
## loop set zookeeper property
total_num=0
function loop_set_zookeeper_server_config {
	echo "start set zookeeeper config"
	for ip_obj in $input_ip_list;
	do
		echo $ip_obj
		let total_num++
		server_ip="server.$total_num=$ip_obj:2888:3888"
		echo $server_ip >> $TGZ_PACKEGER_URL/$ZOOKEEPER_NAME/conf/zoo.cfg
		echo "zookeeper server ip $total_num=$server_ip"
	do
;