Zookeeper的安装与使用

安装

Step1:下载

官网地址:https://www.apache.org/dyn/closer.lua/zookeeper/zookeeper-3.6.2/apache-zookeeper-3.6.2-bin.tar.gz

linux执行

wget https://www.apache.org/dyn/closer.lua/zookeeper/zookeeper-3.6.2/apache-zookeeper-3.6.2-bin.tar.gz

下载显示

Step2:解压

tar -zxvf apache-zookeeper-3.6.2-bin.tar.gz 

在这里插入图片描述解压后目录:
在这里插入图片描述目录说明

  • bin目录
    zk的可执行脚本目录,包括zk服务进程,zk客户端,等脚本。其中,.sh是Linux环境下的脚本,.cmd是Windows环境下的脚本。
  • conf目录
    配置文件目录。zoo_sample.cfg为样例配置文件,需要修改为自己的名称,一般为zoo.cfg。log4j.properties为日志配置文件。
  • lib
    zk依赖的包。

Step3:集群模式

在集群模式下,建议至少部署3个zk进程,或者部署奇数个zk进程。本安装示例采用伪集群模式。

复制zookeeper实例

在同一台主机上,通过复制得到三个zookeeper实例

cp -r apache-zookeeper-3.6.2-bin apache-zookeeper-3.6.2-bin1
cp -r apache-zookeeper-3.6.2-bin apache-zookeeper-3.6.2-bin2

复制成功后如图
在这里插入图片描述

配置zoo.conf 文件

执行命令

cd conf
cp zoo_sample.cfg zoo.cfg

修改zoo.cfg文件

  • apache-zookeeper-3.6.2-bin对应配置文件
tickTime=2000
initLimit=5
syncLimit=2
dataDir=/home/wangqingshan/soft/apache-zookeeper-3.6.2-bin/data
dataLogDir=/home/wangqingshan/soft/apache-zookeeper-3.6.2-bin/logs
clientPort=12181

server.1=127.0.0.1:12888:13888
server.2=127.0.0.1:14888:15888
server.3=127.0.0.1:16888:17888

备注:server.1中的数字1为服务器的ID,需要与myid文件中的id一致,配置myid命令:

echo '1' > data/myid
  • apache-zookeeper-3.6.2-bin1对应配置文件
tickTime=2000
initLimit=5
syncLimit=2
dataDir=/home/wangqingshan/soft/apache-zookeeper-3.6.2-bin1/data
dataLogDir=/home/wangqingshan/soft/apache-zookeeper-3.6.2-bin1/logs
clientPort=12182

server.1=127.0.0.1:12888:13888
server.2=127.0.0.1:14888:15888
server.3=127.0.0.1:16888:17888

配置myid命令:

echo '2' > data/myid
  • apache-zookeeper-3.6.2-bin2对应配置文件
tickTime=2000
initLimit=5
syncLimit=2
dataDir=/home/wangqingshan/soft/apache-zookeeper-3.6.2-bin2/data
dataLogDir=/home/wangqingshan/soft/apache-zookeeper-3.6.2-bin2/logs
clientPort=12183

server.1=127.0.0.1:12888:13888
server.2=127.0.0.1:14888:15888
server.3=127.0.0.1:16888:17888

配置myid命令:

echo '3' > data/myid

节点启动

启动&状态查看

./zkServer.sh  start      //启动
./zkServer.sh status    //查看状态

在这里插入图片描述

基本使用

待完善…

附录

安装JDK

  • 下载
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u141-linux-x64.tar.gz"
  • 拷贝到usr目录,解压
cp jdk-8u141-linux-x64.tar.gz /usr/jdk-8u141-linux-x64.tar.gz 
tar -zxvf jdk-8u141-linux-x64.tar.gz 

解压后目录:jdk1.8.0_141

  • 设置环境变量

vi /etc/profile

#Java Env
export JAVA_HOME=/usr/jdk1.8.0_141
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
  • 使环境变量生效
    source /etc/profile
  • 版本查看

配置说明

Zookeeper配置文件说明

# The number of milliseconds of each tick
# tickTime:CS通信心跳数
# Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。tickTime以毫秒为单位。
tickTime=2000

# The number of ticks that the initial
# synchronization phase can take
# initLimit:LF初始通信时限
# 集群中的follower服务器(F)与leader服务器(L)之间初始连接时能容忍的最多心跳数(tickTime的数量)。
initLimit=5

# The number of ticks that can pass between
# sending a request and getting an acknowledgement
# syncLimit:LF同步通信时限
# 集群中的follower服务器与leader服务器之间请求和应答之间能容忍的最多心跳数(tickTime的数量)。
syncLimit=2

# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
# dataDir:数据文件目录
# Zookeeper保存数据的目录,默认情况下,Zookeeper将写数据的日志文件也保存在这个目录里。
dataDir=/data/soft/zookeeper-3.4.12/data


# dataLogDir:日志文件目录
# Zookeeper保存日志文件的目录。
dataLogDir=/data/soft/zookeeper-3.4.12/logs

# the port at which the clients will connect
# clientPort:客户端连接端口
# 客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。
clientPort=2181

# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir 保留数量3
autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature 清理时间间隔1小时
autopurge.purgeInterval=1


# 服务器名称与地址:集群信息(服务器编号,服务器地址,LF通信端口,选举端口)
# 这个配置项的书写格式比较特殊,规则如下:

# server.N=YYY:A:B

# 其中N表示服务器编号,YYY表示服务器的IP地址,A为LF通信端口,表示该服务器与集群中的leader交换的信息的端口。B为选举端口,表示选举新leader时服务器间相互通信的端口(当leader挂掉时,其余服务器会相互通信,选择出新的leader)。一般来说,集群中每个服务器的A端口都是一样,每个服务器的B端口也是一样。但是当所采用的为伪集群时,IP地址都一样,只能时A端口和B端口不一样。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值