Skip to content

Instantly share code, notes, and snippets.

@chebyte
Created August 18, 2011 19:13
Show Gist options
  • Save chebyte/1154889 to your computer and use it in GitHub Desktop.
Save chebyte/1154889 to your computer and use it in GitHub Desktop.
Guide for configure Tomcat6, Solr 1.4, Sunspot for Rails Application on Ubuntu 8.04 or 10.04

Guide for configure Tomcat6, Solr 1.4, Sunspot for Rails Application on Ubuntu 8.04 or 10.04

1. Install the Java JRE and Ant

for ubuntu 8.04

add the following sources to /etc/apt/sources.list

deb http://us.archive.ubuntu.com/ubuntu/ hardy multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ hardy multiverse
deb http://us.archive.ubuntu.com/ubuntu/ hardy-updates multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ hardy-updates multiverse

for ubuntu 10.04


sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ferramroberto/java
$ sudo apt-get update
$ sudo apt-get install openjdk-6-jdk ant sun-java6-jdk sun-java6-bin sun-java6-jre

2. Change into the /opt director

$ cd /opt

3. Download tomcat (at the time v6.0.35)

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

4. Unpack tomcat

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

5. Rename the tomcat directory

$ sudo mv apache-tomcat-6.0.35 tomcat6

6. Recursively set the moonshine/capistrano user to own the tomcat6 directory

$ sudo chown -R rails:rails /opt/tomcat6

7. Edit the tomcat users list

$ sudo pico /opt/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

8. Test Tomcat works with the following: (localhost:8080)

$ sudo /opt/tomcat6/bin/catalina.sh run

  • use ctrl+c to stop tomcat

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

$ cd /etc/init.d

10. Paste this into a file in /etc/init.d called tomcat6 – https://gist.github.com/3285426


#!/bin/sh

  1. Tomcat Startup Script

CATALINA_HOME=/opt/tomcat6; export CATALINA_HOME
JAVA_HOME=/usr; export JAVA_HOME
TOMCAT_OWNER=rails; export TOMCAT_OWNER

start() {
echo -n "Starting Tomcat: "
su $TOMCAT_OWNER -c $CATALINA_HOME/bin/startup.sh
sleep 2
}
stop() {
echo -n "Stopping Tomcat: "
su $TOMCAT_OWNER -c $CATALINA_HOME/bin/shutdown.sh
}

case “$1” in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $“Usage: tomcat {start|stop|restart}”
exit
esac

11. Make the file executable

$ sudo chmod +x tomcat6

12. Start tomcat to make sure the script works

$ sudo /etc/init.d/tomcat6 start

13. Make sure the stop script works

$ sudo /etc/init.d/tomcat6 stop

14. Add the service to start on boot

$ sudo update-rc.d tomcat6 defaults

15. Download Solr 1.4

$ sudo wget http://archive.apache.org/dist/lucene/solr/1.4.0/apache-solr-1.4.0.tgz

16. Unpack Solr

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

17. Move into the apache-solr dir

$ cd /opt/apache-solr-1.4.0

18. Build the .war file under dist

$ sudo ant dist

19. Build the example solr

$ sudo ant example

20. Test the solr example:

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

21. Change back to the /opt directory

$ cd /opt

22. Make a solr directory

$ sudo mkdir /opt/solr

23. Change into the new solr directory

$ cd /opt/solr

24. Make a solr index directory

$ sudo mkdir /opt/solr/example

25. Change back to the /opt directory

$ cd /opt

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

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

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

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

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

$ sudo pico /opt/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>
    

29. Make sure that file is owned by the mooshine/capistrano user:

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

30. Copy solrconfig.xml file from the sunspot gem

$ sudo  cp RAILS_APP/solr/conf/solrconfig.xml /opt/solr/example/conf/solrconfig.xml

31. Edit the dataDir for the solr/example project

$ sudo pico /opt/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>

32. Copy schema.xml file from the sunspot gem

$ sudo cp RAILS_APP/solr/conf/schema.xml /opt/solr/example/conf/schema.xml

33. Ensure that the /opt/solr and /opt/tomcat6 directory is owned by the mooshine/capistrano user

$ sudo chown -R rails:rails /opt/* 

34. Start the tomcat server

$ sudo /etc/init.d/tomcat6 start

35: Visit your solr admin!

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

36: Security tomcat for accepts just local request

  • add to file /opt/tomcat6/context.xml
    $ sudo pico /opt/tomcat6/conf/context.xml
  • and add this
    <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.0\.0\.1"/>

OPTIONAL

*tomcat.god
%w{8080}.each do |port|
  God.watch do |w|
    w.name = "tomcat"
    w.interval = 30.seconds # default
    w.start = "/etc/init.d/tomcat6 start"
    w.stop = "/etc/init.d/tomcat6 stop"
    w.restart = "/etc/init.d/tomcat6 restart"
    w.start_grace = 10.seconds
    w.restart_grace = 10.seconds

    w.start_if do |start|
      start.condition(:process_running) do |c|
          c.interval = 5.seconds
          c.running = false
      end
    end
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment