Solr and tomcat

From snippet wiki
Jump to: navigation, search

Running a solr index server under a tomcat 8 server:

Directory structure

root@j:/opt# ls -la
drwxr-xr-x 12 root   root   4096 Mar 28 12:57 .
drwxr-xr-x 22 root   root   4096 Feb  5 12:35 ..
drwxr-xr-x  9 root   root   4096 Feb 24 20:51 apache-tomcat-8.0.20
drwxr-xr-x  9 root   root   4096 Mar 28 12:57 apache-tomcat-8.0.21
lrwxrwxrwx  1 root   root     11 Jan 12 21:00 java -> jdk1.8.0_25
drwxr-xr-x  8 root   root   4096 Sep 18  2014 jdk1.8.0_25
lrwxrwxrwx  1 root   root     11 Jan 12 21:01 solr -> solr-4.10.3
drwxr-xr-x  8 tomcat tomcat 4096 Jan 12 21:01 solr-4.10.3
drwxr-xr-x  6 tomcat tomcat 4096 Jan 13 09:12 solrhome
lrwxrwxrwx  1 root   root     20 Mar 28 12:57 tomcat -> apache-tomcat-8.0.21
drwxr-xr-x 11 tomcat tomcat 4096 Apr  3 17:15 tomcatbase

And define the tomcat/catalina base path within /etc/default/tomcat

JAVA_HOME=/opt/java
JAVA_OPTS="-Djava.awt.headless=true -Xmx1024M -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC"
AUTHBIND=yes
CATALINA_BASE=/opt/tomcatbase
TOMCAT_SECURITY=no

Setting things up

Make a copy or a symlink of the solr war file solr-4.10.3.war to solr.war, because the webapps folder hase to be the base name of the war file.

Create the file /opt/tomcatbase/conf/Catalina/localhost/solr.xml

<Context docBase="/opt/solr/dist/solr.war" crossContext="true" >
   <Environment name="solr/home" type="java.lang.String" value="/opt/solrhome" override="true" />
</Context>

After unpacking and deploying the war archive you have to add and change some parts within the webapps/solr path:

Copy the jar files for logging from /opt/solr/example/lib/ext/*.jar to the WEB-INF/lib/ folder including the log4j.properties file.

Add the security settings to the web.xml file:

...
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Solr authenticated application</web-resource-name>
      <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <role-name>solr-gui</role-name>
    </auth-constraint>
  </security-constraint>
 
  <login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>Test Realm</realm-name>
  </login-config>
 
  <security-role>
    <role-name>solr-gui</role-name>
  </security-role>
...

And create that role and some users for it within the global /opt/tomcatbase/conf/tomcat-users.xml file

Autoren der Seite / Contributors of the page

» Kai Kretschmann, (google+)