title: ZooKeeper集群部署 summary: Installation and configuration of ZooKeeper as a distributed service registry and configuration management center for Dubbo services, including cluster setup with leader election and DNS configuration. sources: - 400-devops__06-Kubernetes__k8s-paas__05.K8S结合CI&CD持续交付和集中管理配置.md kind: concept createdAt: "2026-04-28T04:45:29.703Z" updatedAt: "2026-04-28T04:45:29.703Z" tags: - zookeeper - service-discovery - distributed-systems - configuration-management aliases: - zookeeper confidence: 0.9 provenanceState: extracted inferredParagraphs: 1
ZooKeeper集群部署¶
ZooKeeper集群部署通常涉及配置奇数个节点(例如3个节点)以维持高可用性。^[400-devops__06-Kubernetes__k8s-paas__05.K8S结合CI&CD持续交付和集中管理配置.md] The cluster operates with a Leader-Follower model, where one node acts as the leader and the others as followers; if the leader fails, the remaining nodes automatically elect a new leader.^[400-devops__06-Kubernetes__k8s-paas__05.K8S结合CI&CD持续交付和集中管理配置.md]
In distributed systems, ZooKeeper is commonly used as a registration center for services (such as Dubbo) and for centralized configuration management.^[400-devops__06-Kubernetes__k8s-paas__05.K8S结合CI&CD持续交付和集中管理配置.md] Unlike stateless services, ZooKeeper maintains state, which often necessitates deploying it outside of container orchestration clusters or on persistent storage to ensure data integrity.^[400-devops__06-Kubernetes__k8s-paas__05.K8S结合CI&CD持续交付和集中管理配置.md]
Deployment Prerequisites¶
Before deploying the cluster, ensure the following dependencies are met:
- Java Environment: ZooKeeper requires a Java Runtime Environment (JRE) or JDK.^[400-devops__06-Kubernetes__k8s-paas__05.K8S结合CI&CD持续交付和集中管理配置.md]
- Host Resources: Allocate sufficient disk space for data and logs.
Configuration Steps¶
1. Install and Configure Java¶
Install the JDK on the designated nodes and configure the environment variables (JAVA_HOME, PATH).^[400-devops__06-Kubernetes__k8s-paas__05.K8S结合CI&CD持续交付和集中管理配置.md]
2. Install ZooKeeper Software¶
Download and extract the ZooKeeper binaries. It is recommended to create a symbolic link to the installation directory to facilitate future upgrades.^[400-devops__06-Kubernetes__k8s-paas__05.K8S结合CI&CD持续交付和集中管理配置.md]
3. Create Data Directories¶
Create necessary directories for storing data and transaction logs, for example:
* /data/zookeeper/data
* /data/zookeeper/logs
4. Configure zoo.cfg¶
The core configuration file is usually located at <zk_install>/conf/zoo.cfg. Key parameters include:
tickTime: The basic time unit (in milliseconds) used by ZooKeeper.initLimit: Timeouts for ZooKeeper to connect to the leader.syncLimit: Timeouts for followers to sync with the leader.dataDir: The location to store the in-memory database snapshots.dataLogDir: The location to store transaction logs (optional but recommended for performance).clientPort: The port listening for client connections (default is 2181).
Additionally, you must define the cluster members using the server.X format:
server.X=hostname:peer_port:leader_port
* X: The server ID.
* hostname: DNS name or IP of the node.
* peer_port: Port for peer communication (default 2888).
* leader_port: Port for leader election (default 3888).
Example:
server.1=zk1.od.com:2888:3888
server.2=zk2.od.com:2888:3888
server.3=zk3.od.com:2888:3888
5. Configure myid¶
In the dataDir defined in zoo.cfg, create a file named myid. This file must contain only the server ID (X) corresponding to the node.^[400-devops__06-Kubernetes__k8s-paas__05.K8S结合CI&CD持续交付和集中管理配置.md]
For example, on the node configured as server.1:
/data/zookeeper/data/myid
# Content:
1
6. DNS Resolution¶
Ensure that the hostnames used in zoo.cfg (e.g., zk1.od.com) are resolvable via DNS or configured in the /etc/hosts file on all nodes.^[400-devops__06-Kubernetes__k8s-paas__05.K8S结合CI&CD持续交付和集中管理配置.md]
Starting the Cluster¶
Start the ZooKeeper service on each node:
/opt/zookeeper/bin/zkServer.sh start
Verification¶
Verify that the process is running and listening on the configured port:
netstat -luntp | grep 2181
To check the status of a node (Leader or Follower), run:
/opt/zookeeper/bin/zkServer.sh status
Related Concepts¶
- [[Distributed Systems]]
- [[Service Registration]]
- [[High Availability]]
- Dubbo
Sources¶
400-devops__06-Kubernetes__k8s-paas__05.K8S结合CI&CD持续交付和集中管理配置.md