Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
FREEDOM251

Freedom251 › Blog

Resolving a Common Error in Apache Zookeeper

By Freedom251 Team · · 17 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Apache ZooKeeper startup and connectivity errors often appear suddenly, but they usually trace back to a small set of causes: incorrect configuration, occupied ports, unreachable peers, damaged or inaccessible data directories, or quorum communication failures. Symptoms can include clients timing out, servers stuck in standalone or looking mode, repeated connection refused messages, or ensemble members failing to elect a leader.

A focused troubleshooting process can restore service quickly. By checking zoo.cfg, validating client and quorum ports, reviewing logs, confirming file permissions, and testing connectivity between servers, you can isolate whether the issue is local to one node or affecting the whole ensemble.

As an Amazon Associate I earn from qualifying purchases.

This guide walks through practical checks and recovery steps for diagnosing a common ZooKeeper startup or connectivity problem, then validating that the cluster is healthy before returning dependent applications to normal operation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Understanding the ZooKeeper Error and Its Symptoms

A common ZooKeeper failure appears as either a startup error on the server or a connection error from clients such as Kafka, Solr, HBase, or a custom application. The symptoms often look similar even when the cause is different: the service starts and exits immediately, clients report session timeouts, or one node in the ensemble cannot join quorum. Before changing configuration, identify whether the failure is local to one ZooKeeper server, affects the whole ensemble, or only impacts specific clients.

On the client side, typical messages include Connection refused, Session expired, KeeperErrorCode = ConnectionLoss, Unable to connect to ZooKeeper server, or repeated retries against host:2181. These usually indicate that the client port is not reachable, ZooKeeper is not listening on the expected address, firewall rules are blocking traffic, or the server is overloaded and failing to respond before the session timeout. Start by confirming the exact connection string used by the client, including all hosts and ports, because stale DNS records or an old node name can make a healthy ensemble appear unavailable.

On the server side, startup failures are most often visible in zookeeper.out, zookeeper.log, or the system journal. Check the active log location used by your installation, then inspect recent entries:

  • sudo journalctl -u zookeeper -n 100 --no-pager
  • tail -n 100 /var/log/zookeeper/zookeeper.log
  • tail -n 100 /opt/zookeeper/logs/zookeeper.out

Errors such as Address already in use usually point to a port conflict on the client port 2181 or quorum ports such as 2888 and 3888. Messages like Cannot open channel to X at election address, Not forming quorum, or LOOKING repeated continuously indicate that ensemble members cannot communicate with each other. A node stuck in LOOKING is searching for a leader; one node briefly entering this state can be normal, but repeated transitions between LOOKING, FOLLOWING, and LEADING suggest unstable quorum connectivity or mismatched server definitions.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Data directory problems produce a different pattern. If ZooKeeper reports myid file is missing, Invalid config, exiting abnormally, Permission denied, or transaction log errors, focus on dataDir, dataLogDir, file ownership, disk space, and whether the myid value matches the corresponding server.N entry in zoo.cfg. A full disk can also cause ZooKeeper to stop accepting writes, which then causes clients to time out even though the process still appears to be running.

A quick health check can separate client-facing problems from quorum problems. Run the four-letter commands from a ZooKeeper host or an allowed admin machine:

  • echo ruok | nc localhost 2181 should return imok.
  • echo stat | nc localhost 2181 should show whether the node is leader, follower, or standalone.
  • echo mntr | nc localhost 2181 should expose metrics such as outstanding requests, latency, and synced followers.

If these commands fail locally, investigate the ZooKeeper process, bind address, client port, and local firewall. If they succeed locally but fail from another host, the issue is likely network routing, firewall policy, security groups, DNS, or client configuration. If only one ensemble member fails while others report healthy leader and follower states, isolate that node and compare its configuration, myid, ports, logs, and data directory permissions against a working peer.

Checking ZooKeeper Configuration Files

After confirming the startup or connectivity symptom, inspect the ZooKeeper configuration before changing ports, deleting data, or restarting the whole ensemble. The primary file is usually zoo.cfg, commonly located in /etc/zookeeper/conf/zoo.cfg, /opt/zookeeper/conf/zoo.cfg, or under a package-specific path such as /etc/zookeeper/conf. On systemd-based hosts, also check the service definition to confirm which configuration directory is actually being used.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start by locating the active configuration and checking the effective service command:

  • Find the service command: systemctl cat zookeeper
  • Check the running process: ps -ef | grep -i zookeeper
  • List common config locations: ls -l /etc/zookeeper/conf /opt/zookeeper/conf
  • Review the main file: grep -v ‘^#’ /etc/zookeeper/conf/zoo.cfg | sed ‘/^$/d’

