{"id":2324,"date":"2015-01-08T13:20:42","date_gmt":"2015-01-08T11:20:42","guid":{"rendered":"http:\/\/www.extradrm.com\/?p=2324"},"modified":"2015-01-08T14:40:14","modified_gmt":"2015-01-08T12:40:14","slug":"setting-up-apache-solr-jetty-on-windows-as-a-service","status":"publish","type":"post","link":"https:\/\/www.extradrm.com\/?p=2324","title":{"rendered":"Setting up Apache Solr multicore \/ Jetty on Windows 7"},"content":{"rendered":"<h2>Initial setup<\/h2>\n<p>We to deploy <code>Apache Solr<\/code> to <code>Jetty<\/code> or <code>Apache Tomcat especially when know that SolR has choosen Jetty as a Servlet container. Probably this choice is because it is \"light\" and can be easily embedded on the Solr distribution... so you can immediately have a running Solr server without requiring any other Servlet container (such as Tomcat, etc.). In terms of performance, not sure there will be such a big difference. Probably this depends on your own setup, for example in \"development\" I use Jetty, in production I use Tomcat, since I already am using it for other applications... In other hand, you can stop jetty service without affecting other web application. In case of stopping of Tomcat service all web applications on server are affected .... So for this tutorial we will use Jetty which need<br \/>\n<\/code><\/p>\n<ol>\n<li>Ensure Java version 1.7 or higher is present on the machine (java -version on cmd screen). If not, download it from <a title=\"Java website for download\" href=\"http:\/\/www.java.com\/\">http:\/\/www.java.com\/<\/a> <strong>(Java 7 is also known as 1.7<\/strong>).<\/li>\n<li>Download <a title=\"Apache Solr home\" href=\"https:\/\/lucene.apache.org\/solr\/\">latest Solr<\/a> (here Solr 4.9.1.zip) and unpack it somewhere.<\/li>\n<li>Create a directory where your Solr configuration and Jetty will live (e.g. <strong>C:\\Solr<\/strong>, which we will refer to as <strong>&lt;_SOLRDIR_&gt;<\/strong>).<\/li>\n<li>If you don\u2019t have Solr configuration defined yet, you can just copy Solr\u2019s own <strong>example\\solr<\/strong> directory to\u00a0<strong>&lt;_SOLRDIR_&gt;<\/strong>, such that\u00a0<strong>solr.xml<\/strong> is just inside\u00a0<strong>&lt;_SOLRDIR_&gt;<\/strong> directory.<br \/>\n<a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/WindowsSolrJetty.jpg\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-2325\" alt=\"WindowsSolrJetty\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/WindowsSolrJetty.jpg\" width=\"643\" height=\"343\" srcset=\"https:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/WindowsSolrJetty.jpg 792w, https:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/WindowsSolrJetty-300x160.jpg 300w\" sizes=\"(max-width: 643px) 100vw, 643px\" \/><\/a><\/li>\n<li>Under the\u00a0<strong>&lt;_SOLRDIR_&gt;<\/strong>, create subdirectory called <strong>jetty.<\/strong><\/li>\n<li>Copy the following directories and the files into the\u00a0<strong>jetty<\/strong> subdirectory from the Solr\u2019s <strong>example<\/strong> directory:\n<ul>\n<li>contexts<\/li>\n<li>etc<\/li>\n<li>lib<\/li>\n<li>logs<\/li>\n<li>resources (Solr 4.9+)<\/li>\n<li>webapps<\/li>\n<li>solr-webapp<\/li>\n<li>start.jar<\/li>\n<\/ul>\n<\/li>\n<li>From the command line in the\u00a0<strong>jetty<\/strong> directory, run the Solr server to make sure it works:\n<ol>\n<li>java -Dsolr.solr.home=.. -jar start.jar<\/li>\n<li>Ensure that Solr is accessible at: <a title=\"Solr admin interface\" href=\"http:\/\/localhost:8983\/solr\/\">http:\/\/localhost:8983\/solr\/<\/a><\/li>\n<li>Stop the server (Ctrl-C)<\/li>\n<\/ol>\n<p>&nbsp;<\/li>\n<li>In case of multicore configuration, copy multicore folder to c:\\solr (if you want to add cores see end of this topic):\n<ol>\n<li>java -Dsolr.solr.home=..\/multicore -jar start.jar<\/li>\n<li>Ensure that Solr is accessible at: <a title=\"Solr admin interface\" href=\"http:\/\/localhost:8983\/solr\/\">http:\/\/localhost:8983\/solr\/<\/a><\/li>\n<li>Stop the server (Ctrl-C)<\/li>\n<li>Here is what you see when adding a core2 to SolR<a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/Solr-Multicore.jpg\"><img loading=\"lazy\" class=\"aligncenter size-large wp-image-2328\" alt=\"Solr Multicore\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/Solr-Multicore-1024x433.jpg\" width=\"600\" height=\"253\" srcset=\"https:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/Solr-Multicore-1024x433.jpg 1024w, https:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/Solr-Multicore-300x126.jpg 300w, https:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/Solr-Multicore.jpg 1142w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/li>\n<\/ol>\n<h2>Jetty Service setup as a service Daemon for Windows<\/h2>\n<ol>\n<li>Download Apache Commons\u2019 <a href=\"http:\/\/www.apache.org\/dist\/commons\/daemon\/binaries\/windows\/\">Daemon package for Windows<\/a>\u00a0(make sure to get the Windows package that includes .exe files).<\/li>\n<li>Copy platform-appropriate <strong>prunsrv.exe<\/strong> into the <strong>jetty<\/strong>\u00a0directory and rename it to <strong>SolrService.exe<\/strong> \u2013 this is the actual Windows service executable.<\/li>\n<li>Copy <strong>prunmgr.exe<\/strong> into a new subdirectory <strong>jetty\/serviceui<\/strong> and rename it also\u00a0to\u00a0<strong>SolrService.exe<\/strong> (to provide default service name) \u2013 this is the UI that allows to correct some of the parameters of the service after it had been setup via the command line.<\/li>\n<li>Make sure that computer\u2019s environmental variables have\u00a0<strong>JAVA_HOME<\/strong> defined for system variables, not just for user\u2019s (run<strong> sysdm.cpl <\/strong>as Administrator). The variable value should look something like <strong><em>C:\\Progra~1\\Java\\jre7\u00a0<\/em><\/strong>. Otherwise, attempting to start the service will produce the following message in the daemon\/service logs:\u00a0<em>Unable to find Java Runtime Environment<\/em>.<\/li>\n<li>Run the service registration (with <a title=\"Parameters for prunsrv\/prunmgr\" href=\"http:\/\/commons.apache.org\/proper\/commons-daemon\/procrun.html\">renamed prunsrv<\/a>) as the Administrator on the command prompt after replacing <strong>&lt;_SOLRDIR_&gt;<\/strong> with the\u00a0actual path to the Solr installation as setup above.\u00a0\u00a0The command below should be all on a single line (with spaces instead of line breaks):\n<pre>SolrService.exe \/\/IS\/\/SolrService\r\n--DisplayName=\"Solr Service\"\r\n--Install=<strong>&lt;_SOLRDIR_&gt;<\/strong>\\jetty\\SolrService.exe\r\n--LogPath=<strong>&lt;_SOLRDIR_&gt;<\/strong>\\jetty\\logs\r\n--LogLevel=Debug\r\n--StdOutput=auto\r\n--StdError=auto\r\n--StartMode=java\r\n--StopMode=java\r\n--Jvm=auto\r\n++JvmOptions=-Djetty.home=<strong>&lt;_SOLRDIR_&gt;<\/strong>\\jetty\r\n++JvmOptions=-DSTOP.PORT=8087\r\n++JvmOptions=-DSTOP.KEY=stopsolr\r\n++JvmOptions=-Djetty.logs=<strong>&lt;_SOLRDIR_&gt;<\/strong>\\jetty\\logs\r\n++JvmOptions=-Dorg.eclipse.jetty.util.log.SOURCE=true\r\n++JvmOptions=-XX:MaxPermSize=128M\r\n--Classpath=<strong>&lt;_SOLRDIR_&gt;<\/strong>\\jetty\\start.jar\r\n--StartClass=org.eclipse.jetty.start.Main\r\n++StartParams=OPTION=ALL\r\n++StartParams=<strong>&lt;_SOLRDIR_&gt;<\/strong>\\jetty\\etc\\jetty.xml\r\n--StopClass=org.eclipse.jetty.start.Main\r\n++StopParams=--stop\r\n++JvmOptions=-Dsolr.solr.home=<strong>&lt;_SOLRDIR_&gt;<\/strong>\r\n--StartPath=<strong>&lt;_SOLRDIR_&gt;<\/strong>\\jetty<\/pre>\n<\/li>\n<li>Run the service:\n<ol>\n<li><strong>SolrService.exe start<\/strong><\/li>\n<li>Check the log files in the log subdirectory (usually\u00a0<strong>commons-daemon.&lt;date&gt;.log<\/strong>) for messages.<\/li>\n<li>If there is an error message, run\u00a0<strong>serviceui\\SolrService.exe<\/strong> and try to correct possible problems. An account that runs the service may need to switch to one with full access to the directories (e.g. Administrator).<\/li>\n<li>Run\u00a0<strong>SolrService.exe stop<\/strong> to stop the service and try starting again. If error log shows problems with stopping and the Services control panel shows the service as \u2018starting\u2019, see the troubleshooting section below on how to kill a run-away service.<\/li>\n<li>The success criteria here is being able to access Solr\u2019 Web Admin UI from <a title=\"Solr admin\" href=\"http:\/\/localhost:8983\/solr\">http:\/\/localhost:8983\/solr<\/a> (again).<\/li>\n<\/ol>\n<\/li>\n<li>In the Services control panel, change status of the service\u00a0<strong>Solr Service<\/strong>\u00a0from manual to automatic to ensure it survives restart. Try stopping and starting the service from the Services control panel to test that\u00a0it works. Use Solr\u2019 Web Admin UI to verify that\u00a0it has stopped\/started correctly.<\/li>\n<\/ol>\n<h2>Updating Solr configuration<\/h2>\n<ol>\n<li>Update would usually involve changes to <strong>schema.xml<\/strong>\u00a0and \u2013 much more rarely \u2013 to <strong>solrconfig.xml\u00a0<\/strong>.<\/li>\n<li>For example in this tutorial we must give the windows path to avoid warning messages<\/li>\n<li><a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/Solrconf.jpg\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-2330\" alt=\"Solrconf\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/Solrconf.jpg\" width=\"600\" height=\"268\" srcset=\"https:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/Solrconf.jpg 600w, https:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/Solrconf-300x134.jpg 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a>Most of the time, the core can be reloaded from the Solr\u2019s Web Admin UI to account for the new configuration : we should need to comment the 2 lines &lt;lib dir=$&#8230;<\/li>\n<li><a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/Solrconf1.jpg\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-2331\" alt=\"Solrconf1\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/Solrconf1.jpg\" width=\"603\" height=\"202\" srcset=\"https:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/Solrconf1.jpg 603w, https:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/Solrconf1-300x100.jpg 300w\" sizes=\"(max-width: 603px) 100vw, 603px\" \/><\/a>If the changes are significant (e.g. new collection or some deep server settings), the service itself may need\u00a0to be restarted.<\/li>\n<\/ol>\n<h2>Upgrading Solr<\/h2>\n<ol>\n<li>Download and unpack the latest 4.x version of Solr.<\/li>\n<li>Stop Solr service.<\/li>\n<li>Delete and re-copy\u00a0the directories into\u00a0<strong>jetty<\/strong> subdirectory as per the initial-installation instructions above, with two exceptions:\n<ol>\n<li>Keep\u00a0<strong>logs<\/strong> directory, which contains production logs.<\/li>\n<li>Delete\u00a0<strong>solr-webapp<\/strong> directory, which is an expanded version of \u2013 now obsolete \u2013\u00a0<strong>webapps\/solr.war<\/strong>. If this is not done, you will get version mismatch between old and new content. The\u00a0<strong>solr-webapp<\/strong> directory will be regenerated on the next Jetty restart.<\/li>\n<\/ol>\n<\/li>\n<li>If you need to update schema or config, do it now while the service is down.<\/li>\n<li>Restart the service.<\/li>\n<li>If you are running some persistent client, you may need to restart that as well.<\/li>\n<li>Test from Web Admin UI interface that the service is running.<\/li>\n<\/ol>\n<h2>\u00a0Troubleshooting service setup<\/h2>\n<p>If a service is misconfigured, Java runtime not found or something else goes wrong, you may get a run-away service that refuses to start and stop properly from the control panel. In which case, you may need to use command line tools (possibly as Administrator) to find and kill the stuck service:<\/p>\n<ol>\n<li>sc queryex<\/li>\n<li>taskkill \/PID <strong>&lt;PID&gt;<\/strong> \/F<\/li>\n<\/ol>\n<p>In here,\u00a0<strong>&lt;PID&gt;<\/strong> is the process ID for the solr service that is stuck.<\/p>\n<h2>Creating a core in a SolR mulicore instance under Jetty<\/h2>\n<p>Using Multiple SolrCores<br \/>\nIt is possible to segment Solr into multiple cores, each with its own configuration and indices. Cores may be dedicated to a single application or to very different ones, but all are administered through a common administration interface. You can create new Solr cores on the fly, shutdown cores, even replace one running core with another, all without ever stopping or restarting your servlet container.<br \/>\nSolr cores are configured by placing a file named <strong>solr.xml<\/strong> in your solr.home directory. A typical solr.xml looks like this:<\/p>\n<p>&lt;solr persistent=&#8221;false&#8221;&gt;<br \/>\n&lt;cores adminPath=&#8221;\/admin\/cores&#8221; host=&#8221;${host:}&#8221; hostPort=&#8221;${jetty.port:}&#8221;&gt;<br \/>\n&lt;core name=&#8221;core0&#8243; instanceDir=&#8221;core0&#8243; \/&gt;<br \/>\n&lt;core name=&#8221;core1&#8243; instanceDir=&#8221;core1&#8243; \/&gt;<br \/>\n&lt;\/cores&gt;<br \/>\n&lt;\/solr&gt;<br \/>\nThis sets up two Solr cores, named &#8220;core0&#8221; and &#8220;core1&#8221;, and names the directories (relative to the Solr installation path) which will store the configuration and data sub-directories. So you can add core2 by creating a folder core2 and copy the folder data and conf of core0<\/p>\n<p>So the File solr.xml under multicore becomes with one more core (core2) :<\/p>\n<p><a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/solr-multicore1.jpg\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-2337\" alt=\"solr-multicore1\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/solr-multicore1.jpg\" width=\"570\" height=\"180\" srcset=\"https:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/solr-multicore1.jpg 794w, https:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/solr-multicore1-300x94.jpg 300w\" sizes=\"(max-width: 570px) 100vw, 570px\" \/><\/a><br \/>\n<a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/Solrxml.jpg\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-2339\" alt=\"Solrxml\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/Solrxml.jpg\" width=\"720\" height=\"252\" srcset=\"https:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/Solrxml.jpg 905w, https:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/Solrxml-300x105.jpg 300w\" sizes=\"(max-width: 720px) 100vw, 720px\" \/><\/a><\/p>\n<hr \/>\n","protected":false},"excerpt":{"rendered":"<p>Initial setup We to deploy Apache Solr to Jetty or Apache Tomcat especially when know that SolR has choosen Jetty as a Servlet container. Probably this choice is because it is &#8220;light&#8221; and can&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":2847,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[320,2],"tags":[322,323],"youtube_video":null,"_links":{"self":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/2324"}],"collection":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2324"}],"version-history":[{"count":0,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/2324\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/media\/2847"}],"wp:attachment":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}