Introduction to Apache Solr
Apache Solr is a powerful, open-source search platform built on Apache Lucene. It provides distributed indexing, replication, load-balanced querying, automated failover and recovery, and centralized configuration. Solr is highly reliable, scalable, and fault-tolerant, making it ideal for enterprise search applications.
Key Features
- • Full-text search with advanced query capabilities including faceted search, highlighting, and spell checking
- • Real-time indexing for immediate searchability of new content
- • Highly scalable distributed architecture with SolrCloud mode
- • Rich document handling supporting JSON, XML, CSV, and binary formats
- • Comprehensive REST-like API for easy integration
- • Built-in admin interface for monitoring and management
Common Use Cases
E-commerce Search
Product search and filtering
CMS & Document Management
Content and document search
Log Analysis
Log monitoring and analytics
Knowledge Base
Enterprise wiki search
Prerequisites and VPS Requirements
Before installing Solr, ensure your RamNode VPS meets the following requirements:
| Resource | Recommendation |
|---|---|
| CPU | 2+ vCPU cores (4+ for production) |
| RAM | 4GB minimum (8GB+ for larger indexes) |
| Storage | SSD, 20GB+ depending on data volume |
| OS | Ubuntu 22.04 LTS or Ubuntu 24.04 LTS |
Recommended VPS
Premium KVM VPS with 4GB RAM and SSD storage for development and small-to-medium workloads.
Software Prerequisites
- • Java 11+ (Java 17 LTS recommended)
- • Root or sudo access
- • Basic Linux command line
- • Firewall access for ports
Installing Java (OpenJDK)
Solr requires Java to run. We'll install OpenJDK 17, the current long-term support release.
sudo apt update && sudo apt upgrade -ysudo apt install openjdk-17-jdk -yjava -versionopenjdk version "17.0.x" 2024-xx-xx
OpenJDK Runtime Environment (build 17.0.x+x-Ubuntu-xxxxx)
OpenJDK 64-Bit Server VM (build 17.0.x+x-Ubuntu-xxxxx, mixed mode)echo 'export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64' | sudo tee -a /etc/profile.d/java.sh
echo 'export PATH=$PATH:$JAVA_HOME/bin' | sudo tee -a /etc/profile.d/java.sh
source /etc/profile.d/java.shInstalling Apache Solr
We'll download and install Solr 9.x, the latest stable major version, using the official installation script.
cd /opt
sudo wget https://dlcdn.apache.org/solr/solr/9.7.0/solr-9.7.0.tgz💡 Version Note: Check solr.apache.org/downloads for the latest version. Replace 9.7.0 with the current stable release if newer.
sudo tar xzf solr-9.7.0.tgz solr-9.7.0/bin/install_solr_service.sh --strip-components=2
sudo bash ./install_solr_service.sh solr-9.7.0.tgzThis script will create a dedicated 'solr' user, extract Solr to /opt/solr, configure data directory at /var/solr, and set up Solr as a systemd service.
sudo systemctl status solrsudo systemctl start solr
sudo systemctl enable solr✅ Access the Solr Admin UI at http://YOUR_SERVER_IP:8983/solr
Configuring Solr
Solr's main configuration is managed through several files. Understanding these will help you customize your deployment.
| File | Purpose |
|---|---|
| solr.in.sh | Environment variables, JVM settings, memory |
| solr.xml | Global settings, core discovery configuration |
| solrconfig.xml | Per-core: request handlers, caching, indexing |
| managed-schema | Field definitions, field types, analyzers |
Adjusting Memory Settings
Edit the Solr environment file to configure JVM heap size based on your VPS RAM:
sudo nano /etc/default/solr.in.shSOLR_HEAP="2g"
# For a 4GB VPS, use 2GB heap
# For an 8GB VPS, use 4GB heap
# Leave at least 2GB for the OS and other processesBinding to Specific IP
For security, bind Solr to localhost or a specific interface:
SOLR_HOST="127.0.0.1"
# Or bind to all interfaces (not recommended for production)
# SOLR_HOST="0.0.0.0"sudo systemctl restart solrCreating Your First Core
A Solr core is a single index with its own configuration. Let's create a core and index some data.
sudo -u solr /opt/solr/bin/solr create -c mycoreThis creates a core named 'mycore' with the default schema-less configuration.
Index Sample Data
cd /opt/solr
sudo -u solr bin/solr post -c mycore example/exampledocs/books.jsoncurl -X POST -H 'Content-Type: application/json' \
'http://localhost:8983/solr/mycore/update?commit=true' \
--data-binary '[
{"id": "1", "title": "Introduction to Solr", "author": "John Doe"},
{"id": "2", "title": "Advanced Search Techniques", "author": "Jane Smith"}
]'Query Your Data
curl 'http://localhost:8983/solr/mycore/select?q=*:*'curl 'http://localhost:8983/solr/mycore/select?q=title:Solr'Managing Cores
# List all cores
sudo -u solr /opt/solr/bin/solr status
# Delete a core
sudo -u solr /opt/solr/bin/solr delete -c mycore
# Reload a core (after config changes)
curl 'http://localhost:8983/solr/admin/cores?action=RELOAD&core=mycore'Security Configuration
Securing your Solr installation is critical for production environments. Implement these security measures before exposing Solr to the network.
Enable Authentication
Solr supports Basic Authentication. Create a security.json file:
sudo -u solr nano /var/solr/data/security.json{
"authentication": {
"class": "solr.BasicAuthPlugin",
"credentials": {
"admin": "IV0EHq1OnNrj6gvRCwvFwTrZ1+z1oBbnQdiVC3otuq0= Ndd7LKvVBAaZIF0QAVi1ekCfAJXr1GGfLtRUXhgrF8c="
},
"blockUnknown": true
},
"authorization": {
"class": "solr.RuleBasedAuthorizationPlugin",
"permissions": [
{ "name": "security-edit", "role": "admin" },
{ "name": "all", "role": "admin" }
],
"user-role": { "admin": "admin" }
}
}⚠️ Important: The password hash above is for 'SolrRocks'. Generate your own secure password hash using: echo -n 'yourpassword' | sha256sum
Firewall Configuration
Configure UFW to restrict access to Solr:
# Allow SSH
sudo ufw allow ssh
# Allow Solr only from specific IPs (recommended)
sudo ufw allow from YOUR_IP_ADDRESS to any port 8983
# Or allow from anywhere (less secure)
# sudo ufw allow 8983/tcp
# Enable firewall
sudo ufw enableReverse Proxy with Nginx (Recommended)
For production, use Nginx as a reverse proxy with SSL:
sudo apt install nginx -y
sudo nano /etc/nginx/sites-available/solrserver {
listen 443 ssl;
server_name solr.yourdomain.com;
ssl_certificate /etc/letsencrypt/live/solr.yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/solr.yourdomain.com/privkey.pem;
location / {
proxy_pass http://127.0.0.1:8983;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}sudo ln -s /etc/nginx/sites-available/solr /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginxPerformance Tuning
Optimize Solr performance based on your workload and available resources.
JVM Garbage Collection
For Solr 9.x, G1GC is recommended. Add to /etc/default/solr.in.sh:
GC_TUNE=("-XX:+UseG1GC" \
"-XX:+PerfDisableSharedMem" \
"-XX:+ParallelRefProcEnabled" \
"-XX:MaxGCPauseMillis=250" \
"-XX:+AlwaysPreTouch")Query Cache Configuration
Edit solrconfig.xml for your core to tune caching:
<query>
<filterCache class="solr.CaffeineCache"
size="512"
initialSize="512"
autowarmCount="256"/>
<queryResultCache class="solr.CaffeineCache"
size="512"
initialSize="512"
autowarmCount="256"/>
<documentCache class="solr.CaffeineCache"
size="512"
initialSize="512"/>
</query>OS-Level Optimizations
sudo nano /etc/security/limits.conf
# Add these lines:
solr soft nofile 65535
solr hard nofile 65535
solr soft nproc 65535
solr hard nproc 65535sudo sysctl -w vm.max_map_count=262144
echo 'vm.max_map_count=262144' | sudo tee -a /etc/sysctl.confMonitoring and Maintenance
Regular monitoring and maintenance keeps your Solr instance healthy and performant.
Checking Solr Status
# Service status
sudo systemctl status solr
# Solr admin status
curl 'http://localhost:8983/solr/admin/info/system?wt=json'
# Core status
curl 'http://localhost:8983/solr/admin/cores?action=STATUS'Log Management
Solr logs are located at /var/solr/logs/:
# View recent logs
sudo tail -f /var/solr/logs/solr.log
# Check for errors
sudo grep -i error /var/solr/logs/solr.log | tail -20Backup and Recovery
# Backup via API
curl 'http://localhost:8983/solr/mycore/replication?command=backup&location=/var/solr/backups'
# Manual backup of data directory
sudo -u solr cp -r /var/solr/data/mycore /var/solr/backups/mycore-$(date +%Y%m%d)
# Restore from backup
curl 'http://localhost:8983/solr/mycore/replication?command=restore&location=/var/solr/backups'Index Optimization
# Optimize (merge segments)
curl 'http://localhost:8983/solr/mycore/update?optimize=true&waitFlush=true'
# Force commit
curl 'http://localhost:8983/solr/mycore/update?commit=true'Troubleshooting
Common issues and their solutions.
Solr Won't Start
# Check logs for errors
sudo journalctl -u solr -n 50
sudo cat /var/solr/logs/solr.log | tail -50
# Verify Java is available
java -version
# Check port availability
sudo netstat -tlnp | grep 8983Out of Memory Errors
If you see OutOfMemoryError in logs:
- 1. Increase SOLR_HEAP in /etc/default/solr.in.sh
- 2. Reduce cache sizes in solrconfig.xml
- 3. Consider upgrading to a VPS with more RAM
- 4. Split large cores into multiple smaller ones
Slow Query Performance
- • Enable query logging to identify slow queries
- • Review and optimize your schema field types
- • Increase cache sizes for frequently accessed data
- • Use filter queries (fq) for faceting and filtering
- • Consider using SSD storage for improved I/O
📚 Need Help? Consult the Apache Solr documentation or reach out to RamNode support for VPS-related issues.