In zoo.cfg, verify the values that control where ZooKeeper stores state and how clients and peers connect. A minimal standalone or ensemble configuration should have a valid tickTime, dataDir, and clientPort. Ensemble nodes also require matching server.N entries across all members. For example, if a node has server.1, server.2, and server.3, every ZooKeeper host in that ensemble should list the same three servers with the same hostnames and quorum ports.

Setting What to check
dataDir Directory exists, is writable by the ZooKeeper user, and contains the correct myid file for ensemble mode.
clientPort Port used by clients, commonly 2181, is not duplicated by another service.
server.N Each node has a unique numeric ID and the hostname resolves correctly from every peer.
initLimit and syncLimit Values are present and reasonable for the network latency between ensemble members.

For ensemble deployments, compare zoo.cfg on every node. Small differences can cause repeated leader election, failed quorum formation, or messages such as Cannot open channel to X at election address. Use checksum or diff commands to compare files after copying them to one host, or run direct checks with SSH:

  • ssh zk1 “grep ‘^server\.’ /etc/zookeeper/conf/zoo.cfg”
  • ssh zk2 “grep ‘^server\.’ /etc/zookeeper/conf/zoo.cfg”
  • ssh zk3 “grep ‘^server\.’ /etc/zookeeper/conf/zoo.cfg”

Next, confirm that the myid file matches the corresponding server.N entry. If zk2.example.com is listed as server.2, then its data directory should contain a file named myid with only the value 2. Check it with cat /var/lib/zookeeper/myid or the configured dataDir path. Extra spaces, the wrong number, or a missing file can prevent the node from joining the quorum.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Also look for version-specific configuration mistakes. Newer ZooKeeper releases may use admin.serverPort, secureClientPort, TLS-related properties, or dynamic configuration files such as zoo.cfg.dynamic. If dynamic reconfiguration is enabled, make sure the static and dynamic files agree and that stale server entries were not left behind after replacing a node. Once the configuration is consistent, back up the corrected files and manage them through automation such as Ansible, Puppet, Chef, or Kubernetes ConfigMaps to prevent drift across the ensemble.

Verifying Ports, Firewall Rules, and Network Connectivity

After confirming that zoo.cfg contains the expected client and quorum settings, verify that each required port is actually reachable. A typical ZooKeeper node uses port 2181 for client connections, plus two ports per peer in each server.X entry, commonly 2888 for follower-to-leader communication and 3888 for leader election. If any of these ports are blocked, already in use, or bound to the wrong interface, ZooKeeper may fail to start, repeatedly drop from the ensemble, or show connection timeouts from clients.

Begin on each ZooKeeper host by checking whether the expected ports are listening. On Linux, use ss or netstat:

  • ss -lntp | grep -E '2181|2888|3888'
  • netstat -lntp | grep -E '2181|2888|3888'

If ZooKeeper is running, you should see the Java process bound to the configured ports. If another process owns one of them, identify it with lsof -i :2181, lsof -i :2888, or lsof -i :3888. Stop the conflicting service or change the ZooKeeper port configuration consistently across the ensemble. Avoid changing only one node’s quorum ports unless every other node’s server.X line is updated to match.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Next, test connectivity between machines rather than only checking local listeners. From each ZooKeeper node, connect to the client and quorum ports on the other nodes:

  • nc -vz zk1.example.com 2181
  • nc -vz zk2.example.com 2888
  • nc -vz zk3.example.com 3888

A refused connection usually means no process is listening or the service is bound incorrectly. A timeout often points to a firewall, security group, routing, or name resolution problem. If nc is unavailable, use telnet host port or timeout 5 bash -c '</dev/tcp/host/port' as a quick substitute.

Firewall and security group checks

Review host-based firewall rules on every ZooKeeper server. For firewalld, inspect active zones with firewall-cmd --get-active-zones and list rules with firewall-cmd --list-all. For iptables, use iptables -L -n -v. For Ubuntu systems using UFW, run ufw status verbose. Allow the client port only from trusted application hosts, and allow quorum ports only between ZooKeeper nodes. In cloud environments, also check network security groups, subnet ACLs, and load balancer rules if clients connect through one.

