解压文件
tar -zxvf zookeeper-3.4.10.tar.gz
mv zookeeper-3.4.10 /opt/zookeeper/zookeeper3.4
修改配置文件
cd /opt/zookeeper/zookeeper3.4/
cp conf/zoo_sample.cfg conf/zoo_1.cfg
vi conf/zoo_1.cfg
dataDir=/opt/zookeeper/zookeeper3.4/data/zk1
clientPort=2181
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890
cat conf/zoo_1.cfg > conf/zoo_2.cfg
vi conf/zoo_2.cfg
dataDir=/opt/zookeeper/zookeeper3.4/data/zk2
clientPort=2182
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890
cat conf/zoo_1.cfg > conf/zoo_3.cfg
vi conf/zoo_3.cfg
dataDir=/opt/zookeeper/zookeeper3.4/data/zk3
clientPort=2183
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890
mkdir -p data/zk1
mkdir -p data/zk2
mkdir -p data/zk3
# 给每一个zookeeper服务添加唯一标识ID,来标识是哪一个server
echo 1 > data/zk1/myid
echo 2 > data/zk2/myid
echo 3 > data/zk3/myid
启动zookeeper
# 使用配置文件来启动三个zookeeper服务
./bin/zkServer.sh start conf/zoo_1.cfg
./bin/zkServer.sh start conf/zoo_2.cfg
./bin/zkServer.sh start conf/zoo_3.cfg
# 查看三个zookeeper的状态
./bin/zkServer.sh status conf/zoo_1.cfg
./bin/zkServer.sh status conf/zoo_2.cfg
./bin/zkServer.sh status conf/zoo_3.cfg
# 关闭服务
./bin/zkServer.sh stop conf/zoo_1.cfg
# 启动zookeeper的客户端
./bin/zkCli.sh -server localhost:2182