Using ZooKeeper to Manage Configuration Files

With SolrCloud your configuration files are kept in ZooKeeper.

These files are uploaded in either of the following cases:

  • When you start a SolrCloud example using the bin/solr script.
  • When you create a collection using the bin/solr script.
  • Explicitly upload a configuration set to ZooKeeper.

Startup Bootstrap

When you try SolrCloud for the first time using the bin/solr -e cloud, the related configset gets uploaded to ZooKeeper automatically and is linked with the newly created collection.

The below command would start SolrCloud with the default collection name (gettingstarted) and default configset (_default) uploaded and linked to it.

bin/solr -e cloud -noprompt

You can also explicitly upload a configuration directory when creating a collection using the bin/solr script with the -d option, such as:

bin/solr create -c mycollection -d _default

The create command will upload a copy of the _default configuration directory to ZooKeeper under /configs/mycollection. Refer to the Solr Control Script Reference page for more details about the create command for creating collections.

Once a configuration directory has been uploaded to ZooKeeper, you can update them using the Solr Control Script

It’s a good idea to keep these files under version control.

Uploading Configuration Files using bin/solr or SolrJ

In production situations, Configsets can also be uploaded to ZooKeeper independent of collection creation using either Solr’s Solr Control Script or SolrJ.

The below command can be used to upload a new configset using the bin/solr script.

bin/solr zk upconfig -n <name for configset> -d <path to directory with configset>

The following code shows how this can also be achieved using SolrJ:

try (SolrZkClient zkClient = new SolrZkClient(zkConnectionString, ZK_TIMEOUT_MILLIS)) {
  ZkConfigManager manager = new ZkConfigManager(zkClient);
  manager.uploadConfigDir(Paths.get(localConfigSetDirectory), "nameForConfigset");

It is strongly recommended that the configurations be kept in a version control system, Git, SVN or similar.

Managing Your SolrCloud Configuration Files

To update or change your SolrCloud configuration files:

  1. Download the latest configuration files from ZooKeeper, using the source control checkout process.
  2. Make your changes.
  3. Commit your changed file to source control.
  4. Push the changes back to ZooKeeper.
  5. Reload the collection so that the changes will be in effect.

Preparing ZooKeeper before First Cluster Start

If you will share the same ZooKeeper instance with other applications you should use a chroot in ZooKeeper. Please see ZooKeeper chroot for instructions.

There are certain configuration files containing cluster wide configuration. Since some of these are crucial for the cluster to function properly, you may need to upload such files to ZooKeeper before starting your Solr cluster for the first time. Examples of such configuration files (not exhaustive) are solr.xml, security.json and clusterprops.json.

If you for example would like to keep your solr.xml in ZooKeeper to avoid having to copy it to every node’s solr_home directory, you can push it to ZooKeeper with the bin/solr utility (Unix example):

bin/solr zk cp file:local/file/path/to/solr.xml zk:/solr.xml -z localhost:2181
If you have defined ZK_HOST in (see instructions) you can omit -z <zk host string> from the above command.