自动化安装zookeeper脚本
linux下shell编写的zookeeper自动化安装脚本
欢迎关注“程序杂货铺”公众号,里面有精彩内容,欢迎大家收看^_^
1.自动化安装zookeeper
1.run.sh:
#参数1:zk的压缩包地址(后缀为.tar.gz)
#参数2:zk解压后目录
#参数3:zk存储data的目录
#参数4:zk运行log的目录
#参数5:集群中每个集群的ip(','分割)
#参数6:myid编号
sh makeZookeeperInstall.sh /home/wangyida/software/zookeeper-3.4.6.tar.gz /home/wangyida/software/zookeeper-3.4.6 /home/wangyida/temp/zk/data /home/wangyida/temp/zk/log "127.0.0.1" 1
2.makeZookeeperInstall.sh:
#!/bin/sh
function makeDir()
{
dir=$1
cur_dir=''
OLD_IFS="$IFS"
IFS="/"
arr=($dir)
IFS="$OLD_IFS"
for s in ${arr[@]}
do
cur_dir=''$cur_dir'/'$s''
if [ ! -d "$cur_dir" ]; then
echo 'create dir '$cur_dir
mkdir $cur_dir
fi
done
}
tar_file=$1
tar -zxvf $tar_file
sleep 5
dir=$2
cd $dir/conf/
cp zoo_sample.cfg zoo.cfg
sed -i '/dataDir/d' zoo.cfg
dataDir=$3
makeDir $dataDir
dataLogDir=$4
makeDir $dataLogDir
echo 'dataDir='$dataDir'' >> zoo.cfg
echo 'dataLogDir='$dataLogDir'' >> zoo.cfg
iplist=$5
i=1
for ip in $iplist
do
echo 'server.'$i'='$ip':2888:3888' >> zoo.cfg
i=$(($i+1))
done
cd $dataDir
myid=$6
touch myid
echo $myid > myid
3.设置环境变量:
makeZookeeperEvn.sh
echo 'ZOOKEEPER_HOME='$1'' >> /etc/profile
echo 'PATH=$PATH:$ZOOKEEPER_HOME/bin' >> /etc/profile
echo 'export ZOOKEEPER_HOME' >> /etc/profile
echo 'export PATH' >> /etc/profile
source /etc/profile
4.ReadMe:
安装zookeeper:
运行步骤:
sh run.sh
sudo root
sh makeZookeeperEvn.sh
当集群中每台集群都安装完成后
运行zookeeper:
./zookeeper-3.4.6/bin/zkServer.sh start
./zookeeper-3.4.6/bin/zkServer.sh status
./zookeeper-3.4.6/bin/zkServer.sh stop
注:程序详见:http://download.csdn.net/download/u013473512/10166374
https://github.com/Emmitte/zookeeper
2.zookeeper手动安装及运行步骤:
安装zookeeper
tar -zxvf zookeeper-3.4.6.tar.gz
进入conf目录,创建zoo.cfg
cd zookeeper-3.4.6/conf
cp zoo_sample.cfg zoo.cfg
添加配置信息:
dataDir=/home/zookeeper/data/zookeeper
dataLogDir=/home/zookeeper/log/zookeeper
server.1=ip地址1:2888:3888
server.2=ip地址2:2888:3888
server.3=ip地址3:2888:3888
创建dataDir、dataLogDir:
cd
mkdir data
cd data
mkdir zookeeper
cd
mkdir log
cd log
mkdir zookeeper
创建myid文件
cd
cd data/zookeeper/
touch myid
vi myid
1(即server.后的数字)
修改环境变量:
su root
vi /etc/profile
export ZOOKEEPER_HOME=/home/zookeeper/zookeeper-3.4.6
export PATH=$ZOOKEEPER_HOME/bin:$PATH
export PATH
保存
source /etc/profile
运行zookeeper
./zookeeper-3.4.6/bin/zkServer.sh start
./zookeeper-3.4.6/bin/zkServer.sh status
./zookeeper-3.4.6/bin/zkServer.sh stop
欢迎关注“程序杂货铺”公众号,里面有精彩内容,欢迎大家收看^_^
更多推荐
所有评论(0)