{"id":2463,"date":"2015-01-26T22:23:03","date_gmt":"2015-01-26T20:23:03","guid":{"rendered":"http:\/\/www.extradrm.com\/?p=2463"},"modified":"2015-03-13T09:18:57","modified_gmt":"2015-03-13T07:18:57","slug":"solr-4-jetty-9-and-search-api-on-ubuntu-2","status":"publish","type":"post","link":"https:\/\/www.extradrm.com\/?p=2463","title":{"rendered":"Solr 4, Jetty 9 Multicore Drupal Solr Search API on Ubuntu"},"content":{"rendered":"<p>First let me say I love the new UI for the Solr Admin pages (<a href=\"https:\/\/lucene.apache.org\/solr\/\" target=\"_blank\">download at Apache Solr<\/a>).<br \/>\n<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><br \/>\n<strong>Install Jetty 9<\/strong><\/p>\n<p>Jetty 9 requires <strong>JDK 7<\/strong>, so if you don\u2019t have it installed, install it first. In Ubuntu, it is very convenient to install openjdk using apt-get.<\/p>\n<pre>apt-get install -y openjdk-7-jdk\r\nmkdir -p \/usr\/java\r\nln -s \/usr\/lib\/jvm\/java-7-openjdk-amd64 \/usr\/java\/default<\/pre>\n<p>Extract the tarball of Jetty 9 to a preferred directory, e.g. \/opt. Then set $JETTY_HOME, create a new user called \u201cjetty\u201d and make it the owner of $JETTY_HOME.<\/p>\n<pre>tar zxvf jetty-distribution-9.0.3.v20130506.tar.gz -C \/opt\r\nmv \/opt\/jetty-distribution-9.0.3.v20130506\/ \/opt\/jetty\/\r\nuseradd jetty -U -s \/bin\/false\r\nchown -R jetty:jetty \/opt\/jetty<\/pre>\n<h2>Installing Solr Manually<\/h2>\n<p><strong>Lets put all this in \/opt<\/strong><\/p>\n<pre># cd \/opt<\/pre>\n<p><strong>Let&#8217;s make a Solr user<\/strong><\/p>\n<pre># adduser solr<\/pre>\n<p><strong>We can now start the real installation of Solr. First, download all files and uncompress them:<\/strong><\/p>\n<pre>cd \/opt\r\nwget http:\/\/archive.apache.org\/dist\/lucene\/solr\/4.9.1\/solr-4.9.1.tgz\r\ntar -xzvf solr-4.9.1.tgz\r\ncp -R solr-4.9.1\/example \/opt\/solr\r\ncd \/opt\/solr\r\njava -jar start.jar<\/pre>\n<p><em>Check if it works by visiting <code>http:\/\/YOUR_IP:8983\/solr<\/code>. When it works, go back into your SSH session and close the window with Ctrl+C.<\/em><strong><br \/>\n<\/strong><\/p>\n<p><strong>Make a place for Solr<\/strong><\/p>\n<pre># mkdir \/opt\/solr<\/pre>\n<p><strong>Lets put all this in \/opt<br \/>\n<\/strong># cd \/opt<br \/>\n<strong>Get some files<\/strong><\/p>\n<pre># wget http:\/\/apache.mirror.serversaustralia.com.au\/lucene\/solr\/4.9.1\/solr-4.9.1.tgz\r\n# wget http:\/\/ftp.drupal.org\/files\/projects\/search_api_solr-7.x-1.6.tar.gz<\/pre>\n<p><strong>After that, download the start file and set it to automatically start up if it hasn&#8217;t been done already:<\/strong><\/p>\n<pre>sudo wget -O \/etc\/init.d\/jetty http:\/\/dev.eclipse.org\/svnroot\/rt\/org.eclipse.jetty\/jetty\/trunk\/jetty-distribution\/src\/main\/resources\/bin\/jetty.sh\r\nsudo chmod a+x \/etc\/init.d\/jetty\r\nsudo update-rc.d jetty defaults<\/pre>\n<p>Finally start Jetty\/Solr:<\/p>\n<pre>sudo \/etc\/init.d\/jetty start<\/pre>\n<pre>service jetty start<\/pre>\n<p>You can now access your installation just as before at http:\/\/YOUR_IP:8983\/solr.<\/p>\n<p><strong>Copy the Solr application into Jetty (this is how we do it in Jetty 9)<\/strong><\/p>\n<pre># cp -a solr-4.9.1\/dist\/solr-4.9.1.war \/opt\/jetty\/webapps\/solr.war\r\n# cp -a solr-4.9.1\/example\/contexts\/solr-jetty-context.xml \/opt\/jetty\/\r\n# cp -a solr-4.9.1\/example\/lib\/ext\/* \/opt\/jetty\/lib\/ext\/<\/pre>\n<p>Also, you will need the context and some modules to have Solr run properly on Jetty.<\/p>\n<pre># cp -a solr-4.9.1\/example\/contexts\/solr-jetty-context.xml \/opt\/jetty\/webapps\/solr.xml\r\n# cp -a solr-4.9.1\/example\/lib\/ext\/* \/opt\/jetty\/lib\/ext\/<\/pre>\n<p>Copy the Solr config into place<\/p>\n<pre># cp -a solr-4.9.1\/example\/solr \/opt\/solr\r\n# cp -a solr-4.9.1\/dist\/ \/opt\/solr\r\n# cp -a solr-4.9.1\/contrib\/ \/opt\/solr<\/pre>\n<p><strong>Make a place for logs<\/strong><\/p>\n<pre># mkdir \/opt\/solr\/logs<\/pre>\n<p><strong>Everything is owned by Solr<\/strong><\/p>\n<pre># chown -R solr:solr \/opt\/solr\/logs<\/pre>\n<p><strong>Open the \/etc\/default\/jetty file (nano \/etc\/default\/jetty) and paste this into it<\/strong><br \/>\n# sudo nano \/etc\/default\/jetty<\/p>\n<pre>NO_START=0 # Start on boot\r\nJAVA_OPTIONS=\"-Dsolr.solr.home=\/opt\/solr\/solr $JAVA_OPTIONS\"\r\nJAVA_HOME=\/usr\/java\/default\r\nJETTY_HOME=\/opt\/solr\r\nJETTY_USER=solr\r\nJETTY_LOGS=\/opt\/solr\/logs<\/pre>\n<p><strong>Open the file \/opt\/solr\/etc\/jetty-logging.xml (nano \/opt\/solr\/etc\/jetty-logging.xml) and paste this into it:<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\"?&gt;\r\n  &lt;!DOCTYPE Configure PUBLIC \"-\/\/Mort Bay Consulting\/\/DTD Configure\/\/EN\" \"http:\/\/jetty.mortbay.org\/configure.dtd\"&gt;\r\n  &lt;!-- =============================================================== --&gt;\r\n  &lt;!-- Configure stderr and stdout to a Jetty rollover log file --&gt;\r\n  &lt;!-- this configuration file should be used in combination with --&gt;\r\n  &lt;!-- other configuration files.  e.g. --&gt;\r\n  &lt;!--    java -jar start.jar etc\/jetty-logging.xml etc\/jetty.xml --&gt;\r\n  &lt;!-- =============================================================== --&gt;\r\n  &lt;Configure id=\"Server\" class=\"org.mortbay.jetty.Server\"&gt;\r\n\r\n      &lt;New id=\"ServerLog\" class=\"java.io.PrintStream\"&gt;\r\n        &lt;Arg&gt;\r\n          &lt;New class=\"org.mortbay.util.RolloverFileOutputStream\"&gt;\r\n            &lt;Arg&gt;&lt;SystemProperty name=\"jetty.logs\" default=\".\"\/&gt;\/yyyy_mm_dd.stderrout.log&lt;\/Arg&gt;\r\n            &lt;Arg type=\"boolean\"&gt;false&lt;\/Arg&gt;\r\n            &lt;Arg type=\"int\"&gt;90&lt;\/Arg&gt;\r\n            &lt;Arg&gt;&lt;Call class=\"java.util.TimeZone\" name=\"getTimeZone\"&gt;&lt;Arg&gt;GMT&lt;\/Arg&gt;&lt;\/Call&gt;&lt;\/Arg&gt;\r\n            &lt;Get id=\"ServerLogName\" name=\"datedFilename\"\/&gt;\r\n          &lt;\/New&gt;\r\n        &lt;\/Arg&gt;\r\n      &lt;\/New&gt;\r\n\r\n      &lt;Call class=\"org.mortbay.log.Log\" name=\"info\"&gt;&lt;Arg&gt;Redirecting stderr\/stdout to &lt;Ref id=\"ServerLogName\"\/&gt;&lt;\/Arg&gt;&lt;\/Call&gt;\r\n      &lt;Call class=\"java.lang.System\" name=\"setErr\"&gt;&lt;Arg&gt;&lt;Ref id=\"ServerLog\"\/&gt;&lt;\/Arg&gt;&lt;\/Call&gt;\r\n      &lt;Call class=\"java.lang.System\" name=\"setOut\"&gt;&lt;Arg&gt;&lt;Ref id=\"ServerLog\"\/&gt;&lt;\/Arg&gt;&lt;\/Call&gt;&lt;\/Configure&gt;<\/pre>\n<p>Then, create the Solr user and grant it permissions:<\/p>\n<pre>sudo useradd -d \/opt\/solr -s \/sbin\/false solr\r\nsudo chown solr:solr -R \/opt\/solr<\/pre>\n<p><em>Solr is now one directory closer to Jetty than the default configuration shipped with Solr<\/em><\/p>\n<p># sudo nano solr\/solr\/collection1\/conf\/solrconfig.xml<br \/>\n&lt;!&#8211; modify the path as following as we are a directory closer now &#8211;&gt;<br \/>\n&#8230;<br \/>\n&lt;lib dir=&#8221;..\/..\/contrib\/extraction\/lib&#8221; regex=&#8221;.*\\.jar&#8221; \/&gt;<br \/>\n&lt;lib dir=&#8221;..\/..\/dist\/&#8221; regex=&#8221;solr-cell-\\d.*\\.jar&#8221; \/&gt;<\/p>\n<p>&lt;lib dir=&#8221;..\/..\/contrib\/clustering\/lib\/&#8221; regex=&#8221;.*\\.jar&#8221; \/&gt;<br \/>\n&lt;lib dir=&#8221;..\/..\/dist\/&#8221; regex=&#8221;solr-clustering-\\d.*\\.jar&#8221; \/&gt;<\/p>\n<p>&lt;lib dir=&#8221;..\/..\/contrib\/langid\/lib\/&#8221; regex=&#8221;.*\\.jar&#8221; \/&gt;<br \/>\n&lt;lib dir=&#8221;..\/..\/dist\/&#8221; regex=&#8221;solr-langid-\\d.*\\.jar&#8221; \/&gt;<\/p>\n<p>&lt;lib dir=&#8221;..\/..\/contrib\/velocity\/lib&#8221; regex=&#8221;.*\\.jar&#8221; \/&gt;<br \/>\n&lt;lib dir=&#8221;..\/..\/dist\/&#8221; regex=&#8221;solr-velocity-\\d.*\\.jar&#8221; \/&gt;<br \/>\n&#8230;<\/p>\n<p>&lt;!&#8211; &lt;lib dir=&#8221;\/non\/existent\/dir\/yields\/warning&#8221; \/&gt; &#8211;&gt;<br \/>\n<strong>Start Solr<\/strong><\/p>\n<pre># service solr start<\/pre>\n<p><strong>View the Solr admin interface\u00a0 (try also port 8080 jetty)<br \/>\n<\/strong><\/p>\n<pre>http:\/\/solr.example.com:8983\/solr\/\r\n\r\n==============================================<\/pre>\n<h2><strong>Add a core for a Drupal Search API project in a multicore solr server<\/strong><\/h2>\n<pre># mkdir -p \/opt\/solr\/solr\/[corename]\/data<\/pre>\n<p>Copy the search_api_solr config into place<\/p>\n<pre># cp -a \/opt\/search_api_solr\/solr-conf\/4.x\/ \/opt\/solr\/solr\/[corename]\r\n# chown -R solr:solr \/opt\/solr\/solr\/[corename]<\/pre>\n<p>Visit the Solr admin page<\/p>\n<pre>http:\/\/solr.example.com:8983\/solr\/#\/~cores\/[corename]<\/pre>\n<p>If corename = drupal so to connect on a remote Solr server (not locahost), you must remove # in the url solr admin :<\/p>\n<p><a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/connect_solr_remote.jpg\"><img loading=\"lazy\" class=\"aligncenter size-large wp-image-2536\" alt=\"connect_solr_remote\" src=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/connect_solr_remote-1024x66.jpg\" width=\"600\" height=\"38\" srcset=\"https:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/connect_solr_remote-1024x66.jpg 1024w, https:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/connect_solr_remote-300x19.jpg 300w, https:\/\/www.extradrm.com\/wp-content\/uploads\/2015\/01\/connect_solr_remote.jpg 1052w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>The same thing happens with swagger.io to check an API the adding character # in <strong>url\/rest\/#<\/strong> is important to redirect you to the swagger folder API !!!<\/p>\n<p><strong>NOTA : <\/strong>Be aware of removing the symbol # in solr server url when using calls via SolrPhpClient library which causes annoying json validate errors around line 206 in Service.php file.<em><\/em><\/p>\n<p><em><br \/>\n$LWS = new Apache_Solr_Service( &#8216;localhost&#8217;, &#8216;8983&#8217;, &#8216;solr\/collection1&#8217; );<br \/>\nWithout any # in solr\/collection1<\/p>\n<p><\/em><span style=\"text-decoration: underline;\"><strong>Same thing for multicore :<\/strong><em><br \/>\n<\/em><\/span><em>$<\/em><em><em>LWS <\/em><\/em><em>= new Apache_Solr_Service( &#8216;localhost&#8217;, &#8216;8983&#8217;, &#8216;solr\/~cores\/core2\/&#8217; )<\/em><span style=\"text-decoration: underline;\"><em><br \/>\n<\/em><strong>and not<\/strong><em><br \/>\n<\/em><\/span><em>$<\/em><em><em>LWS <\/em><\/em><em>= new Apache_Solr_Service( &#8216;localhost&#8217;, &#8216;8983&#8217;, &#8216;solr\/#\/~cores\/core2\/&#8217; );<\/em><span style=\"text-decoration: underline;\"><em><br \/>\n<\/em><\/span><\/p>\n<h2><strong><br \/>\n<\/strong>Configuring a schema.xml for Solr<\/h2>\n<p>Add your database fields to index :<\/p>\n<p>&lt;field name=&#8221;typeressource&#8221; type=&#8221;string&#8221; indexed=&#8221;true&#8221; stored=&#8221;true&#8221; \/&gt;<br \/>\n&lt;field name=&#8221;titre&#8221; type=&#8221;text_general&#8221; indexed=&#8221;true&#8221; stored=&#8221;true&#8221; multiValued=&#8221;true&#8221;\/&gt;<\/p>\n<p>&nbsp;<\/p>\n<h2><strong>Phrase Query<\/strong><\/h2>\n<p>A phrase query matches multiple terms (words) in sequence.<\/p>\n<p><strong>text:&#8221;yonik seeley&#8221;<\/strong><\/p>\n<p>This query will match text containing Yonik Seeley but will not match Yonik C Seeley or Seeley Yonik.<\/p>\n<p>Internally, a phrase query is created when the fieldType produces multiple terms for the given value. For the example above, the fieldType <strong>splits on whitespace<\/strong> and <strong>lowercases the result<\/strong>, and we get two terms\u2026 [yonik, seeley].<br \/>\nIf our fieldType <strong>had been string<\/strong>, <span style=\"text-decoration: underline;\">a single term of yonik seeley would have been produced<\/span> since string fields do not change values in any way.<\/p>\n<h2><strong>Add a core into a multicore solr server environnement<br \/>\n<\/strong><\/h2>\n<p>1- First, Stop tomcat or jetty service before everything :<\/p>\n<pre>sudo service jetty stop<\/pre>\n<p>2- Copy \/ rename the \/opt\/solr-distribution\/example\/collection1 to an understandable name like <strong>stores <\/strong>for example. ..\u00a0 In that case, you can execute the following command :<\/p>\n<p>* NotaBena :\u00a0 if you installed it using apt-get, this can be skipped by going to cd \/usr\/share\/solr &#8230;<br \/>\n* NotaBene : the collection1 core conf is more complete than the multicore (core0\/core1 samples) so try to get collection1\/conf files by copy .. in this example I suppose that I have collection1 saved from mono instance basic install &#8230;<\/p>\n<pre>cd \/opt\/solr\/solr\r\ncp -R collection1 stores or mv collection1 stores\r\ncd stores<\/pre>\n<p>3- Also, if you installed Solr manually, open the file <strong>core.properties<\/strong> :<\/p>\n<pre>sudo nano core.properties<\/pre>\n<p>and change the core name inside to the same name above (<strong>stores<\/strong>)<\/p>\n<p>4- Then, remove the data directory and change the schema.xml :<br \/>\nNota bene : with this method you can delete a whole index solr instead using curl and delete Rest calls &#8230;<\/p>\n<pre>rm -R data\r\nnano conf\/schema.xml<\/pre>\n<p>5- Paste your own schema.xml in here and think to correct directories if needed according to your installation (example drupal solr search) see above what to modify in solrconfig.xml.\u00a0 There is a very advanced schema.xml in the Solr Repository for monocore collection1. You can probably find a lot more of them on the internet &#8230;<\/p>\n<p>7- Do not forget to make solr owner of the new core :<\/p>\n<pre>sudo chown -R solr:solr \/opt\/solr\/solr\/stores<\/pre>\n<p>8- Add the new core in\u00a0 solr.xml on \/opt\/solr\/solr: (remember this solr.xml is a copy of the multicore file in examples)<\/p>\n<p>&lt;cores adminPath=&#8221;\/admin\/cores&#8221; host=&#8221;${host:}&#8221; hostPort=&#8221;${jetty.port:8983}&#8221; hostContext=&#8221;${hostContext:solr}&#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<strong>&lt;core name=&#8221;stores&#8221; instanceDir=&#8221;stores&#8221; \/&gt;<\/strong><br \/>\n&lt;shardHandlerFactory name=&#8221;shardHandlerFactory&#8221;&gt;<br \/>\n&lt;str name=&#8221;urlScheme&#8221;&gt;${urlScheme:}&lt;\/str&gt;<br \/>\n&lt;\/shardHandlerFactory&gt;<br \/>\n&lt;\/cores&gt;<\/p>\n<p>9- Start Jetty :<\/p>\n<pre>sudo \/etc\/init.d\/jetty start<\/pre>\n<p>When you now visit your Solr instance, you should see the Dashboard with the collection somewhere under cores. think to check logs if there are any errors &#8230;<\/p>\n<h3>JETTY PORTS and as service at boot<\/h3>\n<p>If you want Jetty to start when boot up, execute following code<\/p>\n<pre>update-rc.d jetty defaults<\/pre>\n<p>If you want to change the port Jetty runs on, edit start.ini in $JETTY_HOME and change jetty.port<\/p>\n<pre>sudo nano \/opt\/jetty\/start.ini<\/pre>\n<p>&#8230;<\/p>\n<p>#=============<br \/>\n# HTTP Connector<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n<strong>jetty.port=9090<\/strong><br \/>\nhttp.timeout=30000<br \/>\netc\/jetty-http.xml<\/p>\n<p>&#8230;<\/p>\n<p><strong>&gt;&gt;&gt; Multicore Install<\/strong> : Read this <a href=\"http:\/\/pietervogelaar.nl\/ubuntu-12-04-install-solr-4-with-jetty-9\" target=\"_blank\">link<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>First let me say I love the new UI for the Solr Admin pages (download at Apache Solr). Install Jetty 9 Jetty 9 requires JDK 7, so if you don\u2019t have it installed, install&#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,139,2],"tags":[],"youtube_video":null,"_links":{"self":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/2463"}],"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=2463"}],"version-history":[{"count":0,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/2463\/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=2463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}