I had a two bat files start.bat and stop.bat for starting and stopping SOLR server manually, Is it possible for me to create a windows serive which will call start.bat on starting the service and also call stop.bat on stopping the sERVICE
问题:
回答1:
Consider Solr Multicore feature with Tomcat. Each core is like a fully fledged installation, "separate configurations and indexes, with their own config and schema for very different applications, but still have the convenience of unified administration" http://wiki.apache.org/solr/CoreAdmin
Even if you dont use multiple indexes, it's much more elegant to set up. Solr is available on startup if Tomcat is set that way. I assume you are using Solr 1.4.
You need to do these steps:
Set up a solr root directory
Overview
c:\solr
|-lib
|-solr.war
|-solr.xml
- Create c:\solr
- from the Solr package directory, copy the lib directory to the root dir.
- from \example\webapps of Solr package directory, copy the solr.war
solr.xml has the following contents
<?xml version="1.0" encoding="UTF-8" ?> <solr persistent="false" sharedLib="lib"> <cores adminPath="/admin/cores"> <core name="myindex" instanceDir="myindexdir" /> </cores> </solr>
The core parameter specifies a new core. The attributes specify that for serving http//localhost:8080/mysearchapp/myindex, the index directory is myindexdir, which brings us to the next step.
Create the actual core
Overview
c:\solr
|-lib
|-solr.war
|-solr.xml
|-myindexdir
|-bin
|-conf
|-data
- copy the conf directory, where you have done your configuration to myindexdir. Dont bother creating bin and data, it will be automatically created.
Set up tomcat
- install Tomcat, run it once (dont skip this) and open http://localhost:8080 to see if it is successfully installed
- Of course, set it to start on boot by using services.msc
- Open this directory Apache Software Foundation\Tomcat 6.0\conf\Catalina\localhost
Create the file mysearchapp.xml
Context docBase="c:\solr\solr.war" debug="0" crossContext="true" > <Environment name="solr/home" type="java.lang.String" value="c:\solr\" override="true" /> </Context>
Restart tomcat and open http://localhost:8080/mysearchapp/ If all goes well it will display
Welcome to Solr! Solr Admin myindex
Now do your operations on your core like http://localhost:8080/mysearchapp/myindex/select?q=MY-QUERY
回答2:
Solr runs on top of a Servlet container like Tomcat. So for starting Solr you have to configure Solr with your Servlet container and then start.
Yes you can of course create a Windows Service. However you have not mentioned which Servlet container are you using for running Solr?
If it is Apache Tomcat here you go:
1. Just go to tomcat/bin folder from command prompt
2. Say service.bat install
3. You can see the service being listed in the Microsoft Services
Application
4. Right click on the service and add solr home (in Start
parameters). For an example if your Solr home is in D drive then:
-Dsolr.solr.home="D:\solr"
5.You are done. Just right click on the service, start it or even you can set
it to start automatically when your system starts.