As a followup to my previous article detailing how to deploy Liferay in a Jboss managed domain, I decided that I should build on that and explain how to deploy the Apache Solr enterprise search engine to a separate node within the Jboss-managed domain. This will explain how to deploy the Solr web application to a separate server within the same JBoss installation as Liferay and how to configure and deploy the Liferay solr-web.war plugin into Liferay.
NOTE: Liferay currently only supports Apache Solr version 1.4.1; more recent versions of the Solr application will not work without extensive modification of the Liferay Solr plugin.
This post assumes that you have a stock installation of JBoss 7.0.2 placed in /opt/liferay/jboss-7.0.2. The following variables will be used inline for brevity:
- ${JBOSS_HOME}: The root directory for the JBoss installation; for my purposes, this would be /opt/liferay/jboss-7.0.2.
- ${SOLR_HOME}: Solr’s “home” directory; the directory containing Solr configuration and index information. I will be using /opt/solr-home/solr-01 for this location.
- ${LIFERAY_HOME}: Liferay’s “home” directory; the directory containing the Liferay “deploy”, “data”, and “license” directories. By default, this is the parent directory of the application server installation directory; I will be using this default (/opt/liferay) for this document.
Create the JBoss server group and server for hosting the Solr server
First things first; it is necessary to create a separate JBoss server group and server for hosting the Apache Solr application; you do not want the Solr instance residing in the same JVM as the Liferay instance, for many reasons.
- Open the ${JBOSS_HOME}/domain/configuration/domain.xml file and locate the <server-groups /> container. Add the following content to create a server group for your Solr instance:
<server-group name="solr-server-group" profile="default"> <jvm name="default"> <heap size="128m" max-size="384m"/> </jvm> <socket-binding-group ref="standard-sockets"/> </server-group>
- Open the ${JBOSS_HOME}/domain/configuration/host.xml file and locate the <servers /> container. Add the following to add a server for your Solr instance:
<server name="solr-01" group="solr-server-group"> <system-properties> <property name="solr.solr.home" value="${SOLR_HOME}" /> </system-properties> <socket-binding-group ref="standard-sockets" port-offset="150"/> <jvm name="default" /> </server>
- Stop and start the target JBoss instance.
Run through basic configuration for the Solr instance
The initial configuration for Apache Solr consists of extracting the WAR and configuration files for Solr and deploying them to the appropriate locations.
- Download and unpack the apache-solr-1.4.1 archive from the Apache download site.
- From the unpacked apache-solr-1.4.1 directory, copy the contents of the example/solr/ directory into ${SOLR_HOME}.
- Copy the apache-solr-1.4.1.war file from the dist directory in the unpacked apache-solr-1.4.1 directory to /tmp/solr.war.
- Start the JBoss administration CLI by issuing the following command from the ${JBOSS_HOME}/bin directory:
./jboss-admin.sh --connect
- Deploy the apache-solr-1.4.1.war file by issuing the following command at the JBoss administration client prompt:
deploy /tmp/solr.war --server-groups=solr-server-group
Customize the solr-web.war Liferay plugin
- Download the solr-web plugin file from Liferay (at the time of this writing, the war file was named solr-web-6.1.0.1-ce-ga1-20120106155615760.war).
- Copy the solr-web.war file to ${LIFERAY_HOME}/deploy. This will cause Liferay to process the web plugin and expand it to ${JBOSS_HOME}/standalone/deployments/solr-web.war.
- From the expanded ${JBOSS_HOME}/standalone/deployments/solr-web.war directory, copy the schema.xml file located in WEB-INF/conf/ into the ${SOLR_HOME}/conf/ directory.
- Stop and start the JBoss server to force the Solr instance to pick up the new schema.xml
- Unpack the Liferay unbundled WAR file to /tmp/liferay-unbundled
- From /tmp/liferay-unbundled/WEB-INF/lib directory, copy the following jars into ${JBOSS_HOME}/standalone/deployments/solr-web.war/WEB-INF/lib/:
- commons-codec.jar
- commons-httpclient.jar
- commons-logging.jar
- Open the ${JBOSS_HOME}/standalone/deployments/solr-web.war/WEB-INF/classes/META-INF/solr-spring.xml file and modify the <constructor /> element as follows:
<constructor-arg type="java.lang.String" value="http://localhost:8230/solr" />
- Jar the contents of the ${JBOSS_HOME}/standalone/deployments/solr-web.war/ directory into /tmp/solr-web.war
- Start the JBoss administration CLI by issuing the following command from the ${JBOSS_HOME}/bin directory:
./jboss-admin.sh --connect
- Deploy the solr-web.war file by issuing the following command at the JBoss administration client prompt:
deploy /tmp/solr-web.war --server-groups=liferay-server-group