#/bin/bash
#editor by yhzong
#date :2020-07-28
#zookeeper单节点安装脚本
echo "由于zookeeper安装依赖于JDK,所以先安装JDK,再安装zookeeper,此脚本会对
JDK进行检测,如果检测到JDK不在运行,将终止zookeeper的安装************"
#定义变量,包括zk版本号等等
OS=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'`
#定义安装日志文件.没有就创建
install_log=/tmp/install_zookeeper.log
[ -f $install_log ] || touch $install_log
#zookeeper版本号
zk_setup=3.4.14
#zookeeper安装目录
zk_dir=/home/zookeeper
#指定zookeeper的端口号
zk_port=2181
#创建zookeeper的安装目录
mkdir -p ${zk_dir}
#检测JDK是否成功安装
java -version |grep "1.8"
if [ -z $? ];then
echo "*****请执行JDK安装脚本去安装JDK先*****" >> ${install_log}
exit 1
else
echo "您已经成功安装了JDK,现在继续下一步即可" >> ${install_log}
fi
#开始下载zookeeper
echo "上传zookeeper软件包到脚本的同级目录,如果没有的上传的话将会从网上下载相应的安装包" >> ${install_log}
if test -n "`ls -a | grep ${zk_setup} `"
then
echo "您已经成功上传了安装包到同级的目录" >> ${install_log}
else
wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-${zk_setup}.tar.gz >> ${install_log}
fi
#安装zookeeper
tar xvfz zookeeper-${zk_setup}.tar.gz -C ${zk_dir} >> ${install_log}
#配置zookeeper
#创建zookeeper配置文件
touch ${zk_dir}/zookeeper-${zk_setup}/conf/zoo.cfg >> ${install_log}
#创建zookeeper的数据data目录
mkdir -p ${zk_dir}/zookeeper-${zk_setup}/data >> ${install_log}
#开始配置zookeeper配置文件
cat > ${zk_dir}/zookeeper-${zk_setup}/conf/zoo.cfg <<EOF
tickTime=2000
initLimit=10
syncLimit=5
dataDir=${zk_dir}/zookeeper-3.4.6/data
dataLogDir=${zk_dir}/zookeeper-3.4.6/logs
clientPort=${zk_port}
EOF
#启动zookeeper
cd ${zk_dir}/zookeeper-${zk_setup}/bin
./zkServer.sh start
#检测
check_zk=`ps -ef |grep "zookeeper"`
if [ -z "${check_zk}" ];then
echo "************请检查你的配置和日志查看是否有问题*******"
else
echo "************您已经成功安装了zookeeper************"
fi
shell脚本企业实战系列-zookeeper安装
最新推荐文章于 2024-04-28 11:12:55 发布