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.
相关文章
- 靶向甲状腺癌治疗的4种小分子药物 | MedChemExpress
- 小分子化合物曲贝替定与艾日布林的合成之路 | MedChemExpress
- 如何手动配置EasyNVR安防视频云服务平台的Onvif探测功能?
- 批量 ping 网段的终极方法
- 交换机安全功能介绍
- 广播风暴的成因以及如何判断、解决
- 什么是千兆光模块和万兆光模块?它们有什么区别?
- 什么?《三体》海报可以自己画!
- 麦德龙Metro EDI 需求分析
- R语言入门-02:向量
- 在日报、读后感、小说、公文模版、编程等场景体验了一把chatGPT
- 小蝶量化:在区块链技术中什么是智能合约?
- Spring 事务失效的几种情况
- 软件测试|f-string格式化输出的这些用法,90%的Pythoner不知道
- 软件测试|pip命令,你真的会了吗?
- [oeasy]python0074_修改字体背景颜色_background_color_背景色
- PHP - 语言底层运行及生命周期
- PS2023 Neural Filters(PS2023神经滤镜插件) V24.0 最新离线安装包直装版
- 蓝桥杯题目——飞行员兄弟解题详解及其包含的思想
- R语言-画图