一、window下zookeeper独立部署

zookeeper是一个分布式协调应用,用于管理大型主机。通俗地说,分布式应用相对于单体应用存在着很多要处理的问题,而这些问题通常是不太好处理的。比如,典型的一致性问题,而zookeeper可以很简单的实现解决一致性问题。我们可以将zookeeper理解为“解决分布式应用常见问题的应用”。

zookeeper可以解决如:发布订阅、负载均衡、命名服务、分布式通知与协调、集群管理与master选举、分布式锁、分布式队列等。

一、环境准备

zookeeper是由Java语言编写的,所以运行zookeeper需要Java环境的支持。

windows下JDK开发环境请参考:http://www.runoob.com/java/java-environment-setup.html#win-install

 

二、下载

下载二进制包,下载地址:http://mirrors.shu.edu.cn/apache/zookeeper/zookeeper-3.4.13/

 

三、配置

解压二进制包:zookeeper-3.4.13.tar.gz

将\zookeeper-3.4.13\conf目录下的文件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=C:\\Users\\admin\\Desktop\\software\\zk\\data
dataLogDir=C:\\Users\\admin\\Desktop\\software\\zk\\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=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

添加修改数据目录dataDir、日志目录dataLogDir

 

四、启动测试

进入bin目录\zookeeper-3.4.13\bin

双击执行服务端启动命令:zkServer.cmd

双击执行客户端启动命令:zkCli.cmd

如果要连接远程的话:

zkCli.cmd -server localhost:2181 // windows
zkCli.sh -server localhost:2181 // Linux

使用ls命令查看根节点下的节点

[zk: localhost:2181(CONNECTED) 0] ls /
[zookeeper]

只有一个zookeeper节点

使用create命令创建一个节点,添加数据

[zk: localhost:2181(CONNECTED) 1] create /user lay
Created /user

再ls查看一次

[zk: localhost:2181(CONNECTED) 2] ls /
[zookeeper, user]

我们发现新增了一个user节点

查看user节点

[zk: localhost:2181(CONNECTED) 3] get /user
lay
cZxid = 0x1b
ctime = Wed Sep 12 11:06:27 CST 2018
mZxid = 0x1b
mtime = Wed Sep 12 11:06:27 CST 2018
pZxid = 0x1b
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 3
numChildren = 0

我们看到了数据lay,以及一些元数据

 如果你要删除节点可以使用命令

delete /路径

但是如果该路径存在节点或者数据时无法删除的,这时候你可以使用递归删除命令

rmr /路径

 

posted @ 2018-09-12 11:09  __lay  阅读(713)  评论(0编辑  收藏  举报