Skip to content

Instantly share code, notes, and snippets.

@ianmariano ianmariano/
Last active Aug 20, 2018

What would you like to do?
Setting up SolrCloud (Solr 4.6.0)

Setup SolrCloud

These instructions are for Ubuntu 13.10 x64. Each server should have a proper resolvable hostname!

Environment Setup

Java 7

sudo aptitude install openjdk-7-jre-headless java7-runtime-headless


Setup Zookeper and make it a cluster

sudo aptitude install zookeeperd zookeeper-bin
sudo service zookeeper stop

Set up a unique numeric id (1-255) per server

sudo vi /etc/zookeeper/conf/myid

Add each server to the cluster

sudo vi /etc/zookeeper/conf/zoo.cfg

Start the cluster (each server)

sudo service zookeeper start

If you examine the log (/var/log/zookeeper/zookeeper.log) you can see the cluster activity.

Tomcat 7

sudo aptitude install tomcat7-admin tomcat7

Edit the tomcat users for the UI

sudo vi /etc/tomcat7/tomcat-users.xml
sudo vi /etc/default/tomcat7

Add the following to /etc/defaults/tomcat7, adding the zookeeper cluster servers with their proper hostnames or IP addresses to the zkHost definition next time Tomcat starts:

SOLR_OPTS="-DzkHost=zookeeper1:2181,zookeeper2:2181 -DhostPort=8080"


curl -O
tar xvzf solr-4.6.0.tgz
cd solr-4.6.0/example
sudo mkdir /var/lib/solr
sudo cp -r solr/collection1 solr/solr.xml /var/lib/solr
sudo vi /var/lib/solr/solr.xml

Alter the solr.xml:

  • host value from ${host:} to ${host:hostname} with the proper hostname (alternately set the hostname in the Tomcat server.xml or as part of the SOLR_OPTS in /etc/default/tomcat7 above)
  • hostPort value from ${jetty.port:8983} to ${hostPort:8080}

And make sure Tomcat owns the Solr home:

sudo chown -R tomcat7:tomcat7 /var/lib/solr

Upload the config to Zookeeper, link it to the first collection and setup the bootstrap

Only on the first server to setup the first collection to bootstrap its configuration.

java -jar start.jar

Wait until you see it has extracted the solr.war, then Ctrl+C to stop it. This is necessary to extract the jars to support cloud-scripts/

cloud-scripts/ -cmd upconfig -z localhost:2181 -d /var/lib/solr/collection1/conf -n default
cloud-scripts/ -cmd linkconfig -z localhost:2181 -c collection1 -n default -s /var/lib/solr
cloud-scripts/ -cmd bootstrap -z localhost:2181 -s /var/lib/solr

Now set up a place for Solr to live and run it under Tomcat

sudo mkdir /var/lib/solr
sudo mkdir /var/lib/tomcat7/lib
sudo cp webapps/solr.war /var/lib/solr/
sudo cp lib/ext/* /var/lib/tomcat7/lib
sudo cp resources/ /var/lib/tomcat7/lib/

Create the Tomcat context for Solr

sudo vi /etc/tomcat7/Catalina/localhost/solr.xml

with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/solr/home"
	<Environment name="solr/home" override="true" type="java.lang.String" value="/var/lib/solr" />

Restart Tomcat.

sudo service tomcat7 restart

Repeat all but the Zookeeper bootstrapping on the first server.

Create a new collection by hitting up one of the servers:


Index some stuff and query:


Add more configurations and go!

See also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.