Howto: Install Apache Solr 1.4.1 on CentOS / Drupal 6

Tag: 

Setup Single Core Solr on CentOS

Upgrade Java
yum remove java
yum install java-1.6.0-openjdk
yum install java-1.6.0-openjdk-devel
Install Tomcat5
sudo yum install -y tomcat5

Install Solr 1.4.1
cd /usr/src/
curl http://mirror.lividpenguin.com/pub/apache/lucene/solr/1.4.1/apache-solr-1.4.1.tgz | tar xfz -
mkdir -p /data/solr
cp -R apache-solr-1.4.1/example/solr/* /data/solr
cp apache-solr-1.4.1/dist/apache-solr-1.4.1.war /data/solr/solr.war
Setup Tomcat -> Solr
vi /etc/tomcat5/Catalina/localhost/solr.xml
-----
<Context docBase="/data/solr/solr.war" debug="0" privileged="true" allowLinking="true" crossContext="true">
  <Environment name="solr/home" type="java.lang.String" value="/data/solr" override="true" />
</Context>
-----
Fix CentOS compat issues
cd /usr/share/tomcat5/common/endorsed/
ln -s /usr/share/java/xalan-j2.jar xalan-j2.jar
Set Perms
chown -R tomcat /data/solr/
Start Tomcat
/etc/init.d/tomcat5 start

Add Multiple Core Support

Setup directories and copy examples
mkdir -p /data/solr/cores
cp /usr/src/apache-solr-1.4.1/example/multicore/solr.xml /data/solr/
mkdir /data/solr/cores/core0
mkdir /data/solr/cores/core1
Edit solr core xml
vi /data/solr/solr.xml
 
from:
-----
    <core name="core0" instanceDir="core0" />
    <core name="core1" instanceDir="core1" />
-----
to:
-----
    <core name="core0" instanceDir="core/core0" />
    <core name="core1" instanceDir="core/core1" />
-----
Setup new core directories
for i in `ls /data/solr/cores`; do cp /data/solr/conf /data/solr/cores/$i/ -r; done
for i in `ls /data/solr/cores`; do mkdir /data/solr/cores/$i/data; done
Set Perms
chown -R tomcat /data/solr/
Restart Tomcat
/etc/init.d/tomcat5 restart

Add Apache Frontend

Install Apache2
yum install -y httpd
Add virtualhost - example below
<virtualhost *:80>
servername primary-1.solr.dev.example.net
serveralias solr.dev.example.net
serveradmin admin@example.net
documentroot /var/www/
errorlog /var/log/httpd/solr.dev.example.net.error.log
loglevel warn
customlog /var/log/httpd/solr.dev.example.net.access.log combined
serversignature on
##load balanced proxying
ProxyRequests Off
##remember to turn the next line off if you are proxying to a NameVirtualHost
ProxyPreserveHost On
<Proxy *>
        Order deny,allow
        Allow from all
</Proxy>
ProxyPass /solr balancer://my_cluster stickysession=JSESSIONID|jsessionid nofailover=On
<Proxy balancer://my_cluster>
        BalancerMember http://127.0.0.1:8080/solr route=node1
        #BalancerMember http://x.x.x.x:8080/solr route=node2
</Proxy>
##/status & /balancer info
<Location /balancer>
        SetHandler balancer-manager
        Order Deny,Allow
        Deny from all
        Allow from all
</Location>
ProxyStatus On
<Location /status>
        SetHandler server-status
        Order Deny,Allow
        Deny from all
        Allow from all
</Location>
</virtualhost>
Bind to tomcat local port
vi /etc/tomcat5/server.xml
from:
-----
<Connector port="8080" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" />
-----
to:
-----
<Connector port="8080" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               address="127.0.0.1"
               connectionTimeout="20000" disableUploadTimeout="true" />
-----
Restart Tomcat
/etc/init.d/tomcat5 restart

Setup Drupal -> Solr

1. Download / Extract Solr Module
        http://drupal.org/project/apachesolr
2. Download / Extract SolrPHPLibrary within new module directory
        curl http://solr-php-client.googlecode.com/files/SolrPhpClient.r22.2009-11-09.tgz | tar xfz -
3. Copy schema.xml / solrconfig.xml from new module directory to "conf" directory of solr core
           scp *.xml user@x.x.x.x:/data/solr/cores/core0/conf
4. Restart tomcat on solr server
            /etc/init.d/tomcat5 restart
5. Enable Solr Module
            /admin/build/modules
6. Point to solr server
            /admin/settings/apachesolr
            Solr host name: x.x.x.x
            Solr port: 80
            Solr path: /solr/core0/
            Save
</bash>