Wednesday 25 January 2012

Setup Apache Solr on Windows with Jetty Running as a Service via NSSM

Setup Apache Solr on Windows with Jetty Running as a Service via NSSM

Initial Solr Setup

  1. Install the latest Java JDK from http://www.oracle.com/technetwork/java/javase/downloads/index.html. Make sure to select 64bit version if you need it.
    Get Latest Java Image
  2. Download Solr 1.4.1 from one of the mirrors at http://www.apache.org/dyn/closer.cgi/lucene/solr/ (at the time of writing, not all mirrors seem to be hosting 1.4.1, but most seem to have at least 1.4.0)
    Solr Mirror Image
  3. Unzip the Solr download. You should have the files listed in the image below. Open the example folder.
    Unzip Solr Image
  4. Copy the etc, lib, logs, solr, webapps, and start.jar folders to C:\solr (you will need to create the folder at C:\solr)
    Copy to Root Image
  5. Now open the C:\solr\solr folder and copy the contents back to the root C:\solr folder. When you are done you can delete the C:\solr\solr folder.
    Copy Solr to Root Image
  6. At this point your C:\solr directory should look like the image below.
    How your Directory Should Look Image
  7. Solr can now be run at this point if you start it from the command line. Change your directory to c:\solr and then run: java -Dsolr.solr.home=c:/solr/ -jar start.jar <= slash direction seems to matter
    Start Solr Command Image
  8. If you go to http://localhost:8983/solr/ you should be greeted with the Welcome to Solr message.
    Welcome to Solr Image

Setup Jetty to Run as a Windows Service using NSSM

Now that Solr is up and running, we can work on getting Jetty to run as a Windows service. Since Jetty comes bundled with Solr, all we need is a way to run it as a service. There are several options to do this, but the one that I have found works the best and is the most compatible across windows environments is NSSM – the Non Sucking Service.
Once you download NSSM, open the win32 or win64 folder as appropriate and copy nssm.exe to your c:\solr folder.
Copy NSSM Image => NSSM exe Image
  1. Open an elevated command prompt and change the directory to C:\solr. and then run: nssm install Solr
    Install Solr Service Image
  2. A dialog will open. Select java.exe as the Application located at C:\Windows\System32\
  3. In the options input box enter: -Dsolr.solr.home=C:/solr/ -Djetty.home=C:/solr/ -Djetty.logs=C:/solr/logs/ -cp C:/solr/lib/*.jar;C:/solr/start.jar -jar C:/solr/start.jar
    NSSM exe Image
  4. Important! If you copy and paste the line above make sure to take out the line break.
  5. Click Install service. You should get a Service successfully installed message.
    Solr Service Installed Image
  6. Finally run: net start Solr
    Start Solr Command Image
  7. Jetty should now be running as a service. Check by going to http://localhost:/8983/solr
Not working? The best way to see what is going on is to stop the service and then run java.exe -Dsolr.solr.home=C:/solr/ -Djetty.home=C:/solr/ -Djetty.logs=C:/solr/logs/ -cp C:/solr/lib/*.jar;C:/solr/start.jar -jar C:/solr/start.jar from the C:\Windows\System32\ folder and review all the log information in the output.

 

No comments:

Post a Comment