wiki:DebianSolrInstall

Solr on Debian Jessie/Wheezy/Jessie/Stretch

This method should work for Jessie with tomcat7 or tomcat8 and Stretch Tomcat 8 / openjdk8

For other version of Solr, follow all the steps below regarding 1.4.1, with the following differences:

There are some gotchas for some versions of Solr :

  • For Solr >= 4.3 :

see https://wiki.apache.org/solr/SolrLogging : "These versions do not include any logging jars in the WAR file. They must be provided separately."

You can get them from from solr archive you're using, for example for 4.8.1, copy solr-4.8.1/example/lib/ext/*.jar to /usr/share/tomcat7/lib/

Then create a file /usr/share/tomcat7/lib/log4j.properties

#  Logging level
log4j.rootLogger=WARN, file

# Log handler
log4j.appender.file=org.apache.log4j.FileAppender

#- File to log to and log format
log4j.appender.file.File=logs/solr.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%-5p - %d{yyyy-MM-dd HH:mm:ss.SSS}; %C; %m\n
  • For Solr >= 4.4 :

Core default name is collection1. So if your configuration was in /etc/solr/solr-dev/conf/ move configuration to /etc/solr/solr-dev/collection1/conf/ (multicore / core discovery : https://wiki.apache.org/solr/Core%20Discovery%20%284.4%20and%20beyond%29)

Installation

Install Debian's Tomcat 7 with OpenJDK JRE 7 on Wheezy (7.5):

# aptitude install openjdk-7-jre-headless tomcat7

Select OpenJDK JRE 7 for Tomcat and unplug security framework, it's a MAJOR pain to configure, and most applications won't work with the security framework enabled:

# vi /etc/default/tomcat7
...
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
TOMCAT7_SECURITY=no

Create Debian-style data dir:

# mkdir -p /var/lib/solr/data
# chown -R tomcat7:nogroup /var/lib/solr
# chmod -R o-rwx /var/lib/solr

Fetch a binary distribution (WAR) for Solr and deploy in webapps/ :

# wget http://archive.apache.org/dist/lucene/solr/1.4.1/apache-solr-1.4.1.tgz
# tar xzf apache-solr-1.4.1.tgz
# cp apache-solr-1.4.1/dist/apache-solr-1.4.1.war /var/lib/solr/solr-1.4.1.war

Create Tomcat context for Solr (it's mandatory to properly setup the solr/home config string):

# cat >/etc/tomcat7/Catalina/localhost/solr.xml
<?xml version="1.0" encoding="utf-8"?>
<Context docBase="/var/lib/solr/solr-1.4.1.war" debug="0" crossContext="true">
  <Environment name="solr/home" type="java.lang.String" value="/etc/solr" override="true"/>
</Context>
EOF

If you need multiple instances of Solr, you just need to create one xml file like above for each instance, name them for example like /etc/tomcat6/Catalina/localhost/solr-instance.xml and change value="/etc/solr" to /etc/solr/instance.

You need reference config files from Solr dist - at least solrconfig.xml and schema.xml are mandatory, others "*.txt" might be claimed, and adjust one setting:

# mkdir /etc/solr
# cp -r apache-solr-1.4.1/example/solr/conf /etc/solr
# vi /etc/solr/conf/solrconfig.xml
(uncomment and set: <dataDir>${solr.data.dir:/var/lib/solr/data}</dataDir>)

For multiple instances, just change /etc/solr/conf/solrconfig.xml to /etc/solr/instance/conf/solrconfig.xml and <dataDir>${solr.data.dir:/var/lib/solr/data}</dataDir> to <dataDir>${solr.data.dir:/var/lib/solr/data/instance}</dataDir>

You might tune a few things in /etc/tomcat7/server.xml:

  • You might bind the HTTP connector listening on port 8080 on a specific address/interface, add the address="127.0.0.1" attribute for instance.
  • Ensure that the URIEncoding="UTF-8" attribute is present for proper non-latin character support.
        <Connector port="8080" protocol="HTTP/1.1" 
                   connectionTimeout="20000" 
                   URIEncoding="UTF-8"
                   redirectPort="8443"
                   address="127.0.0.1"
                   maxHttpHeaderSize="8192"
                   maxThreads="150" 
                   minSpareThreads="25"
                   maxSpareThreads="75"
                   enableLookups="false"
                   acceptCount="100"
                   disableUploadTimeout="true"/>
    

Note for Drupal 6/7, use the files provided with apachesolr module:

  • protwords.txt
  • schema.xml
  • solrconfig.xml
  • stopwords.txt
  • synonyms.txt
  • mapping-ISOLatin1Accent.txt
  • elevate.xml

Now try it and debug it:

# /etc/init.d/tomcat7 restart
# tail -f /var/log/tomcat7/*.log
(catalina*.log is for deployment: missing dependencies, etc)
(localhost*.log is for app: missing or bogus conf file, etc)

# netstat -tnlp | grep java
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      18660/java      
tcp6       0      0 127.0.0.1:8080          :::*                    LISTEN      18660/java

Solr urls are made up from the XML filename (etc/tomcat6/Catalina/localhost/solr-instance.xml), for example:

In case you need replication between Solr instances, have a look at http://wiki.apache.org/solr/SolrReplication

Log rotation

Tomcat logs in /var/log/tomcat7 but there is an infinite daily log rotation with no compression, we need to change it to behave like apache (ie. rotation, compression and deletion handled by logrotate). First, edit /etc/logrotate.d/tomcat8 to add the following block:

/var/log/tomcat8/catalina.out {
  notifempty
  copytruncate
  daily
  rotate 8
  compress
  missingok
  create 640 tomcat8 adm
}

/var/log/tomcat8/*.log {
  notifempty
  copytruncate
  daily
  rotate 8
  compress
  missingok
  create 640 tomcat8 adm
}

Then edit /etc/tomcat7/server.xml and change the org.apache.catalina.valves.AccessLogValve (towards the end of the file) to look like this:

        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".log" rotatable="false"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

Then edit /etc/tomcat8/logging.properties : leave only the ConsoleHandler? :

handlers = java.util.logging.ConsoleHandler

.handlers = java.util.logging.ConsoleHandler

############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################

java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

Then restart Tomcat and remove the localhost_access_log.txt lying around in the log directory.

Solr 1.4 and 3.6 on Debian Squeeze

For Solr 3.6, follow all the steps below regarding 1.4.1, with the following differences:

Install Debian's Tomcat with Sun's JRE 6 on Squeeze (6.0):

# vi /etc/apt/sources.list
(add 'non-free' branch)
# aptitude install -R sun-java6-jre
(logout, relog)
# aptitude install tomcat6

If you don't log again, the Tomcat install script won't find Java, CLASSPATH and such and the install won't complete. It's not a problem, proceed with the modification below (/etc/default/tomcat6 and run apt-get install -f.

Select JRE 6 for Tomcat and unplug security framework, it's a MAJOR PITA to configure:

# vi /etc/default/tomcat6
...
JAVA_HOME=/usr/lib/jvm/java-6-sun
TOMCAT6_SECURITY=no

Create Debian style data dir:

# mkdir -p /var/lib/solr/data
# chown -R tomcat6:nogroup /var/lib/solr
# chmod -R o-rwx /var/lib/solr

Fetch a binary distribution (WAR) for Solr and deploy in webapps/ :

# wget http://archive.apache.org/dist/lucene/solr/1.4.1/apache-solr-1.4.1.tgz
# tar xzf apache-solr-1.4.1.tgz
# cp apache-solr-1.4.1/dist/apache-solr-1.4.1.war /var/lib/solr/solr.war

Create Tomcat context for Solr (it's mandatory to properly setup the solr/home config string):

# cat >/etc/tomcat6/Catalina/localhost/solr.xml
<?xml version="1.0" encoding="utf-8"?>
<Context docBase="/var/lib/solr/solr.war" debug="0" crossContext="true">
  <Environment name="solr/home" type="java.lang.String" value="/etc/solr" override="true"/>
</Context>
EOF

Important note : In Tomcat 5.5 and later, the war file must be stored outside of the webapps directory for this to work. Otherwise, this entire Context element is ignored. (http://wiki.apache.org/solr/SolrTomcat#Configuring_Solr_Home_with_JNDI)

You need reference config files from Solr dist - at least solrconfig.xml and schema.xml are mandatory, others "*.txt" might be claimed, and adjust two settings (dataDir and luceneMatchVersion):

# mkdir /etc/solr
# cp -r apache-solr-1.4.1/example/solr/conf /etc/solr
# vi /etc/solr/conf/solrconfig.xml
(uncomment and set: <dataDir>${solr.data.dir:/var/lib/solr/data}</dataDir>)
(add: <luceneMatchVersion>LUCENE_40</luceneMatchVersion>)

Note for drupal6 : use apachesolr module files

mkdir -p /etc/solr/conf
cp drupal-path/sites/all/modules/apachesolr/{protwords.txt,schema.xml,solrconfig.xml} /etc/solr/conf
cp apache-solr-1.4.1/example/solr/conf/{stopwords.txt,synonyms.txt,mapping-ISOLatin1Accent.txt,elevate.xml}
vi /etc/solr/conf/solrconfig.xml
(uncomment and set: <dataDir>${solr.data.dir:/var/lib/solr/data}</dataDir>)
(add: <luceneMatchVersion>LUCENE_40</luceneMatchVersion>)

You might tune a few things in /etc/tomcat6/server.xml:

  • You might bind the HTTP connector listeinng on port 8080 on a specific address/interface, add the address="127.0.0.1" attribute for instance.
  • Ensure that the URIEncoding="UTF-8" attribute is present for proper non-latin character support.
        <Connector port="8080" protocol="HTTP/1.1" 
                   connectionTimeout="20000" 
                   URIEncoding="UTF-8"
                   redirectPort="8443"
                   address="127.0.0.1"
                   maxHttpHeaderSize="8192"
                   maxThreads="150" 
                   minSpareThreads="25"
                   maxSpareThreads="75"
                   enableLookups="false"
                   acceptCount="100"
                   disableUploadTimeout="true"/>
    

Now try it and debug it:

# /etc/init.d/tomcat6 restart
# tail -f /var/log/tomcat6/*.log
(catalina*.log is for deployment: missing dependencies, etc)
(localhost*.log is for app: missing or bogus conf file, etc)

# netstat -tnlp | grep java
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      18660/java      
tcp6       0      0 127.0.0.1:8080          :::*                    LISTEN      18660/java

multiple instances of solr

Create a Tomcat context for each Solr instance :

  • Instance "solr-prod" :
    # cat >/etc/tomcat6/Catalina/localhost/solr-prod.xml
    <?xml version="1.0" encoding="utf-8"?>
    <Context docBase="/var/lib/solr/solr.war" debug="0" crossContext="true">
      <Environment name="solr/home" type="java.lang.String" value="/etc/solr/prod" override="true"/>
    </Context>
    EOF
    
  • Instance "solr-dev" :
    # cat >/etc/tomcat6/Catalina/localhost/solr-dev.xml
    <?xml version="1.0" encoding="utf-8"?>
    <Context docBase="/var/lib/solr/solr.war" debug="0" crossContext="true">
      <Environment name="solr/home" type="java.lang.String" value="/etc/solr/dev" override="true"/>
    </Context>
    EOF
    

Solr urls are made up from the XML filename :

Then ensure you've created and configured different dataDir for each Solr instance :

grep 'dataDir' /etc/solr/{prod,dev}/conf/solrconfig.xml
/etc/solr/prod/conf/solrconfig.xml:  <dataDir>${solr.data.dir:/var/lib/solr/data/prod}</dataDir>
/etc/solr/dev/conf/solrconfig.xml:  <dataDir>${solr.data.dir:/var/lib/solr/data/dev}</dataDir>

Solr 1.4 on Debian Lenny

Install Debian's Tomcat with Sun's JRE 6 on Lenny (5.0):

# vi /etc/apt/sources.list
(add 'non-free' branch)
# aptitude install -R sun-java6-jre
(logout, relog)
# aptitude install tomcat5.5

If you don't log again, the Tomcat install script won't find Java, CLASSPATH and such and the install won't complete. It's not a problem, proceed with the modification below (/etc/default/tomcat5.5 and run apt-get install -f.

Select JRE 6 for Tomcat and unplug security framwork, it's a MAJOR PITA to configure:

# vi /etc/default/tomcat5.5
...
JAVA_HOME=/usr/lib/jvm/java-6-sun
TOMCAT5_SECURITY=no

Fetch a binary distribution (WAR) for Solr and deploy in webapps/ :

# wget http://mir2.ovh.net/ftp.apache.org/dist//lucene/solr/1.4.1/apache-solr-1.4.1.tgz
# tar xzf apache-solr-1.4.1.tgz
# cp apache-solr-1.4.1/dist/apache-solr-1.4.1.war /var/lib/tomcat5.5/webapps/solr.war

Create Tomcat context for Solr (it's mandatory to properly setup the solr/home config string):

# mkdir -p /etc/tomcat5.5/Catalina/localhost
# cat >/etc/tomcat5.5/Catalina/localhost/solr.xml
<?xml version="1.0" encoding="utf-8"?>
<Context docBase="/var/lib/tomcat5.5/webapps/solr.war" debug="0" crossContext="true">
  <Environment name="solr/home" type="java.lang.String" value="/etc/solr" override="true"/>
</Context>
EOF

You need reference config files from Solr dist - at least solrconfig.xml and schema.xml are mandatory, others "*.txt" might be claimed, and adjust two settings (dataDir and luceneMatchVersion):

# mkdir /etc/solr
# cp -r apache-solr-1.4.1/example/solr/conf /etc/solr
# vi /etc/solr/conf/solrconfig.xml
(set: <dataDir>/var/lib/solr/data</dataDir>)
(add: <luceneMatchVersion>LUCENE_40</luceneMatchVersion>)

Now create Debian style data dir:

# mkdir -p /var/lib/solr/data
# chown -R tomcat55:nogroup /var/lib/solr
# chmod -R o-rwx /var/lib/solr

You might tune a few things in /etc/tomcat5.5/server.xml:

  • If you don't use the JK connector listening on port 8009, comment it out
  • You might bind the HTTP connector listeinng on port 8180 on a specific address/interface, add the address="127.0.0.1" attribute for instance.
  • Add the URIEncoding="UTF-8" attribute to the HTTP Connector for proper non-latin character support. Eg:
    <Connector port="8180" address="127.0.0.1" maxHttpHeaderSize="8192"
                   maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
                   enableLookups="false" redirectPort="8443" acceptCount="100"
                   connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="UTF-8" />
    

Now try it and debug it:

# /etc/init.d/tomcat5.5 restart
# tail -f /var/log/tomcat5.5/*.log
(catalina*.log is for deployment: missing dependencies, etc)
(localhost*.log is for app: missing or bogus conf file, etc)

# netstat -tnlp | grep jsvc
  tcp6    0    0 127.0.0.1:8180   :::*    LISTEN    8079/jsvc
Last modified 20 months ago Last modified on Oct 1, 2018, 4:33:08 PM