Technology

Apache Solr 5.0 Install on Centos 7

March 30, 2015

Solr5.0 has been recently released with several new features. One of these is a service install to use with Redhat based Linux systems.  This install will walk you through an install and create two example cores to test with.

Many of the Solr install instructions include the installation of Tomcat.  This is not required. Solr 5.0 will run with the base OpenJDK. The server also does not need the Apache web server.

These instructions assume you are using a login other than Root. If you are using the Root login, you can skip the use of “sudo”.

Install Java

Check and see if you have java installed, by issuing the java version command:

java -version

If you do not have java installed, use the following command to install java:

sudo yum install java-1.7.0-openjdk-devel

After installing java, you will need to define your JAVA_HOME environmental variables. Go to the /usr/lib/jvm directory and find your jdk file. You will need to update the file name to use the command below:

export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75-2.5.4.2.el7_0.x86_64

You can validate if the command was successful, by entering the following command:

echo $JAVA_HOME

To make the JAVA_HOME variable a permanent value, you will need to edit the system profile file with the export command used above. Use vi, nano or your favorite editor and edit /etc/profile. Place the export JAVA_HOME=/… command from above as the last line and save it.

sudo vi /etc/profile
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75-2.5.4.2.el7_0.x86_64

Reboot your system and validate the java version and JAVA_HOME is correctly setup.

Install Solr 5

We will now download and setup the SOLR install. The four commands below will need to be entered one at a time. This will download and untar the SOLR install files. Go to the SOLR5 Download Page to determine the exact http address to use for the wget command.

cd /tmp
wget http://apache.cs.utah.edu/lucene/solr/5.0.0/solr-5.0.0.tgz
tar -zxvf solr-5.0.0.tgz

We are now ready to install SOLR. Use the following command to install the Centos service for Solr. Update the command with the file name you downloaded in the above wget command (My download was solr-5.0.0.tgz. (The command follows the following format:  sudo bin/install_solr_service.sh <path-to-solr-5.0.0.tgz>)

cd solr-5.0.0
sudo bin/install_solr_service.sh /tmp/solr-5.0.0.tgz

You will see the following upon successful completion:

id: solr: no such user
Creating new user: solr
Extracting /tmp/solr-5.0.0.tgz to /opt
Creating /etc/init.d/solr script ...

Started Solr server on port 8983 (pid=). Happy searching!

Found 1 Solr nodes:

Solr process 2196 running on port 8983
{
  "solr_home":"/var/solr/data/",
  "version":"5.0.0 1659987 - anshumgupta - 2015-02-15 12:26:10",
  "startTime":"2015-03-30T03:44:01.64Z",
  "uptime":"0 days, 0 hours, 0 minutes, 6 seconds",
  "memory":"25.3 MB (%5.2) of 490.7 MB"}

Service solr installed.

The Solr service is installed and running. This install will place all the code at /opt/solr and all your data for your cores will be stored at /var/solr.
Installation defaults / options:

  • The installation directory defaults to /opt/solr, and is configurable with the ‘-i’-option
  • The data directory defaults to /var/solr, and is configurable with the ‘-d’-option.
  • The port defaults to 8983 (configuration option ‘-p’)

Notes:

  • The script wil install Solr5 as a service, so that you can easily use sudo service solr start, sudo service solr stop etc.
  • The script also creates a ‘solr’-user and -group which are used to run the server.

If you have activated the Centos firewall, you will need to open up the Port 8983 to see the admin screen. If you have not enabled the firewall, then you can skip these commands:

sudo firewall-cmd --zone = public --add-port = 8983 / tcp --permanent
sudo firewall-cmd --reload

You can now go to the Solr admin panel at http://localhost:8983/solr/.

Solr is now installed, but does not have any data. We will now create a couple of cores to allow you to start using SOLR.

Create Solr Core and Load Sample Documents

First we need to set the solr user as owner of the data directory.

sudo chown -R solr:solr /var/solr/
sudo chown -R solr:solr /var/solr

We will now create the first core called devel1. We will also load all of the Solr documentation into the core.

cd /opt/solr
sudo bin/solr create -c documents
sudo bin/post -c documents docs/

Lets create the second core and load the sample xml documents.

cd /opt/solr
sudo bin/solr create -c gettingstarted
bin/post -c gettingstarted example/exampledocs/*.xml

You know have two different cores to work with. You can follow the examples for loading different document types and searching at the SOLR QuickStart Guide.

Start Solr, Stop Solr and Restart Solr

One of the advantages of running Solr as a service is the ability to easily start, stop and restart Solr. The commands for this are below:

sudo service solr restart
sudo service solr stop
sudo service solr start

I hope this helps with your installation of Solr 5 on Centos 7.

There is one known issue with Solr and it will begin to throw critical errors because there are three files missing from the create core command. The system is looking for:

admin-extra.html
admin-extra.menu-bottom.html
admin-extra.menu-top.html

You will need to go to each of the core directories and create these files to remove the errors.

cd /var/solr/data/<core name>/conf/

Once you are in the conf directory for the core, create the files with the following command:

touch admin-extra.html
touch admin-extra.menu-bottom.html
touch admin-extra.menu-top.html

This will remove the errors.

You Might Also Like

3 Comments

  • Reply Anthony December 4, 2015 at 7:41 pm

    sudo firewall-cmd –zone = public –add-port = 8983 / tcp –permanent

    This line was slightly off.
    Should be at least for me was this:

    sudo firewall-cmd –zone=public –add-port=8983/tcp –permanent

  • Reply lux June 9, 2016 at 10:38 am

    Thanx for this !

  • Reply David S July 19, 2016 at 4:37 pm

    Very helpful, thank you. A couple of observations:
    1. With SOLR 6 it appears to be necessary to run the create and post commands as the solr user or permissions problems will occur as detailed in https://issues.apache.org/jira/browse/SOLR-7826 I think.
    “. It may also be necessary to include the port number in the post command if you don’t use the standard port e.g. add -p 8080 to the end of the post command.

  • Leave a Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.