Apache-Zookeeper3.7.1安装

沈单弓
2023-12-01

1. 安装 JAVA 环境

1.安装 JDK

tar -zxvf jdk-8u261-linux-x64.tar.gz -C /opt/soft/

2.配置 root 用户环境变量 在.bash_profile 中添加 java 环境变量

vim /etc/profile

export JAVA_HOME=/opt/soft/jdk1.8.0_261 
export PATH=$PATH:$JAVA_HOME/bin

source /etc/profile

验证是否安装成功

java -version

2. Zookeeper安装

2.1. 下载安装包

https://archive.apache.org/dist/zookeeper/

2.2. 上传安装包

下载 apache-zookeeper-3.7.1-bin.tar.gz安装包,放置到上面三台服务器一个目录下(/opt/package)

2.3. 解压安装包

进入到/apps/目录下,解压tar包

tar -zxvf apache-zookeeper-3.7.1-bin.tar.gz -C /opt/soft
mv apache-zookeeper-3.7.1-bin/ zookeeper-3.7.1

2.4. 修改配置文件

  1. 进入zookeeper的conf目录,拷贝zoo_sample.cfg为zoo.cfg,cp zoo_sample.cfg zoo.cfg 修改zoo.cfg文件:

cd /opt/soft/zookeeper-3.7.1/conf
cp zoo_sample.cfg zoo.cfg

vim zoo.cfg

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/soft/zookeeper-3.7.1/data/zookeeper
dataLogDir=/opt/soft/zookeeper-3.7.1/logs/zookeeper
clientPort=2181
autopurge.purgeInterval=0
globalOutstandingLimit=200
server.1=node01:2888:3888
server.2=node02:2888:3888
server.3=node03:2888:3888
  1. 创建需要的目录(所有节点)

mkdir -p /opt/soft/zookeeper-3.7.1/data/zookeeper
mkdir -p /opt/soft/zookeeper-3.7.1/logs/zookeeper

配置完成后将当前的zookeeper目录同步到其他两个节点

ssh_do_scp.sh ~/bin/node.list /opt/soft/zookeeper-3.7.1 /opt/soft/

  1. 设置myid

vim /opt/soft/zookeeper-3.7.1/data/zookeeper/myid

node01为1,
node02为2,
node03为3

2.5. 配置环境变量

vim /etc/profile

export ZOOKEEPER_HOME=/opt/soft/zookeeper-3.7.1
export PATH=$PATH:$ZOOKEEPER_HOME/bin

source /etc/profile

3 启动Zookeeper服务

  1. 进入zookeeper的bin目录,启动zookeeper服务,每个节点都需要启动

cd /opt/soft/zookeeper-3.7.1

zkServer.sh start

  1. 启动之后查看每个节点的状态

zkServer.sh status

其中有一个节点是leader,有两个节点是follower,证明zookeeper集群是部署成功的。

[root@node01 zookeeper-3.7.1]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/soft/zookeeper-3.7.1/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
[root@node02 zookeeper-3.7.1]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/soft/zookeeper-3.7.1/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: leader
[root@node03 zookeeper-3.7.1]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/soft/zookeeper-3.7.1/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
  1. 测试zookeeper
zkCli.sh -server localhost:2181
zkCli.sh -server node01/node02/node03:2181

如果出现拒绝连接,查看防火墙是否关闭,关闭防火墙service iptables stop重启zookeeper,或排查是否配置有误

创建目录成功

[zk: localhost:2181(CONNECTED) 1] create /test 111
Created /test
[zk: localhost:2181(CONNECTED) 2] ls /
[test, zookeeper]
[zk: localhost:2181(CONNECTED) 3] get /test
111
 类似资料: