Apache Solr, an enterprise-grade search platform based on the Apache Lucene library, is a powerful and popular tool used by major internet companies like Adobe, Netflix, and Instagram. It offers high availability, scalability, and fault tolerance, making it an excellent choice for building enterprise applications. In this comprehensive guide, we will walk you through the process of installing Apache Solr on an AlmaLinux 9 server, optimizing its performance, securing it with basic authentication, and creating your first Solr index.
Prerequisites
Before we begin, make sure you have the following:
- An AlmaLinux 9 server with at least 2/4 GB of memory (we recommend 8 GB for optimal performance).
- A non-root user with sudo/root administrator privileges.
Installing Java OpenJDK 11
To run Apache Solr, we need to install Java OpenJDK 11. Follow these steps:
- Update your system’s package list:
sudo dnf update
- Install Java OpenJDK 11:
sudo dnf install java-11-openjdk java-11-openjdk-devel
- Verify the Java version:
java --version
You should see the Java OpenJDK 11 version installed.
Installing Apache Solr
Once you have Java OpenJDK 11 installed, you can proceed with the Apache Solr installation:
- Install the required packages:
sudo dnf install curl lsof chkconfig -y
- Download the Apache Solr binary package (version 9.2.1):
curl -so https://downloads.apache.org/solr/solr/9.2.1/solr-9.2.1.tgz
- Extract the installer script:
tar xzf solr-9.2.1.tgz solr-9.2.1/bin/install_solr_service.sh --strip-components=2
- Install Apache Solr:
sudo bash ./install_solr_service.sh solr-9.2.1.tgz
- Stop the current Apache Solr process:
sudo service solr stop
- Start the Apache Solr service:
sudo service solr start
- Verify the Apache Solr service:
sudo service solr status
If Apache Solr is running, you should see a similar output confirming its status.
Optimizing Apache Solr Installation
To optimize the performance of Apache Solr, you can configure its max heap memory and internal IP address. Follow these steps:
- Increase
shmmax
andnr_hugepages
values:
sudo echo 4294967295 > /proc/sys/kernel/shmmax sudo echo 1536 > /proc/sys/vm/nr_hugepages
- Open the
solr.in.sh
file:
sudo nano /etc/default/solr.in.sh
- Uncomment the
SOLR_HEAP
parameter and set the desired max heap memory (e.g., 4g):
SOLR_HEAP="4g"
- Uncomment the
SOLR_JETTY_HOST
andSOLR_HOST
parameters and set your internal IP address:
SOLR_HOST="<INTERNAL_IP_ADDRESS>" SOLR_JETTY_HOST="<INTERNAL_IP_ADDRESS>"
- Save the changes and exit the editor.
- Restart the Apache Solr service:
sudo service solr restart
- Verify the Apache Solr status:
sudo service solr status
Setting Up Ulimits and Firewalld
To ensure Apache Solr runs smoothly, you need to configure max processes and max open files and open the necessary port on firewalld. Follow these steps:
- Open the
limits.conf
file:
sudo nano /etc/security/limits.conf
- Add the following configuration at the end of the file:
solr soft nofile 65000 solr hard nofile 65000 solr soft nproc 65000 solr hard nproc 65000
- Save the file and exit the editor.
- Check the max processes and max open files:
sudo -H -u solr bash -c "ulimit -aH"
Make sure both settings show a value of 65,000.
- Restart the Apache Solr service:
sudo service solr restart
- Open port 8983 on firewalld:
sudo firewall-cmd --add-port=8983/tcp --permanent
- Reload firewalld to apply the changes and verify the rules:
sudo firewall-cmd --reload sudo firewall-cmd --list-all
You should see port 8983 listed in the firewalld rules.
Securing Apache Solr with Basic Authentication
By default, Apache Solr is installed without authentication, which can be a security risk. To secure it, we will enable basic authentication. Follow these steps:
- Create a security.json file:
sudo nano /var/solr/data/security.json
- Insert the following configuration to create a new user with the desired username and password:
{ "authentication":{ "blockUnknown": true, "class":"solr.BasicAuthPlugin", "credentials":{"solr":"IV0EHq1OnNrj6gvRCwvFwTrZ1+z1oBbnQdiVC3otuq0= Ndd7LKvVBAaZIF0QAVi1ekCfAJXr1GGfLtRUXhgrF8c="}, "realm":"My Solr users", "forwardCredentials": false }, "authorization":{ "class":"solr.RuleBasedAuthorizationPlugin", "permissions":[{"name":"all", "role":"admin"}], "user-role":{"solr":"admin"} } }
- Save the file and exit the editor.
- Restart the Apache Solr service:
sudo service solr restart
- Refresh the Apache Solr administration dashboard in your web browser.
- You should now see a login page. Enter the username and password you set in the security.json file.
- Once authenticated, you can access the Apache Solr dashboard.
Creating Your First Solr Index
With Apache Solr installed and secured, you can now create your first Solr index. Follow these steps:
- Open the
solr.in.sh
file:
sudo nano /etc/default/solr.in.sh
- Uncomment the
SOLR_AUTH_TYPE
andSOLR_AUTHENTICATION_OPTS
parameters. - Save the file and exit the editor.
- Restart the Apache Solr service:
sudo service solr restart
- Create a new Solr index:
su- solr -c "/opt/solr/bin/solr create -c test1_core -n Test1Core"
- Verify the creation of the new Solr index in the Apache Solr administration dashboard.
Congratulations! You have successfully installed Apache Solr on your AlmaLinux 9 server, optimized its performance, secured it with basic authentication, and created your first Solr index. Apache Solr is now ready to be used for powerful search capabilities in your enterprise applications.
For reliable and scalable cloud hosting solutions, consider Shape.host’s Linux SSD VPS services. Shape.host offers top-notch hosting services, empowering businesses with efficient, scalable, and secure solutions. Visit Shape.host for more information.