Name resolution must also be consistent. The hostnames in server.X entries should resolve to addresses reachable by the other ZooKeeper nodes. Validate with getent hosts zk1.example.com and compare results across all servers. If DNS returns public addresses on one host and private addresses on another, quorum traffic may take the wrong path or be blocked entirely. For stable clusters, use fixed private IPs or reliable internal DNS records.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Preventing repeat connectivity failures

  • Reserve ZooKeeper ports in deployment documentation and avoid reusing them for other services.
  • Keep firewall rules under configuration management so all ensemble members receive the same access policy.
  • Monitor port availability and connection latency between ZooKeeper nodes, not just process uptime.
  • Use consistent DNS naming and verify forward and reverse records after host replacements.
  • Test 2181, 2888, and 3888 before restarting the full ensemble.

Once port listeners, firewall paths, and hostname resolution are confirmed, remaining startup issues are more likely to involve local storage, permissions, transaction logs, or quorum state. These checks reduce guesswork and help separate network failures from ZooKeeper configuration or data directory problems.

Inspecting Data Directories, Logs, and Permissions

After confirming that the configuration and network path are correct, inspect the local filesystem on each ZooKeeper node. Startup failures and unstable connections often come from an invalid dataDir, missing transaction log location, stale metadata, or a permissions mismatch after a package upgrade, restore, or manual file copy. Start by checking the values in zoo.cfg, commonly found under /etc/zookeeper/conf/, /opt/zookeeper/conf/, or a deployment-specific configuration directory.

Verify that the configured directories exist, have free space, and are owned by the user that runs ZooKeeper. For example, if ZooKeeper runs as the zookeeper user, the data and log paths should be writable by that account:

  • grep -E '^(dataDir|dataLogDir)=' /etc/zookeeper/conf/zoo.cfg
  • ls -ld /var/lib/zookeeper /var/log/zookeeper
  • df -h /var/lib/zookeeper /var/log/zookeeper
  • df -i /var/lib/zookeeper /var/log/zookeeper
  • sudo -u zookeeper test -w /var/lib/zookeeper && echo writable

If ownership is wrong, correct it carefully rather than broadening permissions. A typical repair is chown -R zookeeper:zookeeper /var/lib/zookeeper /var/log/zookeeper, followed by restrictive modes such as chmod 750 /var/lib/zookeeper. Avoid deleting files from dataDir unless you understand the ensemble state, because snapshots, transaction logs, and the node identity file are used to recover server state.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check the myid file

Each ZooKeeper server in an ensemble must have a myid file inside its dataDir. The file contains a single numeric ID that must match one server.X entry in zoo.cfg. For example, if the node is configured as server.2=zk2.example.com:2888:3888, then /var/lib/zookeeper/myid on that host should contain only 2. Validate it with cat /var/lib/zookeeper/myid and compare it against the configuration on all nodes. Duplicate IDs, missing files, hidden whitespace, or mismatched hostnames can prevent quorum formation even when client port connectivity looks healthy.

Next, review the ZooKeeper logs around startup time. Depending on the installation, useful locations include /var/log/zookeeper/zookeeper.log, systemd journal output, or application logs under the ZooKeeper installation directory. Run commands such as journalctl -u zookeeper -n 200 --no-pager, tail -n 200 /var/log/zookeeper/zookeeper.log, and grep -iE 'error|exception|denied|snapshot|myid|quorum' /var/log/zookeeper/zookeeper.log. Permission issues often appear as Permission denied, bad directory paths as No such file or directory, and corrupted local state as snapshot or transaction log load errors.

Symptom in logs Likely local cause Practical check
Cannot open channel to X at election address May be quorum networking, but also confirm this node has the correct myid cat dataDir/myid and compare with server.X
Permission denied Service user cannot read or write data or log paths namei -l /var/lib/zookeeper and ls -ld
No space left on device Full disk or exhausted inodes df -h and df -i
Unable to load database on disk Damaged snapshot or transaction log Review recent filesystem events and restore from a known-good backup if required

As a preventive measure, place dataDir and dataLogDir on reliable storage, monitor disk usage and inode consumption, and rotate logs before they fill the filesystem. Keep backups of configuration files and record each node’s myid mapping. During maintenance, stop ZooKeeper cleanly before moving or restoring data directories, then start one node at a time while watching logs for local recovery messages and quorum progress.

Resolving Quorum and Ensemble Communication Issues

