环境: VMware Workstation 16 Pro、Ubuntu18.04、java version “1.8.0_301”、Hadoop 3.1.3
在 /usr/local 创建 zookeeper 目录结构
root@wyc:~# cd /usr/local
root@wyc:/usr/local# mkdir zookeeper
root@wyc:/usr/local# cd zookeeper/
# zoo_1/2/3 用于存放节点的快照
root@wyc:/usr/local/zookeeper# mkdir zoo_1
root@wyc:/usr/local/zookeeper# mkdir zoo_2
root@wyc:/usr/local/zookeeper# mkdir zoo_3
# zoo_1/2/3_dataLog 用于存放节点的事务日志
root@wyc:/usr/local/zookeeper# mkdir zoo_1_dataLog
root@wyc:/usr/local/zookeeper# mkdir zoo_2_dataLog
root@wyc:/usr/local/zookeeper# mkdir zoo_3_dataLog
用 Xftp 把 zookeeper 压缩包(提取码: ej2w)上传到上面新建的 zookeeper 文件夹内,解压
root@wyc:/usr/local/zookeeper# tar -zxvf zookeeper-3.4.0.tar.gz
配置环境
root@wyc:/usr/local/zookeeper# vim ~/.bashrc
在文件末尾处添加以下几行内容:
export ZK_HOME=/usr/local/zookeeper/zookeeper-3.4.0
export PATH=$PATH:$ZK_HOME/bin
保存并退出,接着使我们刚加入的环境变量生效:
root@wyc:/usr/local/zookeeper# source ~/.bashrc
输入 zk 利用 tab 键补全如果有如图的命令选项则环境变量配置成功:
每个节点赋予节点标识命令如下:
#server1
echo "1" > /usr/local/zookeeper/zoo_1/myid
#server2
echo "2" > /usr/local/zookeeper/zoo_2/myid
#server3
echo "3" > /usr/local/zookeeper/zoo_3/myid
root@wyc:/usr/local/zookeeper# cd /usr/local/zookeeper/zookeeper-3.4.0/conf
root@wyc:/usr/local/zookeeper/zookeeper-3.4.0/conf# cp zoo_sample.cfg zoo1.cfg
root@wyc:/usr/local/zookeeper/zookeeper-3.4.0/conf# cp zoo_sample.cfg zoo2.cfg
root@wyc:/usr/local/zookeeper/zookeeper-3.4.0/conf# cp zoo_sample.cfg zoo3.cfg
三个节点的配置文件只有dataDir、dataLogDir、clientPort不同
root@wyc:/usr/local/zookeeper/zookeeper-3.4.0/conf# vim zoo1.cfg
添加或者修改以下几行内容:
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/zookeeper/zoo_1
dataLogDir=/usr/local/zookeeper/zoo_1_dataLog
clientPort=2181
server.1=localhost:2887:3887
server.2=localhost:2888:3888
server.3=localhost:2889:3889
root@wyc:/usr/local/zookeeper/zookeeper-3.4.0/conf# vim zoo2.cfg
添加或者修改以下几行内容:
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/zookeeper/zoo_2
dataLogDir=/usr/local/zookeeper/zoo_2_dataLog
clientPort=2182
server.1=localhost:2887:3887
server.2=localhost:2888:3888
server.3=localhost:2889:3889
root@wyc:/usr/local/zookeeper/zookeeper-3.4.0/conf# vim zoo3.cfg
添加或者修改以下几行内容:
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/zookeeper/zoo_3
dataLogDir=/usr/local/zookeeper/zoo_3_dataLog
clientPort=2183
server.1=localhost:2887:3887
server.2=localhost:2888:3888
server.3=localhost:2889:3889
root@wyc:/usr/local/zookeeper/zookeeper-3.4.0# bin/zkServer.sh start zoo1.cfg
root@wyc:/usr/local/zookeeper/zookeeper-3.4.0# bin/zkServer.sh start zoo2.cfg
root@wyc:/usr/local/zookeeper/zookeeper-3.4.0# bin/zkServer.sh start zoo3.cfg
root@wyc:/usr/local/zookeeper/zookeeper-3.4.0# bin/zkServer.sh status conf/zoo1.cfg
root@wyc:/usr/local/zookeeper/zookeeper-3.4.0# bin/zkServer.sh status conf/zoo2.cfg
root@wyc:/usr/local/zookeeper/zookeeper-3.4.0# bin/zkServer.sh status conf/zoo3.cfg