单机单节点模式

zookeeper解压, 放到 /opt/zookeeper/下, 新建一个latest的软链

$ ln -s zookeeper-3.4. latest

将 conf/zoo-sample.cfg 重命名为 zoo.cfg, 内容使用默认的就可以

修改 conf/log4j.properties, 这边的日志路径是无效的, 不用动, 注释掉console类型日志, 启用rollingfile类型日志

# Define some default values that can be overridden by system properties
zookeeper.root.logger=INFO, CONSOLE
zookeeper.console.threshold=INFO
zookeeper.log.dir=.
zookeeper.log.file=zookeeper.log
zookeeper.log.threshold=DEBUG
zookeeper.tracelog.dir=.
zookeeper.tracelog.file=zookeeper_trace.log #
# ZooKeeper Logging Configuration
# # Format is "<default threshold> (, <appender>)+ # DEFAULT: console appender only
#log4j.rootLogger=${zookeeper.root.logger} # Example with rolling log file
log4j.rootLogger=DEBUG, ROLLINGFILE # Example with rolling log file and tracing
#log4j.rootLogger=TRACE, CONSOLE, ROLLINGFILE, TRACEFILE

更改日志的存放目录: 和zoo.cfg同目录创建文件 zookeeper-env.sh , 写入

ZOO_LOG_DIR=/opt/zookeeper/server1/log

单机多节点模式

zookeeper解压, 放到 /opt/zookeeper/ 下, 同目录再放一个 server1目录, 下面建data和log两个目录用于存放数据和日志

zoo.cfg

[milton@localhost conf]$ more zoo.cfg
# The number of milliseconds of each tick
tickTime=
# The number of ticks that the initial
# synchronization phase can take
initLimit=
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/opt/zookeeper/server1/data
# the port at which the clients will connect
clientPort=
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=
#
# 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=
# Purge task interval in hours
# Set to "" to disable auto purge feature
#autopurge.purgeInterval=
server.=127.0.0.1::
server.=127.0.0.1::
server.=127.0.0.1::
  • initLimit: zookeeper集群中的包含多台server, 其中一台为leader, 集群中其余的server为follower. initLimit参数配置初始化连接时, follower和leader之间的最长心跳时间. 此时该参数设置为5, 说明时间限制为5倍tickTime, 即5*2000=10000ms=10s.
  • syncLimit: 该参数配置leader和follower之间发送消息, 请求和应答的最大时间长度. 此时该参数设置为2, 说明时间限制为2倍tickTime, 即4000ms.
  • server.X=A:B:C 其中X是一个数字, 表示这是第几号server. A是该server所在的IP地址. B配置该server和集群中的leader交换消息所使用的端口. C配置选举leader时所使用的端口. 由于配置的是伪集群模式, 所以各个server的B, C参数必须不同.

参照zookeeper0/conf/zoo.cfg, 配置zookeeper1/conf/zoo.cfg, 和zookeeper2/conf/zoo.cfg文件. 只需更改dataDir, dataLogDir, clientPort参数即可.

在之前设置的dataDir中新建myid文件, 写入一个数字, 该数字表示这是第几号server. 该数字必须和zoo.cfg文件中的server.X中的X一一对应.
/Users/apple/zookeeper0/data/myid文件中写入0, /Users/apple/zookeeper1/data/myid文件中写入1, /Users/apple/zookeeper2/data/myid文件中写入2.

为了更改日志的存放目录, 和zoo.cfg同目录创建文件 zookeeper-env.sh , 写入

ZOO_LOG_DIR=/opt/zookeeper/server1/log

我用的版本是zookeeper-3.4.6, 如果不起作用, 请查看bin/zkServer.sh 里面具体的指定.

多机多节点集群模式

集群模式下, 各server部署在不同的机器上, 因此各server的conf/zoo.cfg文件可以完全一样.

    tickTime=
initLimit=
syncLimit=
dataDir=/home/zookeeper/data
dataLogDir=/home/zookeeper/logs
clientPort=
server.=10.1.39.43::
server.=10.1.39.47::
server.=10.1.39.48::

示例中部署了3台zookeeper server, 分别部署在10.1.39.43, 10.1.39.47, 10.1.39.48上. 需要注意的是, 各server的dataDir目录下的myid文件中的数字必须不同. 10.1.39.43 server的myid为43, 10.1.39.47 server的myid为47, 10.1.39.48 server的myid为48

zookeeper开启snapshot data自动清理

在版本3.4.0之后, zookeeper增加了这两个参数用于自动清理

 autopurge.snapRetainCount
(No Java system property)
New in 3.4.: When enabled, ZooKeeper auto purge feature retains the autopurge.snapRetainCount most recent snapshots and the corresponding transaction logs in the dataDir and dataLogDir respectively and deletes the rest. Defaults to . Minimum value is .