When ZooKeeper starts but fails to join the cluster, the problem often sits in quorum communication rather than the client port. Each server must be able to reach the other voting members on the peer and election ports defined in zoo.cfg, usually in entries such as server.1=zk1.example.com:2888:3888. Port 2888 is commonly used for follower-to-leader synchronization, while 3888 is used during leader election. If either port is blocked, misrouted, or bound to the wrong interface, the node may repeatedly log messages about looking for a leader, connection refused, socket timeouts, or not enough servers to form a quorum.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start by confirming that every node has the same ensemble membership list and that each node’s myid file matches its corresponding server.X entry. On node zk1, for example, the data directory should contain a plain text file named myid with the value 1 if the configuration includes server.1=zk1.example.com:2888:3888. Check this on all members:

  • cat /var/lib/zookeeper/myid
  • grep '^server\.' /etc/zookeeper/zoo.cfg
  • hostname -f
  • getent hosts zk1.example.com zk2.example.com zk3.example.com

If DNS names resolve differently across hosts, replace them with stable internal DNS names or fixed private IP addresses. Avoid using localhost, public addresses that are not reachable from peer nodes, or hostnames that resolve to IPv6 on some machines and IPv4 on others unless the ensemble is intentionally configured that way. In cloud deployments, confirm that security groups, route tables, network ACLs, and host firewalls allow node-to-node traffic on the quorum ports in both directions.

Test peer-to-peer reachability

Run connectivity checks from each ZooKeeper host to every other host. A successful client port test does not prove that quorum ports are open, so test all relevant ports directly:

  • nc -vz zk2.example.com 2888
  • nc -vz zk2.example.com 3888
  • ss -lntp | grep -E '2181|2888|3888'
  • sudo iptables -S or sudo firewall-cmd --list-all

During startup, a ZooKeeper server may not listen on every peer port until the process reaches the appropriate state, so combine port checks with log review. Look for repeated election rounds, authentication failures, rejected SASL connections, or messages showing an unexpected remote address. If quorum authentication is enabled, verify that all nodes use matching JAAS files, service principals, keytabs, and related JVM flags. A single node with stale Kerberos credentials or an incorrect principal can prevent stable leader election even when ports are reachable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Correct ensemble mismatches safely

For static ensembles, all voting members should use an identical server.X list, with only the myid value differing per node. For dynamic reconfiguration, inspect the active configuration with the ZooKeeper shell where possible, using get /zookeeper/config, and ensure local files do not conflict with the committed cluster configuration. If a node was rebuilt or replaced, clear only the appropriate local state after confirming backups and cluster membership; do not casually delete data directories from mulle nodes at once, as that can destroy quorum history.

After correcting hostnames, ports, firewall rules, authentication, or myid values, restart one node at a time when the ensemble still has quorum. Watch zookeeper.out or the configured log file for a stable role assignment such as LEADING or FOLLOWING. Then validate from mulle members with echo stat | nc localhost 2181 or echo mntr | nc localhost 2181. A healthy ensemble should show one leader, the remaining voting nodes as followers, and no continuous election loop.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Restarting ZooKeeper and Validating Cluster Health

After correcting configuration values, freeing ports, fixing permissions, or restoring quorum connectivity, restart ZooKeeper in a controlled way and verify that the ensemble returns to a stable state. Avoid restarting every node at once in a production quorum unless the cluster is already fully down. For a three-node ensemble, restart one server at a time when possible, waiting for each node to rejoin before moving to the next. This preserves availability and prevents a temporary maintenance action from becoming a full outage.

Use the service manager used by your installation. On systemd-based Linux hosts, restart and inspect the service with:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

sudo systemctl restart zookeeper
sudo systemctl status zookeeper --no-pager
sudo journalctl -u zookeeper -n 100 --no-pager

If ZooKeeper was installed from an Apache distribution package or is managed by scripts, use the bundled control command instead:

bin/zkServer.sh restart
bin/zkServer.sh status

Once the process is running, confirm that the node is listening on the expected client and quorum ports. The client port is commonly 2181, while quorum communication often uses ports such as 2888 and 3888 as defined in each server.X entry. Practical checks include:

  • ss -lntp | grep -E '2181|2888|3888' to confirm listening sockets.
  • nc -vz zk1.example.com 2181 from an application host to test client reachability.
  • nc -vz zk2.example.com 2888 and nc -vz zk2.example.com 3888 from peer nodes to test quorum paths.
  • tail -f /var/log/zookeeper/zookeeper.log or the configured log file to watch startup progress.

