This guide is about how to install apache Solr in Windows 10.
Requirements
- Download Apache Solr
- Download NSSM
- Install Java JDK
Steps
- Create a folder named Solr in your C:/ root.
- Extract the zip folder in your Solr folder.
- In
C:\Solr\solr-8.4.0\server\etc
add the following Powershell script and save it assolrssl.ps1
:
param(
[string]$KeystoreFile = 'solr-ssl.keystore.jks',
[string]$KeystorePassword = 'secret',
[string]$SolrDomain = 'localhost',
[switch]$Clobber
)
$ErrorActionPreference = 'Stop'
### PARAM VALIDATION
if($KeystorePassword -ne 'secret') {
Write-Error 'The keystore password must be "secret", because Solr apparently ignores the parameter'
}
if((Test-Path $KeystoreFile)) {
if($Clobber) {
Write-Host "Removing $KeystoreFile..."
Remove-Item $KeystoreFile
} else {
$KeystorePath = Resolve-Path $KeystoreFile
Write-Error "Keystore file $KeystorePath already existed. To regenerate it, pass -Clobber."
}
}
$P12Path = [IO.Path]::ChangeExtension($KeystoreFile, 'p12')
if((Test-Path $P12Path)) {
if($Clobber) {
Write-Host "Removing $P12Path..."
Remove-Item $P12Path
} else {
$P12Path = Resolve-Path $P12Path
Write-Error "Keystore file $P12Path already existed. To regenerate it, pass -Clobber."
}
}
try {
$keytool = (Get-Command 'C:\Program Files\Java\jdk1.8.0_261\bin\keytool.exe').Source
} catch {
$keytool = Read-Host "keytool.exe not on path. Enter path to keytool (found in JRE bin folder)"
if([string]::IsNullOrEmpty($keytool) -or -not (Test-Path $keytool)) {
Write-Error "Keytool path was invalid."
}
}
### DOING STUFF
Write-Host ''
Write-Host 'Generating JKS keystore...'
& $keytool -genkeypair -alias solr-ssl -keyalg RSA -keysize 2048 -keypass $KeystorePassword -storepass $KeystorePassword -validity 9999 -keystore $KeystoreFile -ext SAN=DNS:$SolrDomain,IP:127.0.0.1 -dname "CN=$SolrDomain, OU=Enginnering, O=Verndale, L=Quito, ST=Pichincha, C=EC"
Write-Host ''
Write-Host 'Generating .p12 to import to Windows...'
& $keytool -importkeystore -srckeystore $KeystoreFile -destkeystore $P12Path -srcstoretype jks -deststoretype pkcs12 -srcstorepass $KeystorePassword -deststorepass $KeystorePassword
Write-Host ''
Write-Host 'Trusting generated SSL certificate...'
$secureStringKeystorePassword = ConvertTo-SecureString -String $KeystorePassword -Force -AsPlainText
$root = Import-PfxCertificate -FilePath $P12Path -Password $secureStringKeystorePassword -CertStoreLocation Cert:\LocalMachine\Root
Write-Host 'SSL certificate is now locally trusted. (added as root CA)'
Write-Host ''
Write-Host '########## NEXT STEPS ##########' -ForegroundColor Green
Write-Host ''
Write-Host '1. Copy your keystore to $SOLR_HOME\server\etc (MUST be here)' -ForegroundColor Green
if(-not $KeystoreFile.EndsWith('solr-ssl.keystore.jks')) {
Write-Warning 'Your keystore file is not named "solr-ssl.keystore.jks"'
Write-Warning 'Solr requires this exact name, so make sure to rename it before use.'
}
$KeystorePath = Resolve-Path $KeystoreFile
Write-Host ''
Write-Host '2. Add the following lines to your solr.in.cmd:' -ForegroundColor Green
Write-Host ''
Write-Host "set SOLR_SSL_KEY_STORE=etc/solr-ssl.keystore.jks" -ForegroundColor Yellow
Write-Host "set SOLR_SSL_KEY_STORE_PASSWORD=$KeystorePassword" -ForegroundColor Yellow
Write-Host "set SOLR_SSL_TRUST_STORE=etc/solr-ssl.keystore.jks" -ForegroundColor Yellow
Write-Host "set SOLR_SSL_TRUST_STORE_PASSWORD=$KeystorePassword" -ForegroundColor Yellow
Write-Host ''
Write-Host 'Done!'
You need to replace C:\Program Files\Java\jdk1.8.0_261\bin\keytool.exe
path that match your installed Java JDK.
- Then you need to run the following powershell script that is located at
C:\Solr\solr-8.4.0\server\etc
.\solrssl.ps1
-
When execution is done, you will see
solr-ssl.keystore.jks
andsolr-ssl.keystore.p12
files generated. -
Edit
C:\Solr\solr-8.4.0\bin\solr.in.cmd
file and uncomment the following lines:
set SOLR_SSL_KEY_STORE=etc/solr-ssl.keystore.jks
set SOLR_SSL_KEY_STORE_PASSWORD=secret
set SOLR_SSL_TRUST_STORE=etc/solr-ssl.keystore.jks
set SOLR_SSL_TRUST_STORE_PASSWORD=secret
set SOLR_SSL_KEY_STORE_TYPE=JKS
set SOLR_SSL_TRUST_STORE_TYPE=JKS
- Extract NSSM zip file into
C:\nssm-2.24
8. Add NSSM_HOME in your Enviroment variables:
- Finally, run the following command
nssm install
10. Fill the form with the following information:
11. Open your browser to check Solr installed at the following url: https://localhost:8983/solr/#/
And that’s all you have Solr successfully installed in your development machine.
2 replies on “How to install Solr?”
Thanks for sharing the script.
However I am getting error when I am using same script to generate SSL certi.
PS F:\Solr\Downloads> .\GenerateSolrSSL.ps1
Generating JKS keystore…
The expression after & in a pipeline element produced an object that was not valid. It must result in a command
name, a script block, or a CommandInfo object.
At F:\Solr\Downloads\GenerateSolrSSL.ps1:50 char:3
+ & $keytool -genkeypair -alias solr-ssl -keyalg RSA -keysize 2048 -keypass $Keyst …
+ ~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : BadExpression
PS F:\Solr\Downloads>
Sorry to heard that and the late reply!, mm looks like it doesn’t accept the & in line 50 any way probably you can remove it. if you see this is only for concatenate Write-Host with Get-Command probably check the path of your Java SDK ‘C:\Program Files\Java\jdk1.8.0_291\bin\keytool.exe’ this is for my machine but probably you have another one for yours.
Write-Host Generating JKS keystore…
& $keytool -genkeypair -alias solr-ssl -keyalg RSA -keysize 2048 -keypass $KeystorePassword -storepass $KeystorePassword -validity 9999 -keystore $KeystoreFile -ext SAN=DNS:$SolrDomain,IP:127.0.0.1 -dname “CN=$SolrDomain, OU=Enginnering, O=Verndale, L=Quito, ST=Pichincha, C=EC”