Apache Zookeeper Cluster Cookie

环境与基础

  • Debian 11
  • OpenJDK 11
  • Zookeeper 3.6.3

部署方式

node1,node2,node3 均安装 Hadoop

所有机器 /etc/hosts 文件

1
2
3
172.16.11.6 node1
172.16.11.7 node2
172.16.11.8 node3

配置ssh-key

在每台机器node1, node2, node3 中复制ssh-key

1
2
3
4
ssh-keygen -b 4096
ssh-copy-id dev@node1
ssh-copy-id dev@node2
ssh-copy-id dev@node3

安装JDK11

每台机器安装JDK11

1
2
apt-get update && apt-get upgrade
apt-get install openjdk-11-jre openjdk-11-jdk

查看JDK安装位置

1
update-alternatives  --display java

配置Zookeeper

在每个node下载 zk 并解压至 /data/apache-zookeeper-3.6.3-bin

在每个node创建目录/data/zookeeper-data 用于做为zk存储目录

node1

1
2
3
4
5
6
7
8
9
10
11
12
13
echo 1 >> /data/zookeeper-data/myid
cp /data/apache-zookeeper-3.6.3-bin/conf/zoo_sample.cfg /data/apache-zookeeper-3.6.3-bin/conf/zoo.cfg
vim /data/apache-zookeeper-3.6.3-bin/conf/zoo.cfg

---
dataDir=/data/zookeeper-data
server.1=node1:2888:3888
server.2=node2:2888:3888
server.3=node3:2888:3888
---

/data/apache-zookeeper-3.6.3-bin/bin/zkServer.sh start

node2

1
2
3
4
5
6
7
8
9
10
11
12
13
echo 2 >> /data/zookeeper-data/myid
cp /data/apache-zookeeper-3.6.3-bin/conf/zoo_sample.cfg /data/apache-zookeeper-3.6.3-bin/conf/zoo.cfg
vim /data/apache-zookeeper-3.6.3-bin/conf/zoo.cfg

---
dataDir=/data/zookeeper-data
server.1=node1:2888:3888
server.2=node2:2888:3888
server.3=node3:2888:3888
---

/data/apache-zookeeper-3.6.3-bin/bin/zkServer.sh start

node3

1
2
3
4
5
6
7
8
9
10
11
12
13
echo 3 >> /data/zookeeper-data/myid
cp /data/apache-zookeeper-3.6.3-bin/conf/zoo_sample.cfg /data/apache-zookeeper-3.6.3-bin/conf/zoo.cfg
vim /data/apache-zookeeper-3.6.3-bin/conf/zoo.cfg

---
dataDir=/data/zookeeper-data
server.1=node1:2888:3888
server.2=node2:2888:3888
server.3=node3:2888:3888
---

/data/apache-zookeeper-3.6.3-bin/bin/zkServer.sh start

server.1=node1:2888:3888 配置

  • 1 与myid 相同
  • node1 服务器的IP或者hostname
  • 2888 与Leader通信
  • 3888 选举通信

查看zk是否启动

jps 后查看是否有 QuorumPeerMain 进程