autopurge.purgeInterval
(No Java system property)
New in 3.4.: The time interval in hours for which the purge task has to be triggered. Set to a positive integer ( and above) to enable the auto purging. Defaults to .

zookeeper多节点配置的更多相关文章

  1. 为什么zookeeper的节点配置的个数必须是奇数个?

    zookeeper有这样一个特性:集群中只要有过半的机器是正常工作的,那么整个集群对外就是可用的.也就是说如果有2个zookeeper,那么只要有1个死了zookeeper就不能用了,因为1没有过半, ...

  2. 为什么zookeeper的节点配置的个数必须是奇数个

    选举机制(FastLeaderElection算法):sid最大且被超过集群中超过半数的机器拥护就会成为leader.所以只有两种情况无法选出leader:整个集群只有2台服务器(注意不是只剩2台,而 ...

  3. ZooKeeper 组件安装配置

    ZooKeeper 组件安装配置 下载和安装 ZooKeeper ZooKeeper最新的版本可以通过官网 http://hadoop.apache.org/zookeeper/ 来获取,安装 Zoo ...

  4. Zookeeper+Kafka的单节点配置

    Zookeeper+Kafka的单节点配置 环境描述:Ubuntu16.04 server系统,在系统上搭建Java环境,jdk的版本为1.8或更高,我的服务器IP地址为192.168.0.106. ...

  5. zookeeper集群配置详细教程

      第一步:环境准备 环境 版本 说明 JDK 1.8 zookeeper运行所需 centos 7 操作系统 需要配置好JDK的环境变量 zookeeper-3.4.9.tar.gz 3.4.9 z ...

  6. kafka集群与zookeeper集群 配置过程

    Kafka的集群配置一般有三种方法,即 (1)Single node – single broker集群: (2)Single node – multiple broker集群:    (3)Mult ...

  7. zookeeper单节点windows下安装

    由于需要在windows下面安装zookeeper,故做个整理 1.下载zookeeper http://mirrors.hust.edu.cn/apache/zookeeper/ 2.解压 3.修改 ...

  8. 基于zookeeper实现分布式配置中心(二)

    上一篇(基于zookeeper实现分布式配置中心(一))讲述了zookeeper相关概念和工作原理.接下来根据zookeeper的特性,简单实现一个分布式配置中心. 配置中心的优势 1.各环境配置集中 ...

  9. ZooKeeper安装、配置和使用

    Zookeeper的概述: ZooKeeper是一个开源的分布式的,为分布式应用提供协调服务的Apache项目. ZooKeeper从设计模式角度来理解:是一个基于观察者模式设计的分布式服务管理框架, ...

随机推荐

  1. AndroidAnnotations简单示例

    @EActivity(R.layout.activity_main) public class MainActivity extends Activity { @ViewById(R.id.textV ...

  2. CoreAnimation方法汇总

    使用CoreAnimation一般分为三个部分:1.创建执行动画的CALayer 2.创建动画 3.CALayer 添加Animation CoreAnimation是以锚点为基础. CoreAnim ...

  3. array_filter、array_map、array_walk解释

    /** * array_filter 用回调函数处理数组中的各个元素, * 重点在于过滤(而不是新增)某个元素,当你处理到一个元素时, * 如果返回了false,那么这个元素将会被过滤掉.PS:保持了 ...

  4. PreferenceScreen监听子项的刷新

    有个PreferenceScreen,他有一些个子项目.它的Summary需要根据子项的设置来改变的,所以需要监听子项的刷新事件. preferenceScreen.setOnPreferenceCh ...

  5. android中的广播接收实现总结

    1 首先根据广播应用内接收和应用外接收,分两个类进行管理[1]  LocalBroadcastManager,应用内广播管理类[2]  BroadcastManager  广播管理类(部分应用内,应用 ...

  6. C#语言基础-类——string增加内容

    .split()    分离——属于string类            Console.Write("请输入姓名和学号(**-****):");            strin ...

  7. javascript-单例模式

    单例模式笔记   也称为单体模式,只允许实例化一次的对象类   用法:      1.命名空间:用一个对象来规划一个命名空间,井井有条的管理对象上的属性和方法      2.静态变量管理:让创建的函数 ...

  8. CSS之旅——第一站 为什么要用CSS

    不知道有多少码农和我一样,css一直是一个软肋,软到全身酥麻...既然软肋来了,只能是要想办法解决,所以就找本CSS权威指南看一看,都说 CSS权威指南这本书比较过时,但是内容还是比较充实的,而且内容 ...

  9. 一篇博客理解Recyclerview的使用

    从Android 5.0开始,谷歌公司推出了RecylerView控件,当看到RecylerView这个新控件的时候,大部分人会首先发出一个疑问,recylerview是什么?为什么会有recyler ...

  10. yii2开发后记

    h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h ...