Skip to content

Instantly share code, notes, and snippets.

@ianmariano
Last active August 20, 2018 08:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianmariano/8478140 to your computer and use it in GitHub Desktop.
Save ianmariano/8478140 to your computer and use it in GitHub Desktop.
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

Zookeeper

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"
JAVA_OPTS="${JAVA_OPTS} ${SOLR_OPTS}"

Solr

curl -O http://psg.mtu.edu/pub/apache/lucene/solr/4.6.0/solr-4.6.0.tgz
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/zkcli.sh

cloud-scripts/zkcli.sh -cmd upconfig -z localhost:2181 -d /var/lib/solr/collection1/conf -n default
cloud-scripts/zkcli.sh -cmd linkconfig -z localhost:2181 -c collection1 -n default -s /var/lib/solr
cloud-scripts/zkcli.sh -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/log4j.properties /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"
		 docBase="/var/lib/solr/solr.war"
		 antiResourceLocking="false"
		 privileged="true">
	<Environment name="solr/home" override="true" type="java.lang.String" value="/var/lib/solr" />
</Context>

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:

http://server:8080/solr/admin/collections?action=CREATE&name=hello&numShards=2&replicationFactor=1&collection.configName=default

Index some stuff and query:

http://server:8080/solr/hello/select?q=*%3A*&wt=xml&indent=true

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