Zookeeper是什么
Zookeeper是一个典型的分布式数据一致性的解决方案,分布式应用程序可以基于它实现诸如数据发布/订阅、负载均衡、命令服务、分布式协调/通知、集群管理、Master选举、分布式锁和分布式队列等功能。
《从Paxos到Zookeeper分布式一致性原理与实践》
环境搭建
- 下载安装包
从官网中下载压缩包 下载地址
版本是3.4.10 - 解压
tar -zxvf zookeeper-3.4.10.tar.gz
- 移动
mv zookeeper-3.4.10 /usr/local
- 复制配置文件
cd /usr/local/zookeeper-3.4.10/
cd conf/
cp zoo_sample.cfg zoo.cfg
- 修改配置文件
dataDir、dataLogDir 改成你自己的目录,如果没有,新建一个目录
server.1=127.0.0.1:2888:3888
单机模式下不需要配置,第一个端口用于Leader与Folloer的通信,第二个端口是用于Master选举时通信
需要在data目录下新建myid文件(没有后缀名)
内容为server.后面的数字
# 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=/usr/local/zookeeper-3.4.10/data
dataLogDir=/usr/local/zookeeper-3.4.10/log
# the port at which the clients will connect
clientPort=2181
#单机模式下不需要配置,第一个端口用于Leader与Folloer的通信,第二个端口是用于Master选举时通信
#server.1=127.0.0.1:2888:3888
# 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
- 启动Zookeeper服务器
#进入bin目录下
./zkServer.sh start
#输出
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.10/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
- 客户端链接Zookeeper
./zkCli.sh -server 127.0.0.1:2181
#输出
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
单机模式下Zookeeper的搭建还是挺简单的哈
网友评论