Skip to content

Ubuntu 10.04 lts server

vlamirc edited this page Jan 30, 2012 · 16 revisions

Ubuntu 10.04 Tomcat6 and Solr 1.4 Installation Steps:

Note: I am NOT a sys admin nor am I a *NIX superuser however, these setup steps seem to be working well to get Solr 1.4 and Tomcat 6 up an running for a sunpot / sunspot_rails project

Installing Solr and Tomcat 6 for working with sunspot / sunspot_rails

1. Install the Java JRE and Ant

$ sudo apt-get install openjdk-6-jdk ant

2. Create a solr user

$ sudo useradd solr

3. Create a password for the solr user

$ sudo passwd solr
  • choose a password

4. Change into the /opt director

$ cd /opt

5. Download tomcat (at the time v6.0.32)

$ sudo wget http://opensource.become.com/apache/tomcat/tomcat-6/v6.0.32/bin/apache-tomcat-6.0.32.tar.gz

6. Unpack tomcat

$ sudo tar -xzvf apache-tomcat-6.0.32.tar.gz

7. Rename the tomcat directory

$ sudo mv apache-tomcat-6.0.32 tomcat6

8. Recursively set the solr user to own the tomcat6 directory

$ sudo chown -R solr:solr tomcat6

9. Edit the tomcat users list

$ sudo pico tomcat6/conf/tomcat-users.xml
  • add the following:

<role rolename="manager"/>
  <role rolename="admin"/>
  <user username="tomcat" password="tomcat" roles="manager,admin"/>
  • choose a more secure password for the tomcat user

10. Test Tomcat works with the following:

$ sudo tomcat6/bin/catalina.sh run
  • use ctrl+c to stop tomcat

11. Change into the /etc/init.d directory

$ cd /etc/init.d

12. Download the startup script from: http://wiki.apache.org/solr/SolrTomcat?action=AttachFile&do=view&target=tomcat6

  • Note: can’t figure out how to get at the file with wget or curl

13. Paste the source into a file in /etc/init.d called tomcat6

$ sudo pico tomcat6
  • paste the contents of the file
  • BE SURE TO change the following line:
    $ export JAVA_HOME=/usr/java/default
  • TO:
    $ export JAVA_HOME=/usr
  • To set the JAVA_HOME path correctly

14. Make the file executable

$ sudo chmod +x tomcat6

15. Start tomcat to make sure the script works

$ sudo /etc/init.d/tomcat6 start

16. Make sure the stop script works

$ sudo /etc/init.d/tomcat6 stop

17. Add the service to start on boot

$ sudo update-rc.d tomcat6 defaults

18. Download Solr 1.4

$ sudo wget http://archive.apache.org/dist/lucene/solr/1.4.0/apache-solr-1.4.0.tgz
$ sudo wget http://www.ecoficial.com/apachemirror//lucene/solr/1.4.0/apache-solr-1.4.0.tgz [Currently 404'ing - use the above]

19. Unpack Solr

$ sudo tar -xzvf apache-solr-1.4.0.tgz

20. Move into the apache-solr dir

$ cd apache-solr-1.4.0

21. Build the .war file under dist

$ sudo ant dist

22. Build the example solr

$ sudo ant example

23. Test the solr example:

  • move into the example directory
    $ cd example
  • start the jetty server
    $ java -jar start.jar
  • visit localhost:8983/solr/admin
  • stop the jetty server (crtl+c)

24. Change back to the /opt directory

$ cd /opt

25. Make a solr directory

$ sudo mkdir solr

26. Change into the new solr directory

$ cd solr

27. Make a solr index directory

$ sudo mkdir example

28. Change back to the /opt directory

$ cd /opt

29. Copy the contents of apache-solr-1.4.0/example project to your new solr/example folder

$ sudo cp -r apache-solr-1.4.0/example/solr/* solr/example

30. Copy the apache-solr dist war file to you example folder

$ sudo cp apache-solr-1.4.0/dist/apache-solr-1.4.0.war solr/example/

31. Edit (or create if necessary) the Tomcat solr.xml file:

$ sudo pico tomcat6/conf/Catalina/localhost/solr.xml
  • add the following:
    
        <Context docBase="/opt/solr/example/apache-solr-1.4.0.war" debug="0" crossContext="true">
          <Environment name="solr/home" type="java.lang.String" value="/opt/solr/example" override="true"/>
        </Context>
    

32. Make sure that file is owned by the solr user:

$ sudo chown solr:solr tomcat6/conf/Catalina/localhost/solr.xml

33. Make a backup copy of the original solrconfig.xml file

$ sudo mv solr/example/conf/solrconfig.xml solr/example/conf/solfconfig.xml.original.bck

34. Create a new solrconfig.xml with the content from the sunspot gem solrconfig.xml file

$ sudo pico solr/example/conf/solrconfig.xml

35. Edit the dataDir for the solr/example project

$ sudo pico solr/example/conf/solrconfig.xml
  • look for the following line:
    <dataDir>${solr.data.dir:./solr/data}</dataDir>
  • change that line to:
    <dataDir>${solr.data.dir:/opt/solr/example/data}</dataDir>

36. Make a backup copy of the original schema.xml file:

$ sudo mv solr/example/conf/schema.xml solr/example/conf/schema.xml.original.bck

37. Create a new schema file with the content from the sunspot gem schema.xml file

$ sudo pico solr/example/conf/schema.xml
  • past the contents of the file that is generated by sunspot

38. Ensure that the /opt/solr directory is owned by the solr user

$ sudo chown -R solr:solr solr/

39. Start the tomcat server

$ sudo /etc/init.d/tomcat6 start

40: Visit your solr admin!

  • open browser to: localhost:8080/solr/admin (or whatever the server’s domain may be)

Notes on trouble shooting:

If your solr is kicking an error, stop tomcat, start it with the catalina server and try it.
If that works, stop the catalina server and try running your tomcat service again


$ sudo /etc/init.d/tomcat6 stop
$ sudo /opt/tomcat6/bin/catalina.sh run
  • check the solr admin
  • ctrl+c to stop catalnina
$ sudo /etc/init.d/tomcat6 start
  • check the solr admin again – should be working

(I have no idea what this fixes but it did the trick for me)

Bonus:
Sample Monit config file:

check process solr with pidfile /opt/tomcat6/bin/tomcat6.pid
  start program = "/etc/init.d/tomcat6 start"
  stop program = "/etc/init.d/tomcat6 stop"
  if failed host solr.domain.com port 8080 protocol http
    and request "/solr" then restart
  if totalmem is greater than 768 MB for 5 cycles then restart

Clone this wiki locally