To verify if ZooKeeper is running or starting from the command line, follow these steps:
1. Check ZooKeeper Process
First, confirm if ZooKeeper is running by searching for its process. On Linux systems, use the ps command or the more specific pgrep command to find ZooKeeper processes. Commands are as follows:
bashps -ef | grep zookeeper
or
bashpgrep -f zookeeper
These commands list all processes containing 'zookeeper'. If output is displayed, it likely indicates that ZooKeeper is running.
2. Use ZooKeeper's Command Line Interface
ZooKeeper provides a command-line tool zkCli.sh for connecting to the server and performing operations. Attempting to connect verifies if ZooKeeper is active. Run the following command:
bash./zkCli.sh -server 127.0.0.1:2181
Replace 127.0.0.1:2181 with your ZooKeeper server's IP address and port. A successful connection means you enter the ZooKeeper command-line interface, confirming it is active.
3. Check Logs
ZooKeeper's log files are a reliable way to check its status. Typically, logs are located in the logs folder within the installation directory. View the latest log file for running status information:
bashtail -f /path/to/zookeeper/logs/zookeeper.out
Example Scenario
For example, I deployed ZooKeeper on my company's server and frequently checked its status. Once, an application reported inability to connect to ZooKeeper. I first ran pgrep -f zookeeper to check if the service was running. Finding no process ID returned indicated the service was not running. I then reviewed the log files and discovered a configuration error prevented startup. After correcting the configuration, I restarted ZooKeeper and verified it was running successfully using pgrep -f zookeeper.
By following these steps, you can effectively check and confirm ZooKeeper's running status.