• zookeeper单节点和多节点配置


    单机单节点模式

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

    $ ln -s zookeeper-3.4.12 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=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=/opt/zookeeper/server1/data
    # 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
    server.1=127.0.0.1:10090:10100
    server.2=127.0.0.1:10091:10101
    server.3=127.0.0.1:10092:10102
    • 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=2000    
        initLimit=5    
        syncLimit=2    
        dataDir=/home/zookeeper/data    
        dataLogDir=/home/zookeeper/logs    
        clientPort=4180  
        server.43=10.1.39.43:2888:3888  
        server.47=10.1.39.47:2888:3888    
        server.48=10.1.39.48:2888:3888

    示例中部署了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.0: 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 3. Minimum value is 3.
    
    autopurge.purgeInterval (No Java system property) New
    in 3.4.0: The time interval in hours for which the purge task has to be triggered. Set to a positive integer (1 and above) to enable the auto purging. Defaults to 0.
  • 相关阅读:
    (一)jQuery EasyUI 的EasyLoader载入原理
    java playframework
    android Handlerr.removeCallbacksAndMessages(null)的妙用
    云已成为一种趋势,大有可为
    将一个4X4的数组进行逆时针旋转90度后输出,要求原数组数据随机输入
    小强的HTML5移动开发之路(40)——jqMobi中实践header定义的几种方式
    AngularJS中的依赖注入
    极光消息推送服务器端开发实现推送(下)
    用CSS指定外部链接的样式
    版本控制(1)——SVN
  • 原文地址:https://www.cnblogs.com/milton/p/4391921.html
Copyright © 2020-2023  润新知