Apache Solr is an open-source enterprise search platform built on top of Apache Lucene. It provides a distributed, scalable, and fault-tolerant search engine that enables users to search and index large volumes of data quickly and easily.
In this tutorial, we will show you how to install Apache Solr on Ubuntu 22.04. We will assume that you have already installed Ubuntu 22.04 on your system.
Prerequisites
Before you begin, you will need the following:
- A system running Ubuntu 22.04
- A user with administrative privileges on your system
Installing the Java Runtime Environment
To install Apache Solr on Ubuntu 22.04, you need to install the Java Runtime Environment (JRE) first. Apache Solr is written in Java, and requires a JRE to run.
To install the JRE on Ubuntu 22.04, use the apt package manager to install the openjdk-11-jre-headless package:
sudo apt update
sudo apt install openjdk-11-jre-headless
This will install the JRE on your system.
To verify the installation, you can run the following command:
java -version
This will print the version of the installed JRE.
Installing Apache Solr
After installing the JRE, you can install Apache Solr on Ubuntu 22.04.
To install Apache Solr, download the latest version of Apache Solr from the Apache Solr website using the wget command:
wget <https://downloads.apache.org/lucene/solr/8.7.0/solr-8.7.0.tgz>
This will download the Apache Solr package to your system.
Then, extract the downloaded package using the tar command:
tar xzf solr-8.7.0.tgz
This will extract the Apache Solr package to the solr-8.7.0 directory.
Next, move the extracted directory to the /opt directory:
sudo mv solr-8.7.0 /opt/solr
This will move the Apache Solr package to the /opt/solr directory.
To make the Apache Solr command-line tools available in your PATH, create a symbolic link to the /opt/solr/bin/solr script in the /usr/local/bin directory:
sudo ln -s /opt/solr/bin/solr /usr/local/bin/solr
This will create a symbolic link to the solr script in the /usr/local/bin directory.
Starting Apache Solr
After installing Apache Solr, you need to start the Apache Solr service to make the search engine available.
To start Apache Solr, use the solr command with the start option:
solr start
This will start the Apache Solr service, and the search engine will be ready to accept connections.
To verify that the Apache Solr service is running, you can use the solr command with the status option:
solr status
This will print the status of the Apache Solr service, including the port number that the service is listening on.
Creating a Solr Core
After starting Apache Solr, you need to create a Solr core to store and index your data. A Solr core is a logical index that contains the data and configuration for a search index.
To create a Solr core, use the solr command with the create option and the -c option, followed by the name of the Solr core:
solr create -c MY_CORE
Replace MY_CORE with the name of the Solr core that you want to create.
This will create a new Solr core with the specified name, and the core will be ready to accept data.
To verify that the Solr core was created successfully, you can use the solr command with the list option:
solr list
This will print a list of the Solr cores that are available on the Apache Solr server. The Solr core that you created earlier should be in the list.
Adding Data to the Solr Core
After creating a Solr core, you can add data to the core using the solr command.
To add data to the Solr core, use the solr command with the import option and the -c option, followed by the name of the Solr core, and the -d option, followed by the data directory containing the data that you want to import:
solr import -c MY_CORE -d /path/to/data
This will import the data from the specified data directory into the Solr core.
To verify that the data was imported successfully, you can use the solr command with the browse option and the -c option, followed by the name of the Solr core:
solr browse -c MY_CORE
This will open the Solr web interface, where you can browse the data that was imported into the Solr core.
Conclusion
In this tutorial, you learned how to install Apache Solr on Ubuntu 22.04. You learned how to install the Java Runtime Environment, install Apache Solr, start the Apache Solr service, create a Solr core, and add data to the Solr core.
With Apache Solr, you can create a scalable, distributed, and fault-tolerant search engine that allows users to search and index large volumes of data quickly and easily.