Skip to content

Instantly share code, notes, and snippets.

@fpiraneo
Last active June 10, 2024 20:03
Show Gist options
  • Save fpiraneo/be58188a68f5ccc5cc2c86dbaf899c68 to your computer and use it in GitHub Desktop.
Save fpiraneo/be58188a68f5ccc5cc2c86dbaf899c68 to your computer and use it in GitHub Desktop.
Install and Configure Apache Solr on AlmaLinux 9

Install and Configure Apache Solr on AlmaLinux 9

Despite the solr official website reports a lot of documentation, it appears incomplete and out of date, for sure not applicable to current solr version (9.6 at the time I'm writing); moreover solr installation procedure (see below) appears to be unable to install correctly on RHEL 9 based distros like AlmaLinux.

These notes to document my journey in solr installation and experimentation getting it up and running.

Warning

The usual disclaimer: I'm not a solr pro, I'm learning; if somebody has more efficient way to do things pls let me know and I'll be glad to update these docs accodingly.

Test bench

All below has been tested under a virtual qemu host run on ProxMox rel. 8.2.2.

Guest OS is AlmaLinux 9.4 bare installation, no GUI.

Tip

Once installed a new AlmaLinux host host don't forget to proceed for a full update with latest patches.

Java

solr require Java to run. We will install epel-release repo first then java.

# dnf install epel-release -y

# dnf install java

To check for correct java installation:

# java -version
openjdk version "11.0.23" 2024-04-16 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.23.0.9-2) (build 11.0.23+9-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.23.0.9-2) (build 11.0.23+9-LTS, mixed mode, sharing)

Downloading solr

solr can be downloaded with wget from the official website.

Tip

Don't forget to install wget, tar and lsof that are not part of the basic AlmaLinux installation!

# dnf install -y wget tar lsof

Download solr on your working directory you feel appropriate.

# wget https://archive.apache.org/dist/solr/solr/9.6.1/solr-9.6.1.tgz

Extract and install

Extract solr on the working directory:

# tar -xzf solr-9.6.1.tgz

Install solr invoking the installation script:

solr-*/bin/install_solr_service.sh solr-9.6.1.tgz

Here begins the pain:

# solr-9.6.1/bin/install_solr_service.sh solr-9.6.1.tgz 
We recommend installing the 'lsof' command for more stable start/stop of Solr
id: ‘solr’: no such user
Creating new user: solr

Extracting solr-9.6.1.tgz to /opt

Installing symlink /opt/solr -> /opt/solr-9.6.1 ...
Installing /etc/init.d/solr script ...

cp: cannot create regular file '/etc/init.d/solr': No such file or directory
chmod: cannot access '/etc/init.d/solr': No such file or directory
chown: cannot access '/etc/init.d/solr': No such file or directory
sed: can't read /etc/init.d/solr: No such file or directory

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

solr-9.6.1/bin/install_solr_service.sh: line 340: chkconfig: command not found
Service solr installed.
Customize Solr startup configuration in /etc/default/solr.in.sh
Redirecting to /bin/systemctl start solr.service
Failed to start solr.service: Unit solr.service not found.
Redirecting to /bin/systemctl status solr.service
Unit solr.service could not be found.

solr doesn't support systemd so we have to create a systemd script to automatically start solr as a service.

solr and systemd

Under /etc/systemd/system create the file solr.service with the following content:

[Unit]
Description=Apache SOLR
After=syslog.target network.target remote-fs.target nss-lookup.target systemd-journald-dev-log.socket
Before=multi-user.target graphical.target nginx.service
Conflicts=shutdown.target

[Service]
User=solr
PIDFile=/data/solr-8983.pid
Environment=SOLR_INCLUDE=/etc/default/solr.in.sh
ExecStart=/opt/solr/bin/solr start
ExecStop=/opt/solr/bin/solr stop
Restart=on-failure
LimitNOFILE=65000
LimitNPROC=65000
TimeoutSec=180s

[Install]
WantedBy=multi-user.target graphical.target

This setup assume that solr has been installed under /opt and the PID file is under /data.

Enable solr to start automatically as a daemon and start it:

# systemctl enable solr
Created symlink /etc/systemd/system/multi-user.target.wants/solr.service → /etc/systemd/system/solr.service.
Created symlink /etc/systemd/system/graphical.target.wants/solr.service → /etc/systemd/system/solr.service.

# systemctl start solr

# systemctl status solr
● solr.service - Apache SOLR
     Loaded: loaded (/etc/systemd/system/solr.service; enabled; preset: disabled)
     Active: deactivating (stop) since Mon 2024-06-10 17:43:34 CEST; 3s ago
    Process: 1575 ExecStart=/opt/solr/bin/solr start (code=exited, status=0/SUCCESS)
   Main PID: 1575 (code=exited, status=0/SUCCESS); Control PID: 1686 (bash)
      Tasks: 48 (limit: 17540)
     Memory: 696.5M
        CPU: 12.222s
     CGroup: /system.slice/solr.service
             ├─1624 java -server -Xms512m -Xmx512m -XX:+UseG1GC -XX:+PerfDisableSharedMem -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=250 >
             ├─1686 bash /opt/solr/bin/solr stop
             ├─1744 bash /opt/solr/bin/solr stop
             ├─1772 sleep 2
             └─1779 sleep 0.5

Jun 10 17:43:31 bibliothekairos-test-01 systemd[1]: Started Apache SOLR.
Jun 10 17:43:33 bibliothekairos-test-01 solr[1575]: [110B blob data]
Jun 10 17:43:33 bibliothekairos-test-01 solr[1634]: Started Solr server on port 8983 (pid=1624). Happy searching!
Jun 10 17:43:34 bibliothekairos-test-01 solr[1575]: [14B blob data]
Jun 10 17:43:34 bibliothekairos-test-01 solr[1686]: Sending stop command to Solr running on port 8983 ... waiting up to 180 seconds to allow Je>
lines 1-20/20 (END)

solr run correctly.

Accessing administration console from a different host

solr is configured to listen only on localhost (127.0.0.1); to allow connection from every host, solr must listen on ETH port.

  • Locate your IP address:
# nmcli
ens18: connected to ens18
        "Red Hat Virtio"
        ethernet (virtio_net), BC:24:11:B5:FC:E2, hw, mtu 1500
        ip4 default
        inet4 192.168.1.120/24
        route4 192.168.1.0/24 metric 100
        route4 default via 192.168.1.254 metric 100

lo: connected (externally) to lo
        "lo"
        loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536
        inet4 127.0.0.1/8
        inet6 ::1/128
        route6 ::1/128 metric 256

DNS configuration:
        servers: 192.168.1.254
        interface: ens18

In this case the IP address is 192.168.1.120;

  • Edit file /etc/default/solr.in.sh;
  • Locate parameter #SOLR_JETTY_HOST="127.0.0.1";
  • Uncomment the line and change with the ip address to be bound: SOLR_JETTY_HOST="192.168.1.120";
  • Reboot the host;

Note

A simple restart of solr doesn't worked for me.

Sources:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment