Skip to content

Install and configure Apache Solr

Install Apache Solr on Ubuntu via the vendor service script, run in SolrCloud mode behind ZooKeeper, create a collection, and verify health from the admin UI and CLI.

Apache Solr is the long-running Lucene search server — older than Elasticsearch, still actively developed, and the engine behind many enterprise catalogs and library systems. This article installs Solr 9.x on Ubuntu via the vendor install_solr_service.sh script, configures a SolrCloud-mode collection backed by ZooKeeper, and verifies cluster health. Audience is operators bringing up Solr for a new deployment or a Lucene-shaped workload where Solr’s mature schema API is the right fit.

How to verify

After install, confirm the service runs and Solr responds:

systemctl status solr
journalctl -u solr -n 50 --no-pager
ss -tlnp | grep 8983
curl -s 'http://127.0.0.1:8983/solr/admin/info/system?wt=json' | jq .lucene
sudo -u solr /opt/solr/bin/solr status
sudo -u solr /opt/solr/bin/solr healthcheck -c products

Healthy output shows Solr running, the Lucene version, and the running collections.

What’s happening

Solr is a Java/Lucene application packaged as a self-contained service with its own embedded Jetty. Two operating modes matter:

  • Standalone (single-core) — one Solr instance, one or more cores. Simple, no coordination overhead, fine for low-scale or read-only use.
  • SolrCloud — multiple Solr nodes coordinate through Apache ZooKeeper. Collections are sharded and replicated, leader election is automatic. This is the production shape.

A SolrCloud “collection” is the logical index split into “shards” (each shard has one leader replica plus followers). ZooKeeper holds the cluster state, configuration sets (configsets), and leader election. You can run a single-node ZooKeeper for dev, but production uses an odd-number ensemble (3 or 5 nodes).

The schema API has two flavors: schemaless mode (Solr guesses field types on first ingest, drops <field> definitions into the managed schema) and classic mode (you declare every field). Operators usually pin to classic for predictability.

The procedure

1. Install Java 17 and download the installer script:

sudo apt update
sudo apt install -y openjdk-17-jre-headless wget lsof
SOLR_VER=9.6.1
wget "https://dlcdn.apache.org/solr/solr/${SOLR_VER}/solr-${SOLR_VER}.tgz" -O /tmp/solr.tgz
tar -xzf /tmp/solr.tgz solr-${SOLR_VER}/bin/install_solr_service.sh --strip-components=2
sudo bash install_solr_service.sh /tmp/solr.tgz -i /opt -d /var/solr -u solr -s solr -p 8983

The script creates the solr user, lays out /opt/solr (binaries) and /var/solr (data + logs), installs the systemd unit and starts Solr.

2. Tune the heap. Edit /etc/default/solr.in.sh:

SOLR_HEAP="2g"
SOLR_JAVA_MEM="-Xms2g -Xmx2g"
SOLR_OPTS="$SOLR_OPTS -Dsolr.disable.allowUrls=false"
GC_TUNE="-XX:+UseG1GC -XX:MaxGCPauseMillis=250"

Restart:

sudo systemctl restart solr

3. Bring up SolrCloud. For a single-node dev cloud (ZooKeeper embedded), stop standalone Solr then start in cloud mode:

sudo systemctl stop solr
sudo -u solr /opt/solr/bin/solr start -c -p 8983 -m 2g

For production, run an external ZooKeeper ensemble (3 nodes minimum) and point Solr at it:

# in /etc/default/solr.in.sh
ZK_HOST="zk1:2181,zk2:2181,zk3:2181/solr"

4. Upload a configset and create a collection:

sudo -u solr /opt/solr/bin/solr zk upconfig \
  -n products_cfg \
  -d /opt/solr/server/solr/configsets/_default
sudo -u solr /opt/solr/bin/solr create -c products \
  -n products_cfg -shards 2 -replicationFactor 2

5. Define fields and ingest:

curl -s -X POST 'http://127.0.0.1:8983/solr/products/schema' \
  -H 'Content-Type: application/json' \
  -d '{
    "add-field": [
      {"name":"name",     "type":"text_general", "indexed":true, "stored":true},
      {"name":"brand",    "type":"string",       "indexed":true, "stored":true, "docValues":true},
      {"name":"price_d",  "type":"pdouble",      "indexed":true, "stored":true, "docValues":true}
    ]
  }'

curl -s -X POST 'http://127.0.0.1:8983/solr/products/update?commit=true' \
  -H 'Content-Type: application/json' \
  -d '[
    {"id":"1","name":"Linen shirt","brand":"Apex","price_d":59.0},
    {"id":"2","name":"Wool sweater","brand":"Vega","price_d":129.0}
  ]'

6. Search:

curl -s 'http://127.0.0.1:8983/solr/products/select?q=linen&fl=id,name,brand,price_d&wt=json' | jq

Open the admin UI at http://127.0.0.1:8983/solr/ to browse the schema, cores, and run queries interactively.

Operational notes

  • ZooKeeper is a hard dependency for SolrCloud — never run a 2-node ensemble. One or three or five. Failing to follow this leads to lockups during partitions.
  • Heap larger than 31 GiB loses compressed oops (same JVM rule as Elasticsearch). Cap at 31g per node.
  • docValues=true for sort/facet fields — without it, Solr builds the field cache in heap, which causes OOM under load.
  • Schema reload after add-field is automatic in SolrCloud — but watch the logs after upload; bad config kills the collection.
  • Backups via the snapshot API — POST /admin/collections?action=BACKUP&name=...&location=/backups. Without a shared filesystem each replica writes locally; use a mounted S3-via-FUSE or use the S3 backup repository plugin pattern.

In the engagements we run, Solr appears in environments where it’s already established — library catalogs, e-commerce catalogs, internal search portals. The operational tooling is mature (admin UI, JMX, replication API), but the moving parts are heavier than Elasticsearch or OpenSearch because of the ZooKeeper dependency. See /en/services/managed-operations/ for how we run Solr clusters as part of larger application stacks.