Friday, June 20, 2014

Install Solr with Tomcat on CentOS

You must have at least version 1.6 in order to run Solr.

Installing Tomcat

yum -y install tomcat6 tomcat6-webapps tomcat6-admin-webapps
chkconfig tomcat6 on
service tomcat6 start
Use a web browser to check it is working correctly.
http://localhost:8080/
If you cannot connect, check your firewall rules
iptables -vnL --line-numbers
and make the necessary changes (Check these iptables snippets).

Config Tomcat

1. Tomcat user.

Ok, let’s go on. Add the following lines between the <tomcat-users> tag in /etc/tomcat6/tomcat-users.xml to add a manager role to your server:
<role rolename="manager" />
<role rolename="admin" />
<user username="tomcat" password="Pass.123" roles="manager,admin" />
Important: Make sure to change the previous username and password!

2. Change port to 8983.

Solr will be running on port 8983, so we need to change the default port of Tomcat to 8983 by modify /etc/tomcat6/server.xml and replace all 8080 port to 8983.
Restart Tomcat
service tomcat6 restart

3. Add a rule for port 8983 to iptables

sudo vi /etc/sysconfig/iptables
Add the following line into it.
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8983 -j ACCEPT

Installing Apache Commons Loggins

Download Apache Commons Logging from http://commons.apache.org/proper/commons-logging/download_logging.cgi to your home directory.
Untar your file and copy the required files to your tomcat library folder:
cd
tar zxf commons-logging-1.1.3.tar.gz
cd commons-loggins-1.1.3
cp commons-logging-*.jar /usr/share/tomcat6/lib

Installing SLF4J

Download the right version from http://www.slf4j.org/ to your home directory.
Untar your file and copy the required files to your tomcat library folder:
cd
tar zxf slf4j-1.7.5.tar.gz
cd slf4j-1.7.5
cp slf4j-*.jar /usr/share/tomcat6/lib
Update: Latest versions include a couple Android files (slf4j-android-1.7.7.jar and slf4j-android-1.7.7-sources.jar). Do not copy them. They will be read by tomcat preventing Solr to start.

Installing Solr (Finally!)

Download Solr (version 4.5.1) from the Apache website to your home directory:
http://lucene.apache.org/solr/downloads.html
Uncompress it:
cd
tar zxf ~/solr-4.5.1.tar.gz
Copy (and rename) the included Solr war file (solr.war) to your Tomcat apps folder:
cp ~/solr-4.5.1/dist/solr-4.5.1.war /usr/share/tomcat6/webapps/solr.war
Now it’s time to create the folder that will keep your Solr index and documents. We also have to copy a basic Solr structure into it. Fortunately, Solr comes with a predefined structure and includes preconfigured files in it. You have to make sure that there is plenty of space wherever you place this folder, since it can grow a lot. By the way, you can place this folder out of your Tomcat webapps folder.
In my case, I have decided to put it in /home/solr. So, let’s do it:
mkdir /home/solr
cp -R ~/solr-4.5.1/example/solr/* /home/solr
chown -R tomcat /home/solr
Restart Tomcat.
service tomcat6 restart
Solr is not ready yet, however this last time we restarted Tomcat it unpackaged the solr.war file. We need to edit a file inside that unpackaged directory structure.
Edit your Solr web.xml file to let it know where your solar directory is located:
nano /usr/share/tomcat6/webapps/solr/WEB-INF/web.xml
Look for the following code and edit it (don’t forget to remove the comment markers!):
<env-entry>
    <env-entry-name>solr/home</env-entry-name>
    <env-entry-value>/home/solr</env-entry-value>
    <env-entry-type>java.lang.String</env-entry-type>
</env-entry>
Ok… so, restart Tomcat
service tomcat6 restart
On your web browser go to:
http://localhost:8983/solr
If everything is ok, your Solr instance should be ready to go.
solr-admin

Troubleshooting

I recommend you to completely stop and start Tomcat over and over and take a look at:
tail /var/log/tomcat6/catalina.out
If you do not restart Tomcat each time, errors will not be logged to the catalina.out file.

500 issue

Mostly you will get a error with solr and error message is like "SolrCore ‘collection1′ is not available due to init failure: Could not load config file /home/solr/collection1/solrconfig.xml"
This is because by default solr enable clustering and we can disable it by modifying /home/solr/collection1/conf/solrconfig.xml.
vi /home/solr/collection1/conf/solrconfig.xml
Search for <bool name="clustering">true</bool> and change it to false.
Restart tomcat.

Write permission issue to /home/solr folder

Modify the permission to /home/solr and make sure the user who running tomcat/solr has write permission to it.

References

1 comment: