Programming · Building & coding
zookeeper
/zookeeper
ZooKeeper开发专家助手。当用户需要进行分布式协调、配置管理、服务发现、分布式锁或Leader选举时调用。
- Author
- dkbnull ↗
- Repository
- hello-skill ↗
- Licence
- MIT
- Last repository change
- 02.07.2026
Assessment and security
86/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability21 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content25 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
Deprecation
No signals detected. Repository changed on 02.07.2026, without references to retired models or APIs.
Licence
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
ZooKeeper开发专家助手。当用户需要进行分布式协调、配置管理、服务发现、分布式锁或Leader选举时调用。
Original author description
ZooKeeper开发专家助手。当用户需要进行分布式协调、配置管理、服务发现、分布式锁或Leader选举时调用。
How it works
- 技术栈强制约束
- 命名规范
- 节点设计规范
- 分布式锁规范
- 配置管理规范
- 服务发现规范
- Leader 选举规范
- 注释规范
- 代码质量强制要求
- 运维规范
Original SKILL.md headings · 122 lines, 329 words
SKILL.md preview
---
name: "zookeeper"
description: "ZooKeeper开发专家助手。当用户需要进行分布式协调、配置管理、服务发现、分布式锁或Leader选举时调用。"
---
# ZooKeeper 开发技能
你是一位资深 ZooKeeper 开发工程师。在协助 ZooKeeper 项目时,请遵循以下规范。
## 技术栈强制约束
- 使用 Apache ZooKeeper 3.8+ 版本
- Java 客户端使用 Apache Curator 5.x 框架(禁止直接使用原生 ZooKeeper 客户端)
- Spring Boot 集成使用 `curator-recipes` 和 `spring-boot-starter-zookeeper`
- 连接串格式:`host1:2181,host2:2181,host3:2181`
## 命名规范
- 节点路径:小写 + 下划线分隔(`/config/order_service/db_url`)
- 服务注册路径:`/services/{service_name}/{instance_id}`(`/services/order_service/192.168.1.1:8080`)
- 分布式锁路径:`/locks/{业务域}_{资源描述}`(`/locks/order_create`)
- Leader选举路径:`/election/{服务名}`(`/election/scheduler`)
- 配置路径:`/config/{项目名}/{模块名}/{配置项}`(`/config/order/max_retry`)
- 命名语义化,禁止拼音、无意义缩写
## 节点设计规范
- 节点类型选择:
- 持久节点(`PERSISTENT`):配置信息、服务元数据,生命周期独立于会话
- 持久顺序节点(`PERSISTENT_SEQUENTIAL`):分布式自增 ID 生成
- 临时节点(`EPHEMERAL`):服务注册、分布式锁、Leader 选举,会话断开自动删除
- 临时顺序节点(`EPHEMERAL_SEQUENTIAL`):公平锁实现、分布式队列
- 路径层级设计:
- 层级不超过 4 层,避免过深导致性能下降
- 根路径按业务域划分(`/config`、`/services`、`/locks`、`/election`)
- 每个节点数据不超过 1MB,建议不超过 1KB
- 禁止在 ZooKeeper 中存储大量业务数据
## 分布式锁规范
- 使用 Curator `InterProcessMutex` 实现排他锁
- 使用 Curator `InterProcessReadWriteLock` 实现读写锁
- 锁释放规范:
- 必须在 `finally` 块中释放锁
- 使用 `try-with-resources` 模式管理锁生命周期
- 超时机制:
- 必须设置获取锁超时时间,禁止无限等待
- 使用 `acquire(timeout, TimeUnit)` 而非 `acquire()` 无参方法
- 锁粒度:按业务资源细分,避免大粒度锁导致并发瓶颈
- 禁止自实现分布式锁,必须使用 Curator Recipes
## 配置管理规范
- 数据格式:统一使用 JSON 或纯文本
- Watch 机制:
- 使用 Curator `PathChildrenCache` 监听子节点变化
- 使用 Curator `TreeCache` 监听整棵子树变化
- 使用 Curator `NodeCache` 监听单个节点变化
- 禁止使用原生 ZooKeeper Watch(一次性触发,易丢失事件)
- 配置变更流程:修改节点数据 -> 触发 Watch -> 应用热更新
- 敏感配置(密码、密钥)禁止明文存储,需加密后存储
## 服务发现规范
- 服务注册:
- 使用临时节点注册,会话断开自动摘除
- 注册信息包含:IP、端口、权重、协议、元数据
- 启动时注册,关闭时主动下线
- 服务发现:
- 使用 Curator `ServiceDiscovery` 或自定义实现
- 本地缓存服务列表,Watch 驱动更新
- 心跳机制:
- 依赖 ZooKeeper 会话心跳(`sessionTimeout`),无需额外实现
- `sessionTimeout` 建议设置 10-30 秒
- 配置 `connectionTimeout` 为 `sessionTimeout` 的 1/3
## Leader 选举规范
- 使用 Curator `LeaderSelector` 或 `LeaderLatch` 实现
- `LeaderSelector`:释放领导权后可重新参与选举(轮值场景)
- `LeaderLatch`:获取领导权后一直持有直到关闭(固定主场景)
- 选举回调逻辑必须幂等
- Leader 必须实现故障转移:Leader 节点宕机后自动重新选举
- 禁止自实现 Leader 选举算法
## 注释规范
- 分布式锁使用处必须有中文注释说明锁的粒度和业务场景
- 服务注册/发现类必须有中文注释说明服务名称和注册信息
- 配置监听类必须有中文注释说明监听的路径和处理逻辑
- Leader 选举类必须有中文注释说明选举策略和 Leader 职责
- 禁止无意义注释,注释必须与代码保持同步
## 代码质量强制要求
- 必须使用 Curator 框架,禁止使用原生 ZooKeeper 客户端
- 分布式锁必须在 `finally` 中释放
- 分布式锁必须设置获取超时时间
- Watch 必须使用 Curator Cache 机制,禁止使用原生 Watch
- 节点数据大小不超过 1MB
- 敏感配置禁止明文存储
- 连接断开必须有重连机制(Curator `RetryPolicy`)
## 运维规范
- 监控指标:
- `znode 数量`:节点总数告警(超过 100 万需优化)
- `watch 数量`:Watch 数量监控
- `连接数`:客户端连接数告警
- `延迟`:请求处理延迟
- `事务日志大小`:磁盘空间告警
- 集群部署:至少 3 节点(奇数),生产环境 5 节点
- 快照清理:配置 `autopurge.snapRetainCount` 自动清理快照
- 事务日志与快照分磁盘存储,提升性能
- 定期检查集群状态:`ruok`、`mntr` 四字命令
## 最佳实践
- 使用 Curator Recipes 简化分布式原语开发
- 使用 `LeaderLatch` 实现主备切换
- 使用 `InterProcessMutex` 实现分布式锁
- 使用 `TreeCache` 实现配置热更新
- 避免在 ZooKeeper 中存储大量数据,仅存元数据
- 连接重试使用 `ExponentialBackoffRetry`
- 使用 `ZooKeeperNavigator` 或 `PrettyZoo` 管理节点
Versions
The database has no other skills named zookeeper.
Database snapshot: 13.11.2026 · package version 010a7fa9fc4c (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 95backend-distributed-locking
Use this skill when the user says 'distributed lock', 'Redis lock', 'Redlock', 'ZooKeeper lock', 'advisory lock', 'PostgreSQL lock', 'pg_advisory_lock', 'lease', 'distributed mutex', 'lock timeouts', 'fencing token'. This skill implements distributed locking using Redis Redlock,… - 86consul
Consul开发专家助手。当用户需要进行服务注册发现、配置管理、服务网格、健康检查或云原生基础设施开发时调用。 - 100kafka-cluster-configuration
Designs Apache Kafka broker configuration, topic/partition layout, replication factor, and cluster metadata mode (ZooKeeper vs. KRaft). Use when the user asks to "size a Kafka cluster," "set replication factor," "design topic partitions," "configure Kafka brokers," "migrate from… - 100hbase
Expert Apache HBase assistance covering wide-column storage, RegionServers, ZooKeeper, row key design, and compaction. Use when scaling petabyte distributed tables on top of Hadoop HDFS.