zookerper学习

zookeeper 安装学习

mac 下安装

http://mirrors.hust.edu.cn/apache/zookeeper/
下载bin包, 源码包不能直接使用
cd /data/soft/apache-zookeeper-3.6.1/conf
cp zoo_sample.cfg zoo.cfg

vi zoo.cfg

# The number of milliseconds of each tick // 服务端和客户端的心跳时间间隔
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
# 集群中的follower服务器(F)与leader服务器(L)之间初始连接时能容忍的最多心跳数(tickTime的数量)。
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
# 集群中的follower服务器与leader服务器之间请求和应答之间能容忍的最多心跳数(tickTime的数量)。
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
# Zookeeper保存数据的目录,默认情况下,Zookeeper将写数据的日志文件也保存在这个目录里。
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181

# 服务器名称与地址:集群信息(服务器编号,服务器地址,LF通信端口,选举端口)
# 这个配置项的书写格式比较特殊,规则如下:
# server.N=YYY:A:B  
# 其中N表示服务器编号,YYY表示服务器的IP地址,A为LF通信端口,表示该服务器与集群中的leader交换的信息的端口。B为选举端口,表示选举新leader时服务器间相互通信的端口(当leader挂掉时,其余服务器会相互通信,选择出新的leader)。一般来说,集群中每个服务器的A端口都是一样,每个服务器的B端口也是一样。但是当所采用的为伪集群时,IP地址都一样,只能时A端口和B端口不一样。 

# 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

## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
启动

sudo zkServer.sh start

链接zookeeper

bin/zkCli.sh -server 127.0.0.1:2181

create /testdir test
get /testdir
delete /testdir

配置调优

设置Java堆大小。这对于避免交换非常重要,因为交换会严重降低ZooKeeper的性能。要确定正确的值,请使用负载测试,并确保您已远远低于会导致交换的使用限制。保守一点-对于4GB的计算机,最大堆大小为3GB
myid文件由仅包含该机器ID的文本的一行组成。因此,服务器1的myid将包含文本“ 1”,除此之外没有其他内容。ID在集合中必须唯一,并且其值应介于1到255之间。重要说明:如果启用了TTL节点之类的扩展功能(请参见下文),由于内部限制,该ID必须在1到254之间

集群配置参考

tickTime=2000
dataDir=/var/lib/zookeeper/
clientPort=2181
initLimit=5
syncLimit=2
server.1=zoo1:2888:3888
server.2=zoo2:2888:3888
server.3=zoo3:2888:3888
设计ZooKeeper部署

ZooKeeper的可靠性基于两个基本假设。
部署中只有少数服务器将发生故障。在这种情况下,故障意味着机器崩溃,或者是网络中的某些错误,这些错误将服务器与大多数服务器分开。
部署的计算机正常运行。正确操作意味着正确执行代码,使时钟正常工作以及使存储和网络组件一致运行。

如果ZooKeeper必须与其他应用程序竞争以访问诸如存储介质,CPU,网络或内存之类的资源,则其性能将显着下降。ZooKeeper具有很强的耐用性保证,这意味着在允许负责更改的操作完成之前,它使用存储介质记录更改。然后,您应该意识到这种依赖性,如果要确保媒体不阻止ZooKeeper的操作,请格外小心。您可以采取以下措施来最大程度地减少这种退化:

ZooKeeper的事务日志必须位于专用设备上。(专用分区是不够的。)ZooKeeper按顺序写入日志,而不进行查找。与其他进程共享日志设备可能导致查找和争用,进而导致数秒的延迟。
不要将ZooKeeper放在可能引起交换的情况下。为了使ZooKeeper能够以任何及时性运行,它根本不能被交换。因此,请确保分配给ZooKeeper的最大堆大小不大于ZooKeeper可用的实际内存量。有关更多信息,请参阅下面的避免注意事项。

ZK服务器被设计为“快速失败”,这意味着如果发生无法恢复的错误,它将关闭(进程退出)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值