1. 获取安装包
Zookeeper官网 : https://zookeeper.apache.org/
进入 /usr/local 目录下
cd /usr/local
wget 安装
yum -y install wget
使用wget命令直接在linux中获取安装包
wget https://dlcdn.apache.org/zookeeper/zookeeper-3.7.1/apache-zookeeper-3.7.1-bin.tar.gz
如果遇到这个问题
错误: 无法验证 dlcdn.apache.org 的由 “/C=US/O=Let's Encrypt/CN=R3” 颁发的证书:颁发的证书已经过期。
输入如下命令
yum install -y ca-certificates
再重新下载安装包,等待下载
…
1. 安装准备
安装zk需要jdk环境,请自主安装!
解压
tar -zxvf apache-zookeeper-3.7.1-bin.tar.gz
重命名,也可以不重命名
mv apache-zookeeper-3.7.1-bin zookeeper-3.7.1
创建zookeeper文件夹
mkdir zookeeper
将解压后的文件放入此文件夹中
mv zookeeper-3.7.1 /usr/local/zookeeper
…
3. 文件配置
进入zookeeper-3.7.1下面的conf
cd zookeeper-3.7.1/conf
更改配置文件名
mv zoo_sample.cfg zoo.cfg
修改配置文件内容
dataDir=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/dataLog
保存
附一下我的zoo.cof配置文件
#客户端端口
admin.serverPort=21819
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/dataLog
# the port at which the clients will connect
#服务端口
clientPort=2181
# 保存的数据快照数量,之外的将会被清除
autopurge.snapRetainCount=3
#⾃动触发清除任务时间间隔,⼩时为单位。默认为0,表示不⾃动清除。
autopurge.purgeInterval=1
…
4. 启动
进入bin/目录中,启动zk服务器,指定启动的配置文件
./zkServer.sh start
查看zk状态
./zkServer.sh status
关闭zk服务器
./zkServer.sh stop
…
5. 客户端命令
在 /bin 目录下,执行 ./zkCli.sh 进入客户端
执行 ls / 查看节点
执行create /zk01 创建一个节点
客户端关闭按 Ctrl+C
6. 环境变量配置
配置环境变量的目的就是在linux任意目录下都能启动zk和关闭zk,不配置环境变量就需要到zk的安卓目录下执行命令,可自行选择是否配置环境变量.
vim /etc/profile
在profile最下方添加以下配置,这里记得改为自己的安装目录:
#zookeeper
export ZOOKEEPER_HOME=/usr/local/zookeeper/zookeeper-3.7.1
export PATH=$PATH:${ZOOKEEPER_HOME}/bin
编辑完成后执行以下命令使配置生效:
source /etc/profile
配置过后在linux任意目录都能启动和关闭zk,并且也能连接客户端
本文结束