zookeeper笔记

1 概述

分布式系统中的协调系统:配置服务、名字服务、分布式同步、组服务等

2 安装

解压后,bin/zkEnv.sh,增加一行
SERVER_JVMFLAGS=" -Xms3g -Xmx3g"
conf目录下创建配置文件zoo.cfg

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=5
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=2
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
#dataDir=/var/lib/zookeeper
dataDir=/usr/local/zookeeper-3.4.6/data
dataLogDir=/usr/local/zookeeper-3.4.6/log
# 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=6000
#
# 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](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
server.1=10.8.0.1:2888:3888
server.2=10.8.0.2:2888:3888
server.3=10.8.0.3:2888:3888

其中,server.id=host :port :port的配置说明:

server.id:在zoo.cfg文件中配置的配置的 dataDir 路径下(即:/var/lib/zookeeper)创建myid文件,里面写入id值
host:构建zookeeper集群的服务器的ip地址
port:第一个 port 用于连接 leader 服务器,第二个 port 用于 leader election

三台服务器./data下myid分别修改为 1、2、3。

启动本地实例:
./bin/zkServer.sh start

检查启动状态:
yum -y install nc
echo ruok | nc localhost 2181
输出“imok”

3 各种状态的检查方法

查看zk的配置,配置正常返回证明zk service 正常
echo conf| nc localhost 2181

stat 可以查看集群状态
echo stat|nc 127.0.0.1 2181 查看集群状态以及follower或leader角色

echo ruok|nc 127.0.0.1 2181 是否启动了该Server,启动则返回imok

echo dump| nc 127.0.0.1 2181 未经处理的会话和临时节点。

echo kill | nc 127.0.0.1 2181 ,关掉server

echo conf | nc 127.0.0.1 2181 ,输出相关服务配置的详细信息。

echo cons | nc 127.0.0.1 2181 所有连接客户端的完全的连接 / 会话的详细信息。

echo envi |nc 127.0.0.1 2181 ,输出关于服务环境的详细信息(区别于 conf 命令)。

echo reqs | nc 127.0.0.1 2181 ,列出未经处理的请求。

echo wchs | nc 127.0.0.1 2181 ,列出服务器 watch 的详细信息。

echo wchc | nc 127.0.0.1 2181 ,通过 session 列出服务器 watch 的详细信息,它的输出是一个与 watch 相关的会话的列表。

echo wchp | nc 127.0.0.1 2181 ,通过路径列出服务器 watch 的详细信息。 session

你可能感兴趣的:(zookeeper笔记)