CentOS7安装Zookeeper伪集群

准备

   1. 服务器上先安装好JDK

安装zookeeper单机版

cd /opt
wget https://archive.apache.org/dist/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
tar -xzhf ./zookeeper-3.4.14.tar.gz
cp /zookeeper-3.4.14/zoo_sample.cfg .//zookeeper-3.4.14/zoo.cfg

安装zookeeper集群

cd /opt
mkdir zookeeper_cluster
cd zookeeper_cluster
 cp -fr /opt/zookeeper-3.4.14 /opt/zookeeper_cluster/1
 cp -fr /opt/zookeeper-3.4.14 /opt/zookeeper_cluster/2
 cp -fr /opt/zookeeper-3.4.14 /opt/zookeeper_cluster/3

mkdir -p /opt/zookeeper_cluster/1/data
mkdir -p /opt/zookeeper_cluster/1/log
sed -i 's/dataDir=.*/dataDir=\/opt\/zookeeper_cluster\/1\/data/g'  ./1/conf/zoo.cfg  
echo 'dataLogDir=/opt/zookeeper_cluster/1/log' >> ./1/conf/zoo.cfg
sed -i 's/clientPort=2181/clientPort=2181/g'  ./1/conf/zoo.cfg
echo 'server.1=192.168.0.180:2881:3881' >> ./1/conf/zoo.cfg
echo 'server.2=192.168.0.180:2882:3882' >> ./1/conf/zoo.cfg
echo 'server.3=192.168.0.180:2883:3883' >> ./1/conf/zoo.cfg
echo '4lw.commands.whitelist=*' >> ./1/conf/zoo.cfg
echo '1' > ./1/data/myid

mkdir -p /opt/zookeeper_cluster/2/data
mkdir -p /opt/zookeeper_cluster/2/log
sed -i 's/dataDir=.*/dataDir=\/opt\/zookeeper_cluster\/2\/data/g'  ./2/conf/zoo.cfg  
echo 'dataLogDir=/opt/zookeeper_cluster/2/log' >> ./2/conf/zoo.cfg
sed -i 's/clientPort=2181/clientPort=2182/g'  ./2/conf/zoo.cfg
echo 'server.1=192.168.0.180:2881:3881' >> ./2/conf/zoo.cfg
echo 'server.2=192.168.0.180:2882:3882' >> ./2/conf/zoo.cfg
echo 'server.3=192.168.0.180:2883:3883' >> ./2/conf/zoo.cfg
echo '4lw.commands.whitelist=*' >> ./2/conf/zoo.cfg
echo '2' > ./2/data/myid


mkdir -p /opt/zookeeper_cluster/3/data
mkdir -p /opt/zookeeper_cluster/3/log
sed -i 's/dataDir=.*/dataDir=\/opt\/zookeeper_cluster\/3\/data/g'  ./3/conf/zoo.cfg  
echo 'dataLogDir=/opt/zookeeper_cluster/3/log' >> ./3/conf/zoo.cfg
sed -i 's/clientPort=2181/clientPort=2183/g'  ./3/conf/zoo.cfg
echo 'server.1=192.168.0.180:2881:3881' >> ./3/conf/zoo.cfg
echo 'server.2=192.168.0.180:2882:3882' >> ./3/conf/zoo.cfg
echo 'server.3=192.168.0.180:2883:3883' >> ./3/conf/zoo.cfg
echo '4lw.commands.whitelist=*' >> ./3/conf/zoo.cfg
echo '3' > ./3/data/myid

    启动脚本

   

#!/bin/bash

cd /opt/zookeeper_cluster
./1/bin/zkServer.sh start
./2/bin/zkServer.sh start
./3/bin/zkServer.sh start

   关闭脚本

   

#!/bin/bash

cd /opt/zookeeper_cluster
./1/bin/zkServer.sh stop
./2/bin/zkServer.sh stop
./3/bin/zkServer.sh stop

相关推荐