1) Install and deploy a SolrCloud example
Download and extract Apache Solr (6.6.0 was used for the purpose of this tutorial). Now start SolrCloud via:
- bin/solr -e cloud
Once the cluster is up and running we can post some data to the collection we have created via the REST interface:
- curl http://localhost:8983/solr/gettingstarted/update -d '[ {"id" : "book1", "title_t" : "The Merchant of Venice", "author_s" : "William Shakespeare"}]'
- curl http://localhost:8983/solr/gettingstarted/update -d '[ {"id" : "book2", "title_t" : "Macbeth", "author_s" : "William Shakespeare"}]'
- curl http://localhost:8983/solr/gettingstarted/update -d '[ {"id" : "book3", "title_t" : "Death of a Salesman", "author_s" : "Arthur Miller"}]'
- curl http://localhost:8983/solr/gettingstarted/query?q=author_s:William+Shakespeare
Now that our SolrCloud instance is up and running, let's look at how we can secure access to it, by using HTTP Basic Authentication to authenticate our REST requests. Download the following security configuration which enables Basic Authentication in Solr:
Two users are defined - "alice" and "bob" - both with password "SolrRocks". Now upload this configuration to the Apache Zookeeper instance that is running with Solr:
- server/scripts/cloud-scripts/zkcli.sh -zkhost localhost:9983 -cmd putfile /security.json security.json
- curl -u alice:SolrRocks http://localhost:8983/solr/gettingstarted/query?q=author_s:Arthur+Miller
Thanks for brief discussion about Solr. I have one question that after implementing Solr security, as you have used curl to get result. How I can do it with REST API
ReplyDeleteThis comment has been removed by the author.
Delete