ZooKeeper also exposes lightweight health commands through the client port when four-letter word commands are enabled. From each node or a trusted admin host, run:

echo ruok | nc localhost 2181
echo stat | nc localhost 2181
echo srvr | nc localhost 2181
echo mntr | nc localhost 2181

A healthy response to ruok is imok. The stat or srvr output should show whether the node is a leader, follower, or standalone. In an ensemble, seeing standalone usually indicates that the node is not reading the intended cluster configuration, cannot reach peers, or has been started with the wrong config file. The mntr output is useful for checking request latency, outstanding requests, packet counts, and synced follower counts on the leader.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Validate the ensemble from the client perspective as well. Use zkCli.sh to connect through the same connection string used by applications:

bin/zkCli.sh -server zk1.example.com:2181,zk2.example.com:2181,zk3.example.com:2181
ls /
create /healthcheck ok
get /healthcheck
delete /healthcheck

If these operations succeed and remain consistent across reconnects, the client path is working. If commands hang, fail with connection loss, or repeatedly reconnect to the same node, recheck DNS, load balancer behavior, firewall rules, and whether all ensemble members advertise reachable hostnames.

Post-restart checks to prevent repeat failures

  • Confirm every node has a unique myid matching its server.X entry.
  • Ensure dataDir and dataLogDir have enough free disk space and are owned by the ZooKeeper service user.
  • Set monitoring alerts for process state, client port availability, quorum port availability, disk usage, and excessive request latency.
  • Keep a copy of the active zoo.cfg and document any ensemble membership changes.
  • Use rolling restarts for routine maintenance so quorum remains available.

When all nodes report an expected leader or follower role, health commands respond normally, application clients can create and read znodes, and logs no longer show binding, permission, snapshot, or quorum timeout errors, ZooKeeper can be considered restored to a healthy state.

Frequently Asked Questions

How do I find the exact ZooKeeper error that is preventing startup?

Start with the ZooKeeper log file, usually under the configured log directory or in files such as zookeeper.out. Look for messages about bind failures, missing myid files, snapshot corruption, permission denied, or failed quorum connections. Also run the service manually with the same configuration file to confirm whether the failure is caused by ZooKeeper itself or by the service manager.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What should I check first in zoo.cfg when ZooKeeper will not start?

Confirm that dataDir points to an existing directory owned by the ZooKeeper user and that clientPort is not already in use. In an ensemble, verify every server.X entry has the correct hostname or IP address and the correct quorum and election ports. Also make sure the myid file inside dataDir contains only the matching numeric server ID for that node.

How can I tell if a port conflict is causing the ZooKeeper error?

Use commands such as ss -lntp or netstat -lntp to check whether clientPort, quorum ports, or election ports are already bound by another process. If the port is occupied, stop the conflicting service or change the ZooKeeper port consistently across the configuration and dependent clients. After changing ports, update firewall rules and any application connection strings that point to ZooKeeper.

What does it mean if ZooKeeper starts on one node but cannot join the ensemble?

This usually points to quorum communication problems between servers rather than a local startup issue. Check that each node can reach the other nodes on the quorum and election ports using tools such as nc, telnet, or curl where applicable. Also verify DNS resolution, firewall rules, server.X entries, time synchronization, and that each node has a unique matching myid value.

How do I confirm ZooKeeper is healthy after restarting it?

Use the four-letter commands such as ruok, stat, mntr, or srvr if they are enabled in your configuration. A healthy node should respond to ruok with imok, and stat or srvr should show whether the node is a leader, follower, or standalone instance. For an ensemble, confirm that one node is leader, the others are followers, and client applications can connect using the full ZooKeeper connection string.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Bottom Line

Most ZooKeeper startup and connectivity errors come down to a few repeat offenders: incorrect configuration, ports already in use, bad permissions or stale files in the data directory, and broken quorum communication between nodes. Work through the checks methodically—verify zoo.cfg, confirm ports with ss or netstat, inspect logs, validate myid, and test peer reachability before restarting the ensemble.

Once the cluster is healthy, prevent repeat failures by standardizing configs, monitoring disk and port availability, backing up snapshots and transaction logs, and documenting safe restart procedures. If issues return, start with the logs and quorum status commands so you can isolate the failing node quickly and restore service with minimal downtime.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.