{"id":27334858,"url":"https://github.com/dmuth/zookeeper-demo","last_synced_at":"2025-10-12T08:02:33.503Z","repository":{"id":25366734,"uuid":"28794695","full_name":"dmuth/zookeeper-demo","owner":"dmuth","description":"A demo setup using Zookeeper on some virtual machines","archived":false,"fork":false,"pushed_at":"2023-05-22T21:34:20.000Z","size":49,"stargazers_count":0,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-05-02T06:07:47.397Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dmuth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-05T02:52:49.000Z","updated_at":"2021-06-02T00:21:31.000Z","dependencies_parsed_at":"2022-08-24T04:31:18.214Z","dependency_job_id":null,"html_url":"https://github.com/dmuth/zookeeper-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmuth%2Fzookeeper-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmuth%2Fzookeeper-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmuth%2Fzookeeper-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmuth%2Fzookeeper-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmuth","download_url":"https://codeload.github.com/dmuth/zookeeper-demo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248585243,"owners_count":21128971,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-12T14:46:29.356Z","updated_at":"2025-10-12T08:02:33.448Z","avatar_url":"https://github.com/dmuth.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Zookeeper-Demo\n\nZookeeper is a filesystem. Sort of.  It is also a database. Sort of.\n\nZookeeper allows you to store data that distributed, highly available, and highly consistent, even when some Zookeeper servers are unavailable. Common uses of Zookeeper include storage of configuration information, naming, providing distributed synchronization, and providing group services.\n\nIn an effort to learn Zookeeper, I put together a collection of scripts that talk to a virtual cluster of Zookeeper instances.  These scripts do reading, writing, and advanced features such as watching and master/leader election.\n\n\n## Quickstart\n\nMake sure you have Vagrant installed: [https://www.vagrantup.com/](https://www.vagrantup.com/)\n\nTo spin up 3 viritual machines, clone this repo and type: `vagant up zoo1 zoo2 zoo3`.  This will spin up (and provision) a cluster of 3 VMs each running Zookeeper.  Each instance uses 256 MB of RAM, for 3/4ths of a Gig total usage.\n\nThe provisioning process on each instance consists of the following:\n\n- Running `apt-get update`\n- Installing Zookeeper and Python Setuptools\n- Installing pip, the Python package manager\n- Installing the modules required by our Python code including [Kazoo](https://kazoo.readthedocs.org/en/latest/)\n- Installing configuration files and server IDs for each Zookeeper server\n- Restarting the Zookeeper server\n\n### Accessing the Zookeeper servers\n\nYou can SSH into each server by typing `vagrant ssh zoo1` (or zoo2 or zoo3 as appropriate).  Once SSHed into a server, each server has an internal IP as follows:\n\n- zoo1: 10.0.10.101\n- zoo2: 10.0.10.102\n- zoo3: 10.0.10.103\n\n\n## Quickstart with low RAM\n\nEach of those VMs takes up 256 MB of RAM.  Don't feel like wasting 3/4ths of a Gig of RAM just to play with Zookeeper?  No worries, I included a separate setup \nto run multiple copies of Zookeeper on the same VM.  To start that off, run:\n\n`vagrant up multi`\n\nSSH into that machine with `vagrant ssh multi` and Zookeeper will be listening on ports 2181, 2182, and 2183.  The utilities descirbed below will still work.  You will, however, have to use the `--host` argument.\n\n\n\n## Utilities to play with\n\nI've written the following Python scripts in `/vagrant/bin/` which let you play with Zookeeper\n\n- `watch.py` - Watches the /zkdemo znode in Zookeeper until the script is terminated with ^C.  All nodes that these scripts create are written there.  When a node is created, updated, or deleted, this script prints that out.  It's a good idea to leave this script running in one terminal while you run…\n- `create.py [NUMBER]` - Creates a single Znode under /zkdemo. The znode is ephemeral (it is deleted when the client disconnects) and seqeuntial (it receives a unique auto incrementing number, not unlike what MySQL does)  If an argument is specified, that is the number of seconds that this script stays running (and keeping the ephemeral node alive) before existing.  If NUMBER is not specified, the script runs for a random number of seconds between 1 and 60.\n    - Another use of this script is that it will check to see if multiple Znodes in that directory exist, and perform rudimentary master/leader election as outlined by the algorithm at [http://zookeeper.apache.org/doc/trunk/recipes.html#sc_leaderElection](http://zookeeper.apache.org/doc/trunk/recipes.html#sc_leaderElection)\n- `get.py` - Lists all znodes under /zkdemo and then exits.  This script (in addition to `watch.py`) is useful when running\n- `create-start.py NUMBER` - Run this script with an integer argment, and the same number of processes which cause `create.py` to be run in an endless loop will run.  Since `create.py` has a random timeout by default, this can be used to watch master election in action.\n- `create-stop.py` - Stop all of the scripts created by `create-start.py`\n- `acl-lockdown.py` - Lock down Zookeeper by making / read-only to everyone, except for 127.0.0.1, which has full access.\n    - Try running this script pointed directly at a server's IP (such as 10.0.10.101) and you'll see it fail with a NoAuth exception.\n- `create-with-acls.py` - Test out some node creation/deletion operations with ACLs based on IP addresses\n\nAll of the above scripts except for `create-start.py` take the optional argument `--host=IP[,IP[,IP[,…]]]` to specify specific IP addresses to connect to.  Kazoo will pick a random IP address from that list to try connecting to.  Zookeeper runs on port 2181, but there's no need to specifty the port number with `--hosts` as it is the default, and used when no port number is specified.  \n\nAssuming that the cluster is in working order, anything written to one node will be immediately readable by any other node, as Zookeeper is highly consistent.\n\n\n## Getting up close and personal with Zookeeper\n\n### The CLI\n\nThe CLI can be run by typing `/usr/share/zookeeper/bin/zkCli.sh` while on the command line of one of the virutal machines.\n\nThe `ls /` and `ls /zkdemo` commands are getting starting points.  `create`, `get`, and `delete` are also worth trying if you'd like to play around in Zookeeper and create your own znodes.\n\nRemember, anything written on one node will immediately be available on the other nodes, so it won't matter which machine you've SSHed into.\n\n\n### Logfiles and troubleshooting\n \nA good place to start looking for errors is `/var/log/zookeeper/zookeeper.log`.  It helps to ignore all lines that have \"INFO\" as the facility (and believe me, there will be many of those).  Pay attention to the WARN and ERROR lines instead.\n\n\n\n## Bugs\n\nI could never figure out how to get digest auth to work. (usernames and passwords)  Any advice is appreciated!\n\n\n## For Further Reading\n\n- [The Kazoo Documentation](https://kazoo.readthedocs.org/en/latest/)\n- [Apache Zookeeper Official Page](http://zookeeper.apache.org/)\n- [Zookeeper Internals](http://zookeeper.apache.org/doc/r3.4.1/zookeeperInternals.html)\n- [Call me maybe: Zookeeper](https://aphyr.com/posts/291-call-me-maybe-zookeeper)\n- [Apache Zookeeper: How do writes work?](http://stackoverflow.com/questions/5420087/apache-zookeeper-how-do-writes-work)\n- [How-to: Use Apache ZooKeeper to Build Distributed Apps (and Why)](http://blog.cloudera.com/blog/2013/02/how-to-use-apache-zookeeper-to-build-distributed-apps-and-why/)\n\n\n## Contact\n\nI can be reach via email (dmuth@dmuth.org) or [various forms of social media](http://www.dmuth.org/contact)\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmuth%2Fzookeeper-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmuth%2Fzookeeper-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmuth%2Fzookeeper-demo/lists"}