How to install the latest Apache Solr version on Linux server?

Updated Jul 28, 2020・4 minute read Post By Server Enthusiast
How to install the latest Apache Solr version on Linux server?

Introduction

Apache Solr is a highly reliable and scalable indexing technology. Solr can be used to create standard search apps. It is written in Java and uses the Lucene library for indexing.

In this tutorial, you will learn how to install the latest version of Solr a Linux server. We will be using the Solr convenience installation script to achieve that. The great thing about the Solr convenience installation script is that it detects the OS and you can use it on all major Linux distributions.

Prerequisites

Before you get started you would need a Linux server with sudo or root access.

I would recommend using DigitalOcean if you do not have an account you can use the following link to get a $100 free credit and spin up your own servers in seconds:

DigitalOcean $100 Free Credit

Choosing Solr version

As of the time of writing this tutorial the latest Solr version available is Solr 8.6.0.

So the download link for Solr 8.6.0 would be:

https://archive.apache.org/dist/lucene/solr/8.6.0/solr-8.6.0.tgz

However, make sure to visit the following link and choose a different or newer version if you need to:

https://archive.apache.org/dist/lucene/solr/

Installing Java

In order to be able to run Solr, we would need to have Java installed.

If you are on an Ubuntu server you could install java by running the following command:

sudo apt install default-jre

If you are using CentOS or RedHat, you need to run the following command:

sudo yum install java-11-openjdk

To test if the installation was successful just run:

java -version

Installing lsof

In order for Solr to work as expected, you would need to have the lsof command installed as well.

The lsof command stands for "list open files". It is widely used in many Unix-like systems. It provides a report of a list of all open files and the processes that opened them. It is a great command for troubleshooting various system problems.

If you do not have it, you can install it by running the following command:

  • For Ubuntu:
sudo apt install lsof
  • For CentOS
sudo yum install lsof

Installing Solr

Once we have the prerequisites ready, we can proceed with the actual Solr installation.

Downloading the Solr installation files

First, go to the /usr/src directory where we will do the actual installation:

cd /usr/src

Then download the installation files by using the following command:

wget https://archive.apache.org/dist/lucene/solr/8.6.0/solr-8.6.0.tgz

As mentioned above, make sure to use the exact version that you need, you can get the link from here.

Finally extract the files:

tar -xzvf solr-8.6.0.tgz

Running the Solr installation script

Once we have the files downloaded, all that we need to do is cd into the Solr bin folder and run the cool installation script that Solr comes with:

cd solr-8.6.0/bin

Then to execute the script, just run:

./install_solr_service.sh ../../solr-8.6.0.tgz

You will get the following output:

id: ‘solr’: no such user
Creating new user: solr
Adding system user `solr' (UID 113) ...
Adding new group `solr' (GID 119) ...
Adding new user `solr' (UID 113) with group `solr' ...
Creating home directory `/var/solr' ...

Extracting ../../solr-8.6.0.tgz to /opt


Installing symlink /opt/solr -> /opt/solr-8.6.0 ...


Installing /etc/init.d/solr script ...


Installing /etc/default/solr.in.sh ...

Service solr installed.
Customize Solr startup configuration in /etc/default/solr.in.sh
? solr.service - LSB: Controls Apache Solr as a Service
   Loaded: loaded (/etc/init.d/solr; generated)
   Active: active (exited) since Sun 2020-07-26 17:13:36 UTC; 5s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 18771 ExecStart=/etc/init.d/solr start (code=exited, status=0/SUCCESS)

The Solr installation script does a few things:

  • It first adds a new system user called solr
  • Then it adds the Solr files to /opt/solr-8.6.0 and creates a symlink for /opt/solr
  • It also prepares the system scripts for starting and stopping the services.

After Solr has been installed you could manage it as any other service with the following commands:

sudo service solr stop
sudo service solr start
sudo service solr status

Creating Solr Collection

As a test you could create a new Solr collection with the following command:

sudo su - solr -c "/opt/solr/bin/solr create -c your_collection -n data_driven_schema_configs"

Output:

Created new core 'your_collection'

Installing Solr MySQL connector

In some cases, you might need to install the MySQL connector. To do so, you can run the following steps.

In order to get the link for the downloading the platform MySQL connector, visit the official download page provided by MySQL:

https://dev.mysql.com/downloads/connector/j/

From the drop-down menu choose your exact OS, I would go for the Platform-independent one.

The link would look like something like this depending on the latest version:

https://cdn.mysql.com//Downloads/Connector-J/mysql-connector-java-8.0.21.tar.gz

Again using the wget command download the file:

cd /opt

wget https://cdn.mysql.com//Downloads/Connector-J/mysql-connector-java-8.0.21.tar.gz

Then extract the files:

sudo tar -xzvf mysql-connector-java-8.0.21.tar.gz

And finally, create a symlink for the MySQL connector to the Solr dist directory:

ln -s /opt/mysql-connector-java/mysql-connector-java-8.0.21-bin.jar /opt/solr/dist/mysql-connector-java.jar

Finally restart Solr and make sure that it starts:

sudo sudo service solr stop
sudo service solr start
sudo service solr status

Accessing Solr Admin Panel

In order to access the Solr admin panel just visit your hostname or IP address on port 8983:

http://your_ip_address:8983/solr/

Once there if you go to Core Admin on the left, you will be able to see the collection that you created in the previous step.

Conclusion

This is pretty much it, now you have installed the latest Solr version at the /opt/solr directory.

As a good practice, I would suggest locking the Solr port via your firewall so that only you could access it directly.

You could use the /etc/default/solr.in.sh config file and allow access to the Solr instance only from your IP range.

Hope that this helps!

© 2020 DevDojo LLC. All rights reserved.