Intro

According to the official Solr documentation, since version 5.0, it is not a recommended practice to have Solr run in a 3rd party container (such as Tomcat). You can read more about it here and here.

Based on the official information on how to install and run Solr, you simply extract the zip in a folder and run the executable. However, that's not all of it, unfortunately. The issue is that when following these instructions, you simply run the program. Nothing gets installed as a service, so if the server gets rebooted, you need to re-run the executable.

Furthermore, the relevant documentation page only lists how to make Solr run as a service under Linux and Unix-based systems.

Solution

Here's a rundown of what I did to get things smoothly working. Most of this stuff is from http://coding-art.blogspot.gr/2016/07/running-solr-61-as-windows-service.html and from https://www.norconex.com/how-to-run-solr5-as-a-service-on-windows/

Downloads

  1. Latest Solr (at the time of writing, this was 6.1.0). From http://www.apache.org/dyn/closer.lua/lucene/solr/6.1.0
  2. Latest Java Server JRE (at the time of writing, 1.8.102). From http://www.oracle.com/technetwork/java/javase/downloads/server-jre8-downloads-2133154.html. You will need to accept their License Agreement.
  3. Latest NSSM. From https://nssm.cc/download.

Installations

Java

The installation instructions for the Server JRE are located at http://docs.oracle.com/javase/8/docs/technotes/guides/install/windows_server_jre.html#CFHGHHFJ. Essentially, what they are saying is "extract the bundle and simply copy the files wherever you want". There are two issues with this:

  • the .tar.gz extention is not recognized by default in Windows. If that's the case with you, you need to download and install a compression/decompression utility that can handle this extension, such as 7-zip. You can get it from here as a portable app.
  • After extraction, I opted to copy the resultant folder "jdk1.8.0_102" into "C:\Program Files\Java"
Solr

As per the documentation, I unzipped the zip file and copied everything over to C:\Program Files\Solr-6.1.0

NSSM

Similar to Solr, I unzipped the file and copied everything over to C:\Program Files\nssm

Configurations
Java

I had to go and register an environment variable, namely JAVA_HOME, with the value of the path to my java installation (i.e. C:\Program Files\Java\jdk1.8.0_102). To do that in Windows 2012 I went to "Computer"--> right click --> "Properties" --> "Advanced System Settings" --> "Environment Variables" button and clicked on the "New" button under "System Variables".
The above is a crucial step, as without it, when you attempt to run Solr, you'll get the message that "JAVA_HOME has not been set".

Solr

First of all, open a command prompt as Administrator, change to the bin folder within the Solr installation folder (mine was C:\Program Files\Solr-6.1.0\bin) and issue the command

solr start

You should get something like the following:

C:\Program Files\solr-6.1.0\bin>solr start
Waiting up to 30 to see Solr running on port 8983
Started Solr server on port 8983. Happy searching

C:\Program Files\solr-6.1.0\bin>

that's great. It's running, you can verify this by opening a browser and going to http://localhost:8983/solr. Stop the server by issuing

solr stop -all

The Program Files folder is not a very handy location to have all the Solr Core definitions and data. So I decided to host this data within C:\Inetpub. I could equally go for C:\solr. In any case, copy the contents of the folder C:\Program Files\Solr-6.1.0\server\solr onto wherever you want to have the Solr files hosted. I went for C:\Inetpub\solr\solr-6.1.0-cores. The reason behind the extra "solr" folder will be explained in a bit.

Now in C:\Inetpub\solr I went and created a file called "solr_start.cmd". I opened it with notepad and wrote the following:

"C:\Program Files\solr-6.1.0\bin\solr" start -f -p 8983 -m 512m -s C:\inetpub\solr\solr-6.1-cores

the -f parameter means that Solr should run in the foreground. The -p sets the port, the -m sets the min/max amount of memory Solr is allowed to use and the -s tells the Solr server to look for cores (and create new ones) in that particular path.

Executing the solr_start.cmd, should get you a CLI with a lot of information, and no command prompt - the server is running in the foreground. If you open the Admin UI in a browser, you should be seeing the interface again, and also see an info message in the CLI that the admin interface has been accessed. Hit Ctrl-C in the window to stop the server (after a prompt to stop the batch job, where you should say "y" as in "yes").

You're now all set to configure the service via nssm.

NSSM

Open a command prompt as administrator and go to C:\Program Files\nssm\win64 (or win32 if you run a 32 bit system, which I doubt). From there, issue the following command:

nssm install "Apache Solr 6.1"

This will open up a GUI (after propmting for Admin approval) where you can fill in the pertinent information for the service you are about to install. As per this blog post, I filled in the following

  1. Application Tab
  2. Details Tab
  3. Log on Tab
  4. I/O Tab

Hit "Install service" and you're almost set.

You still need to start the service. So go to Control Panel --> System and Security --> Administrative Tools --> Services and locate the "Apache Solr 6.1" service and start it.

Once started, you can open up the Admin UI in the browser to verify that the instance is indeed running.

Happy searching!