0%

Zookeeper学习笔记

本文主要包括:

  • Zookeeper简介
  • Zookeeper可以干什么?
  • Zookeeper安装与启动
  • Zookeeper常用操作

    Zookeeper简介

Zookeeper可以干什么?

Zookeeper安装与启动

Zookeeper安装

Zookeeper需要用到java,安装前需要安装java,这里省略
官网下载Zookeeper安装包,并解压

tar zxvf zookeeper-3.4.6.tar.gz -C .
cd zookeeper-3.4.6/conf
cp zoo_sample.cfg zoo.cfg 

修改zoo.cfg

# The number of milliseconds of each tick
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=/opt/modules/zookeeper-3.4.6/zkData
dataLogDir=/opt/modules/zookeeper-3.4.6/zkDataLog
# the port at which the clients will connect
clientPort=2181

这里设置了dataDir和dataLogDir,手动生成了这两个文件,不知道会不会自动生成
最后,设置Zookeeper的环境变量

Zookeeper启动等操作

# 启动
cd /opt/modules/zookeeper-3.4.6/ && bin/zkServer.sh start
# 关闭
cd /opt/modules/zookeeper-3.4.6/ && bin/zkServer.sh stop
# 查看ZK服务状态
cd /opt/modules/zookeeper-3.4.6/ && bin/zkServer.sh status
#  重启ZK服务
cd /opt/modules/zookeeper-3.4.6/ && bin/zkServer.sh restart

Zookeeper操作样例