Tag Archives: solr

Configure logging in Solr

After the base installation of solr under tomcat 7 is now the step to configure seperate logging for solr. Fist step is to create a directory for the log file:

mkdir /var/log/solr
chown tomcat7:adm /var/log/solr

Now delete the following files in the extracted war lib folder (/usr/share/solr/war/WEB-INF/lib)

  • jcl-over-slf4j-1.6.4.jar
  • log4j-over-slf4j-1.6.4 .jar
  • slf4j-api-1.6.4.jar
  • slf4j-jdk14-1.6.4.jar

Copy the following files into this folder

  • slf4j-api-1.6.5.jar
  • slf4j-log4j12-1.6.5.jar
  • log4j-1.2.16.jar

Create a classes folder inside the WEB-INF folder

mkdir /usr/share/solr/war/WEB-INF/classes

Create a log4j.properties in this folder with the following sample content

log4j.rootLogger=WARN, solrLog
log4j.appender.solrLog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.solrLog.File=/var/log/solr/solr.log
log4j.appender.solrLog.Append=true
log4j.appender.solrLog.Encoding=UTF-8
log4j.appender.solrLog.DatePattern=’-‘yyyy-MM-dd
log4j.appender.solrLog.layout=org.apache.log4j.PatternLayout
log4j.appender.solrLog.layout.ConversionPattern=%d [%t] %-5p %c – %m%n
log4j.logger.org.apache.solr=INFO

Change folder and file rights to give the tomcat instance user full access

chown -R tomcat7:adm /usr/share/solr/war

Restart tomcat

service tomcat7 restart

Now you will find a solr.log inside/var/log/solr/

Configuring solr, tomcat 7 with mod_jk and apache 2.2

As follow up post to setting up solr i show you how to integrate tomcat into Apache as main web server:

The setup was made under ubuntu 11.10 with the following prerequisites:

  • CATALINA_HOME is /usr/share/tomcat7
  • JAVA_HOME is /usr/lib/jvm/default-java
  • HOSTNAME in my case is ubuntu-vm.localdomain

 

  1. apt-get install libapache2-mod-jk
  2. nano /etc/apache2/workers.properties with the following contents
workers.tomcat_home=/usr/share/tomcat7
workers.java_home=/usr/lib/jvm/default-java
ps=/
worker.list=ajp13
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
worker.ajp13.lbfactor=1
  1. nano /etc/apache2/mods-available/jk.conf with the following contents

        # Where to find workers.properties
        JkWorkersFile /etc/apache2/workers.properties
        # Where to put jk shared memory
        JkShmFile     /var/log/apache2/mod_jk.shm
        # Where to put jk logs
        JkLogFile     /var/log/apache2/mod_jk.log
        # Set the jk log level [debug/error/info]
        JkLogLevel    info
        # Select the timestamp log format
        JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
        # solr redirect
        JkMount /solr* ajp13

  1. less /etc/apache2/mods-available/jk.load to see the following contents
    1. LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so
  2. run a2enmod jk to see if mod_jk is enabled
    1. Module jk already enabled
  3. less /usr/share/tomcat7/conf/server.xml to see a line like this
    1. <Connector port=”8009″ protocol=”AJP/1.3″ redirectPort=”8443″ />
  4. nano /etc/apache2/sites-available/default and insert a line into the virtualHost:80 section
    1. JKMountCopy On
  5. restart apache2 with service apach2 restart
  6. Open a browser on your client to open http://ubuntu-vm.localdomain/solr/admin/

Installing Solr 3.5 under Tomcat 7

Solr is a open source Enterprise Search Engine. It can be deployed as war file in servlet containers like tomcat or jetty.

This short howto show you run solr with the current Tomcat 7 version:

  1. Download Solr as Zip
  2. Unzip it e.g. in /usr/share/ with folder structure
    1. mv apache-solr-3.5.0.zip /usr/share
    2. cd /usr/share
    3. unzip apache-solr-3.5.0.zip
    4. result is a folder /usr/share/apache-solr-3.5.0
  3. Create a new folder e.g /usr/share/solr as base folder for the configuration
    1. cp -a /usr/share/apache-solr-3.5.0/example/solr /usr/share/solr
    2. cp /usr/share/apache-solr-3.5.0/dist/*.war /usr/share/solr
    3. ln -s /usr/share/solr/apache-solr-3.5.0.war /usr/share/solr.war
    4. mkdir /usr/share/solr/data< for index data/li>
    5. mkdir /usr/share/solr/lib for additional jars
    6. cp /usr/share/apache-solr-3.5.0/dist/apache-solr-velocity-3.5.0.jar /usr/share/solr/lib
    7. cp -a /usr/share/apache-solr-3.5.0/contrib/ /usr/share/solr/
    8. nano /usr/share/solr/conf/solrconfig.xml and change the lib settings
    // ...
      
    
    
      
      
      
      
    
    
    1. chown -R tomcat:tomcat /usr/share/solr if tomcat server runs as user tomcat
  4. Add URIEncoding to tomcat connector settings
    1. nano /usr/share/tomcat7/conf/server.xml
    2. search for the connector on port 8080
    3. add the URIEncoding like this:
    
    
  5. Create a tomcat configuration file for solr (CATALINA_HOME is /usr/share/tomcat7)
    1. cd /usr/share/tomcat7/conf
    2. mkdir Catalina (if not exists)
    3. cd Catalina
    4. mkdir localhost (if not exists)
    5. cd localhost
    6. nano solr.xml
  6. Paste the following configuration and save the file


  

  1. Set properties for tomcat and solr inside /usr/share/tomcat7/bin/setenv.sh
  2. Paste the following configuration and save the file
export JAVA_OPTS="$JAVA_OPTS -Dsolr.solr.home=/usr/share/solr"
export JAVA_OPTS="$JAVA_OPTS -Dsolr.data.dir=/usr/share/solr/data"
export JAVA_OPTS="$JAVA_OPTS -Dsolr.velocity.enabled=true"
export JAVA_HOME="/usr/lib/jvm/default-java"
  1. (Re)start tomcat
    1. /etc/init.d/tomcat7 restart
  2. Open browser and go to http://YOUR_SERVER_HOSTNAME:8080/solr/admin/ assuming that tomcat runs under default port 8080

I use the provided sample xml files to see if import and query functionality works:

  1. cd /usr/share/apache-solr-3.5.0/example/exampledocs
  2. nano post.sh
  3. change the URL parameter to your environment e.g. to URL=http://localhost:8080/solr/update
  4. ./post.sh *.xml
  5. Open the admin ui under http://YOUR_SERVER_HOSTNAME:8080/solr/admin/
  6. click the search button

see my follow up post for Configuring solr, tomcat 7 with mod_jk and apache 2.2