是一个为分布式应用提供一致性服务的软件。
是一个基于观察者模式设计的分布式服务管理框架,他负责存储和管理大家都关心的数据,然后接受观察者的注册,一旦这些数据的状态发生变化,Zookeeper就负责通知已经在Zookeeper上注册的那些观察者做出相应的反应,从而实现集群中类似Master/Slave管理模式。
zookeeper= 文件系统 + 通知机制
下载:https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/stable/
解压
拷贝到自己的zookeeper工作目录下
进入conf文件夹,拷贝一份配置文件
[root@localhost conf]# cat zoo.cfg
# The number of milliseconds of each tick
# 通信心跳数,zookeeper服务心跳时间,单位毫秒
# zookeeper使用的基本时间,服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个tickTime时间就会发送一个心跳
# 用于心跳机制,并设置最小的session超时时间为信条的两倍时间
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
# LF通信时限
# 集群中follower跟随者服务器(F)与领导者服务器(L)之间初始连接时能容忍的最多心跳数(tickTime的数量),用它来限定集群中的zookeeper服务器连接到leader的时限
# 即我给你打电话,电话嘟~的时间
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
# LF同步通信时限
# 集群中leader与follower之间最大响应时间单位,假如响应超过syncLimit*tickTime,leader认为follower已死,从服务器列表中删除follower
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
#
dataDir=/tmp/zookeeper
# the port at which the clients will connect
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
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
启动服务端:
[root@localhost bin]# ./zkServer.sh start
Error: JAVA_HOME is not set and java could not be found in PATH.
先安装jdk1.8
下载jdk1.8,解压到自己的java目录下 /usr/java
vi /etc/profile 配置环境变量
export JAVA_HOME=/usr/java/jdk1.8.0_152
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile 使配置生效
[root@localhost bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /zookeeper/apache-zookeeper-3.5.5-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@localhost bin]# echo ruok | nc 127.0.0.1 2181
imok[root@localhost bin]#
可能会出现
[root@localhost ~]# echo ruok | nc 127.0.0.1 2181
-bash: nc: 未找到命令
安装nc: yum install -y nc
可能会出现:
[root@localhost bin]# echo ruok | nc 127.0.0.1 2181
ruok is not executed because it is not in the whitelist.
修改 conf/zoo.cfg 添加以下属性
开启四字命令:4lw.commands.whitelist=*
Zookeeper相关的命令
启动客户端:
[root@localhost bin]# ./zkCli.sh
...
[zk: localhost:2181(CONNECTED) 0] help
可以使用help查看指令
ps -ef | grep zookeeper | grep -v grep
ZooKeeper是一个分布式服务管理框架,它提供一致性服务,用作文件系统和通知机制。本文介绍了ZooKeeper的下载、解压、配置、启动服务端及客户端的步骤,并提到了可能遇到的问题和解决方案。
1660

被折叠的 条评论
为什么被折叠?



