Adding ZooKeeper to your Sitecore 10 Docker install
March 2021
info
In this blog post, we boost our Sitecore development environment by launching multiple Solr nodes, coordinated by ZooKeeper within a Docker container
Using Sitecore's starter Docker files, we get a single Solr instance, running in SolrCloud mode with a single node.
While this is fine for development testing, it is handy from time-to-time to experiment and test with more production-like Solr topologies.
#
Solr in ProductionLet's refresh ourselves with guidance from Sitecore and the Solr project on what a good Production architecture looks like.
#
From Sitecore
- Solr Cloud 8.4.0 or higher must be hosted outside the Sitecore XP cluster
- The external hosted services for Microsoft SQL Server, SolrCloud and RedisLabs Redis are required for production Kubernetes support from Sitecore.
- You must deploy and configure the external services for production use before you deploy Sitecore XP to Kubernetes.
#
From Solr"Although Solr comes bundled with Apache ZooKeeper, you should consider yourself discouraged from using this internal ZooKeeper in production.
Shutting down a redundant Solr instance will also shut down its ZooKeeper server, which might not be quite so redundant. Because a ZooKeeper ensemble must have a quorum of more than half its servers running at any given time, this can be a problem.
The solution to this problem is to set up an external ZooKeeper ensemble."
Source: https://solr.apache.org/guide/6_6/setting-up-an-external-zookeeper-ensemble.html
Your redundancy requirements will determine exactly how many ZooKeeper and Solr nodes you use in a formation, but the foundational step for our local development environments is creating a separate ZooKeeper instance (within a container) and use that instance to manage our Solr instance (in a different container)
#
Creating a Windows ZooKeeper image to use with SitecoreWhile there are plenty of Linux ZooKeeper images on DockerHub, we need a Windows-compatible image to run alongside our other Windows Sitecore containers.
I ended up building my own image, and have included the Dockerfile
for you, below, should you want to use it for your own development environments.
Here are some choices I made when creating the Dockerfile:
- I mostly drive the building of the image with Powershell, so base the image on the Microsoft Powershell base image. With some work you'll be able to get ZooKeeper running on a slimmer base image.
- I handle the downloading of Java and ZooKeeper within the creation of the image, simply to make this image self-contained, so you can just download the file and run
docker build .
on your machine, and everything will work.
So, without further ado, let's build the image
#
Adding ZooKeeper to your docker-compose.ymlTo illustrate how we can use ZooKeeper and multiple Solr nodes in our development environments, I'm working with the Sitecore Docker Examples getting-started fileset. If you're working along with the examples, check that repository out and edit the files in docker-examples/getting-started/
Open docker-compose.yml
and add the following service definition above solr
#
Add three Solr nodesReplace your solr
service definition with the three definitions below. They're mostly the same as the definition we're replacing, with two differences:
- We need to make sure each service has a different port mapping, eg.
"8985:8983"
- We override the
entrypoint
of the Solr container to ensure the node is registered with ZooKeeper
#
Begin!OK. Now that we have a docker-compose.yml file with 1 x ZooKeeper and 3 x Solr nodes, let's run our containers.
#
Check the status of your SolrCloudNavigate to the Solr UI at http://localhost:8984/solr/#/
. First, check Cloud > ZK Status
to make sure ZooKeeper is happy.
Next, check Cloud > Nodes
. Here, we can see which Solr nodes are hosting which collections.
Looking a bit more closely, we can see that our collections are all empty, and no documents are loaded yet.
#
Populate the schemaOnce your Sitecore Docker containers are all up and running, you can use Sitecore > Control Panel > Populate Solr Managed Schema
to do just that.
#
Perform initial indexingNow, we can perform an initial index, by using Sitecore > Control Panel > Indexing Manager
#
Final status of our SolrCloudBack in our Solr UI, we can refresh Cloud > Nodes
to see our distributed set of collections nicely populated.
Have fun and come chat to me on Sitecore Slack if you have any questions.