Skip to main content

Installing solr 4.x on tomcat 7 on debian 7

Depending on your needs, you can install it through the package manager or manually. Installing via the package manager is always more convenient, as are updates, but depending on the repositories you use, it may be outdated, so the decision is up to you. Since this is a basic configuration to set up a quick solr service for testing, local, etc., the following guidelines are for the package manager:

 

Java installation:

 

We install the basic java package.

# aptitude install openjdk-7-jre-headless

Optional:

# aptitude install java7-jdk

 

 

Tomcat installation:

 

Base:

# apt-get install tomcat7

Administration panel:

# apt-get install tomcat7-admin

Check that it is running:

# service tomcat7 start

The default port for tomcat7 is 8080, we can check it by going to

http://localhost:8080

or

http://{IP}:8080/

Since port

8080

is often used by other services, we can change the port (e.g., 8983) with the following command.

# sed -i s/8080/8983/g /usr/local/tomcat/conf/server.xml
# service tomcat7 restart

 

 

Authentication

 

For security reasons (in addition to any firewall we might set up) we will add a username and password to control access.

We edit the file:

tomcat-users.xml # vim /etc/tomcat7/tomcat-users.xml

We include the following instructions before the closing tag:

</tomcat-users>
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="your_username" password="your_password" roles="manager-gui,admin-gui"/>

We restart the machine:

# service tomcat7 restart

 

 

Solr installation

 

We download the latest version of 4.x (http://www.apache.org/dyn/closer.cgi/lucene/solr)

 # wget http://archive.apache.org/dist/lucene/solr/4.10.0/solr-4.10.0.tgz | tar xz

We start from the default configuration of the Solr example and include it in tomcat's class path.

Note: The tomcat classpath directory contains symbolic links to the JARs in

/usr/share/java

You can do the same with the solr ones if you want, but since we will only use Solr from tomcat, we prefer to include them directly (in future updates you will only need to replace them).

 # cp ~/solr-4.10.0/example/lib/ext/* /usr/share/tomcat7/lib/

We include the Solr WARs inside Tomcat's webapps directory so that Tomcat can deploy the application.

Note: By default, tomcat deploys WARs in folders with the same name, so once deployed, the directory

/var/lib/tomcat7/webapps/solr

should exist. The service will run from there.

# cp ~/solr-4.10.0/dist/solr-4.10.0.war /var/lib/tomcat7/webapps/solr.war

 

 

Catalina

 

Catalina is a Tomcat servlet container: the Tomcat server component that interacts with Java servlets.

We copy the solr example files to the Catalina directory:

/var/lib/tomcat7

and set the permissions so that Tomcat can interact.

# cp -R ~/solr-4.10.0/example/solr /var/lib/tomcat7
# chown -R tomcat7:tomcat7 /var/lib/tomcat7/solr

The Solr application should appear listed as running at:

http://localhost:8080/manager/html

We restart the service to check that everything has been configured correctly.

# service tomcat7 restart

At this point Solr will be running at

http://localhost:8080/solr.

 

Authentication

 

For security reasons, we add access protection to solr.

# service tomcat7 stop

Even if port 8080 is not publicly accessible, it is a good idea to set up authentication to prevent internal unauthorized access.

We edit the file

/var/lib/tomcat7/webapps/solr/WEB-INF/web.xml

(Includes the Solr app configuration).

# vim /var/lib/tomcat7/webapps/solr/WEB-INF/web.xml

We add the following instruction before the closing tag:

<security-constraint>
  <web-resource-collection>
    <web-resource-name>Solr GUI Authentication</web-resource-name>
    <url-pattern>/*</url-pattern>
    <http-method>GET</http-method>
    <http-method>POST</http-method>
  </web-resource-collection>
  <auth-constraint>
    <role-name>solr-gui</role-name>
  </auth-constraint>
 
  <user-data-constraint>
    <transport-guarantee>NONE</transport-guarantee>
  </user-data-constraint>
</security-constraint>
 
<login-config>
  <auth-method>BASIC</auth-method>
</login-config>

This adds a basic HTTP authentication (username and password) for the role

solr-gui

We edit the /etc/tomcat7/tomcat-users.xml file again to add a user with the created role:

<user username="your_username" password="your_password" roles="solr-gui"/>

We restart:

# service tomcat7 restart

We check that accessing

 http://localhost:8080/solr 

now asks for credentials. Similarly, we could have used the same user as before by adding the new role

solr-gui
<user username="your_username" password="your_password" roles="manager-gui,admin-gui,solr-gui"/>

Enjoy your new solr!

  • Jorge Tutor

    Jorge Tutor

    CIO