{"id":3529,"date":"2016-03-30T02:17:27","date_gmt":"2016-03-30T02:17:27","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=3529"},"modified":"2016-03-30T02:17:27","modified_gmt":"2016-03-30T02:17:27","slug":"install-solr-ubuntu","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/install-solr-ubuntu\/","title":{"rendered":"Install Solr on Ubuntu"},"content":{"rendered":"<p>First, you need a JDK.<\/p>\n<p>I ran this:<\/p>\n<pre lang=\"bash\">\napt-get install openjdk-7-jdk\n<\/pre>\n<p>You can also use the Oracle JDK, but it requires signing an additional license. It also seems to involve a more convoluted installation (they make JAVA_HOME point to a symlink to the JDK, which changes as you upgrade).<\/p>\n<p>For me, this JDK was installed here (you may want to note this):<br \/>\n\/usr\/lib\/jvm\/java-7-openjdk-i386\/<\/p>\n<p>Before running the solr installation steps, go to the Solr download page, and find the current version.<\/p>\n<pre lang=\"bash\">\nsudo su root\ncd ~\nwget http:\/\/apache.arvixe.com\/lucene\/solr\/5.5.0\/solr-5.5.0.tgz\ntar xzf solr-5.5.0.tgz solr-5.5.0\/bin\/install_solr_service.sh --strip-components=2\nsudo chmod +x install_solr_service.sh\nsudo .\/install_solr_service.sh solr-5.5.0.tgz\n<\/pre>\n<p>To run solr, you should then be able to run this:<\/p>\n<pre lang=\"bash\">\nservice solr start\n<\/pre>\n<p>However, this may not work at first.<\/p>\n<p>If you get an error that it can&#8217;t find the JDK:<\/p>\n<pre lang=\"bash\">\nThe currently defined JAVA_HOME (\/usr\/lib\/jvm\/java-8-oracle) refers\nto a location where Java could not be found.  Aborting.\nEither fix the JAVA_HOME variable or remove it from the\nenvironment so that the system PATH will be searched.\n<\/pre>\n<p>If this happens, do:<\/p>\n<pre lang=\"bash\">\nvi \/etc\/default\/solr.in.sh\n<\/pre>\n<p>And add this line (using the path you saved above):<\/p>\n<pre lang=\"bash\"> \nSOLR_JAVA_HOME=\"\/usr\/lib\/jvm\/java-7-openjdk-i386\"\n<\/pre>\n<p>If you get a permissions denied error on \/dev\/null:<\/p>\n<pre lang=\"bash\">\n\/opt\/solr\/bin\/solr: line 120: \/dev\/null: Permission denied\nJava not found, or an error was encountered when running java.\nA working Java 7 or later is required to run Solr!\nPlease install Java or fix JAVA_HOME before running this script.\nCommand that we tried: '\/usr\/lib\/jvm\/java-7-openjdk-i386\/bin\/java -version'\nActive Path:\n\/usr\/local\/bin:\/usr\/bin:\/bin:\/usr\/local\/games:\/usr\/games:\/usr\/lib\/jvm\/java-8-oracle\/bin:\/usr\/lib\/jvm\/java-8-oracle\/db\/bin:\/usr\/lib\/jvm\/java-8-oracle\/jre\/bin\n<\/pre>\n<p>This indicates that \/dev\/null is a file, rather than a device. Run this:<\/p>\n<pre lang=\"bash\">\nrm \/dev\/null\nmknod \/dev\/null c 1 3\nchmod 666 \/dev\/null\n<\/pre>\n<p>Once you do this, solr should work.<\/p>\n<p>However, you then should consider disabling external access, since the UI has no security.<\/p>\n<p>The best way to do this is with firewall rules, since this blocks network traffic (make sure you take a snapshot of your virtual machine before you tinker with iptables, because you can lock yourself out)<\/p>\n<pre lang=\"bash\">\nsudo iptables -A INPUT -p tcp -s localhost --dport 8983 -j ACCEPT\nsudo iptables -A INPUT -p tcp --dport 8983 -j DROP\n<\/pre>\n<p>If the above causes you a problem, you can still get out by rebooting.<\/p>\n<p>This makes it permanent:<\/p>\n<pre lang=\"bash\">\n\/sbin\/iptables-save\n<\/pre>\n<p>Another option is to <a href=\"http:\/\/stackoverflow.com\/questions\/8924102\/restricting-ip-addresses-for-jetty-and-solr\">limit access to your IP address, <\/a> although if your IP changes frequently this is not ideal, and it risks you losing the setting if you upgrade.<\/p>\n<p>Alternately, since Solr by default runs on Jetty, you can restrict access to only the loopback address<sup><a href=\"#footnote_0_3529\" id=\"identifier_0_3529\" class=\"footnote-link footnote-identifier-link\" title=\"http:\/\/stackoverflow.com\/questions\/1955455\/how-to-secure-jetty-to-only-allow-access-from-loopbacklocalhost\">1<\/a><\/sup>. The disadvantage of doing this through Jetty is that it assumes you trust Solr not to open more ports without your awareness.<\/p>\n<p>If you go the firewall route, a handy option is SSH port forwarding, which will allow you to access the solr UI when you SSH into the box. <\/p>\n<p>If you use Putty this means adding \u201c-L 8983:localhost:8983\u201d to the command line arguments. Once you connect this way, you can use \u201chttp:\/\/localhost:8983\/solr\/#\/\u201d to connect to the Solr admin panel.<\/p>\n<p><b>Logging<\/b><br \/>\nYou may also want to check the log settings. By default log rotation appears to be enabled correctly, although the file size is a bit small:<\/p>\n<p>File: \/opt\/solr\/server\/resources\/log4j.properties<\/p>\n<pre>\nlog4j.appender.file=org.apache.log4j.RollingFileAppender\nlog4j.appender.file.MaxFileSize=4MB\nlog4j.appender.file.MaxBackupIndex=9\n<\/pre>\n<ol class=\"footnotes\"><li id=\"footnote_0_3529\" class=\"footnote\">http:\/\/stackoverflow.com\/questions\/1955455\/how-to-secure-jetty-to-only-allow-access-from-loopbacklocalhost<span class=\"footnote-back-link-wrapper\"> [<a href=\"#identifier_0_3529\" class=\"footnote-link footnote-back-link\">&#8617;<\/a>]<\/span><\/li><\/ol>","protected":false},"excerpt":{"rendered":"<p>Guide for installing solr on Ubuntu<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[12],"tags":[300,517,559],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3529"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=3529"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3529\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=3529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=3529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=3529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}