目录
1. ZooKeeper 集群的搭建
在ZooKeeper的 conf 下的 zoo.cfg文件中,添加或者修改三行代码,如下:
server.1=127.0.0.1:2887:3887
server后面的数字代表 在集群中的server编号,与myid文件里的数字相同。
127.0.0.1 : 代表ip地址。
2887 : follower和leader进行通信和数据同步时,使用的端口号。
3887 : 选举Leader投票时,使用的端口号。
dataDir=D:\\zookeeper-3.4.13\\data\\1
dataLogDir=D:\\zookeeper-3.4.13\\log\\1
dataDir : 快照文件的存储位置。建议与dataLogDir文件的目录分开。
dataLogDir : 日志文件的存储位置。由于事务日志的写,直接影响zk的服务性能,建议单独放在一个磁盘或者挂载点里。
2. zoo.cfg文件详解:
属性 | 默认值 | 官方介绍 | 详解 |
tickTime | 2000 | the number of milliseconds of each tick | 工作时间单元,以毫秒为单位,用来控制心跳和超时。默认情况下,一次会话的最小的超时时间是tickTime的两倍。 |
initLimit | 10 | the number of ticks that the initial synchronization phase can take
| 默认,初始同步阶段花费10个工作时间单元 |
syncLimit | 5 | the number of ticks that can pass between sending a request and getting an acknowledgement | 发送一次请求和得到一次确认需要花费5个工作时间单元 |
dataDir | the directory where the snapshot is stored | 内存数据库快照被存储的目录 | |
dataLogDir | 事务日志被存储的目录 | ||
clientPort | 2181 | the port at which the clients will connect | client 连接的端口 |
maxClientCnxns | 60 | the maximum number of client connections | 客户端连接的最大数量 |
autopurge.snapRetainCount | 3 | the number of snapshots to retain in dataDir | 在dataDir中保留的快照数量 |
autopurge.purgeInterval | 1 | purge task interval in hours | 清理任务每小时执行的次数 |
snapCount | 100000 | 相邻两个快照文件之间事务操作的次数 | |
preAllocSize | 64MB | 预置事务文件分配的磁盘大小 | |
minSessionTimeout maxSessionTimeout | 4s / 40s | 会话的超时时间 | |
jute.maxbuffer | 1048575 (字节) | 单个数据节点存储的最大数据量 |