Create Solr core in console with authentication - solr

I have a Solr core that needs an authentication. Let's say I have a user with password password.
When I now try to create a Solr core in the console with
bin\solr create -c test
I get an HTTP Error 401.
Of course I need to specify my user. How can I add my user and password in the console?
Something like bin\solr create -c test -authentication user:password

Using Command Line scripts with BasicAuth
Add the following line to the (/opt/solr/bin) solr.in.sh or solr.in.cmd file. This example tells the bin/solr command line to to use "basic" as the type of authentication, and to pass credentials with the user-name "solr" and password "SolrRocks":
SOLR_AUTH_TYPE="basic"
SOLR_AUTHENTICATION_OPTS="-Dbasicauth=solr:SolrRocks"
look:
https://lucene.apache.org/solr/guide/6_6/basic-authentication-plugin.html#BasicAuthenticationPlugin-UsingBasicAuthwithSolrJ

If you use Basic Authentication than first set in the CMD Console:
set SOLR_AUTH_TYPE=basic
set SOLR_AUTHENTICATION_OPTS="-Dbasicauth=USER:PASS"
Customize USER:PASS for your need

It has been a while so, I am not sure if you still have this issue. But this can help others who may come across this like how I did.
I am new to solr, so there could be a better way of doing this than what I have here.
Are you using zookeeper for authentication?
Assuming you are using zookeeper for authentication
First of all, I checked and I don't think there is an -authentication parameter for solr create command.
So, this is how I hacked around this issue:
Stopped solr
Started solr without zookeeper
created the core like how you tried for the test core
Then uploaded configuration of the test core to zookeeper. I followed this document - https://systemsarchitect.net/2013/04/06/painless-guide-to-solr-cloud-configuration/
Restarted zookeeper server
Started solr with -p 8983 -z zookeeper_hostname:zookeeper_port
You should be able to access your test core with authentication enabled

Related

How to create core in solr 7 when using Basic Authentication

I'm using basic authentication in my solr project. I want to create new core but it gives me this error.
ERROR: Solr requires authentication for http://localhost:8983/solr/admin/info/system. Please supply valid credentials. HTTP code=401
I'm creating the core like this
solr create -c StorageCore -credentials solr:SolrRocks
How can I fix this problem?
UPDATE
That command argument is only supported when enabling authentication through the command line tool.
For using the control script with basic auth:
Using the Solr Control Script with Basic Auth
Add the following line
to the solr.in.sh or solr.in.cmd file. This example tells the bin/solr
command line to to use "basic" as the type of authentication, and to
pass credentials with the user-name "solr" and password "SolrRocks":
SOLR_AUTH_TYPE="basic"
SOLR_AUTHENTICATION_OPTS="-Dbasicauth=solr:SolrRocks"

How to make SolrCloud use HTTPS for creating collections?

I'm setting up SolrCloud 7.2.1 on a Windows Server 2016, following the getting started guide: https://lucene.apache.org/solr/guide/7_2/getting-started-with-solrcloud.html#GettingStartedwithSolrCloud-InteractiveStartup
I have to specify the host because for some reason the SOLR_HOST variable does not have any effect. localhost gets tried all to time.
So specifying the host, everything works fine until a new collection has to be created.
For some reason I get the following error:
ERROR: Failed to create collection 'collectionname' due to: {solrurl:8984_solr=org.apache.solr.client.solrj.SolrServerException:IOException occured when talking to server at: http://solrurl:8984/solr, solrurl:8983_solr=org.apache.solr.client.solrj.SolrServerException:IOException occured when talking to server at: http://solrurl:8983/solr}
I'm a bit puzzled here because I don't understand why it uses HTTP instead of HTTPS.
I can call the URLs with HTTPS without any problems.
When creating a new collection inside the Solr web interface, the same error occures.
SOLR_SSL_ENABLED variable is set to true.
So how can I change this behaviour? Is there anything I have to do beforehand to make Solr accept changes to the solr.in.cmd and solr.in.sh?
If you want to use inter node communcation over SSL, you have to tell Solr to use that first before bringing the nodes up.
You can use the bundled zkcli tool to set the cluster property first:
server/scripts/cloud-scripts/zkcli.sh -zkhost localhost:2181 -cmd clusterprop -name urlScheme -val https

SolrJ : Server refused connection

For a customer, I need to write a search engine running on Linux. I am using SolrJ and did not configure anything else so far.
I followed https://lucene.apache.org/solr/guide/7_4/using-solrj.html#common-build-systems and thus added SolrJ in the project pom.xml, and also that tutorial.
The SolR client is instanciated like :
solrClient = new HttpSolrClient.Builder(
GeneralSettings.getRootSolrPath() + "/" + getCollectionName()).
build();
But for any query or commit I keep getting org.apache.solr.client.solrj.SolrServerException: Server refused connection at: http://localhost:8983/solr/test. I read http://lucene.472066.n3.nabble.com/Default-query-error-quot-Server-refused-connection-quot-td4010806.html but I am already using the expected port.
My understanding of the java doc SolrClient ’s handle the work of connecting to and communicating with Solr, and are where most of the user configuration happens. is that I only need to import the jar and then everything will work out of the box.
But as I keep getting this "Server refused connection" error I may have to configure something, but I could not find how to configure SolrJ (use solrconfig.xml or core.properties or call System.setProperty or call an API).
Please note that Apache may be running somewhere because I used to test some sites on it.
So how to get rid of this "Server refused connection" error?
Any help or tutorial to set SolrJ up based on Solr available doc would be very much appreciated,
Edit 2018-08-12 16:10
I thought SolrJ could work like Lucene, without a server, but it looks that I missed one essential piece: installing Solr (see https://www.baeldung.com/apache-solrj). I'll give it a try and post updates.
In case it might help someone else starting with SolrJ here are the steps I did to get rid of the error mentionned in the title (actually I followed https://www.baeldung.com/apache-solrj).
Downloaded the latest binary release of Solr
Extracted it somewhere
CDed into that dir
Lauched bin/solr start from that dir
Created a core with bin/solr create -c coreName (maybe another way exists but I hadn't been able to make it work so far)
Then Solr was running and listening on port 8983, and my Java app could connect to it via SolrJ.

Solr: how to delete a collection?

I am using solr 4.9, not adding any additional shard, just use whatever default it comes with it. I have created a collection and tried to delete it by using the following api :
http://<host>/solr/admin/collections?action=DELETE&name=collectionName
but it returns error :
Solr instance is not running in SolrCloud mode
My Solr is not solrCloud, but how do I delete my collection?
Go to the solr folder and Do this..
bin/solr delete -c collection_name
and restart solr with
bin/solr restart
n.b. Tested against Solr 4.9, should work with newer versions.
curl -v http://localhost:8983/solr/admin/cores?action=UNLOAD&deleteInstanceDir=true&core=collectionName
You can delete the Solr Collection in two ways.
1) From the command prompt:
Launch the command prompt from where you have extracted the Apache Solr. Run the below Command
Solr\bin>solr delete -c My_Collection
2) From the Solr Admin Console:
/admin/collections?action=DELETE&name=collection
For more information about the Apache Solr Collection API.
Apache Solr Collection API
According to this guide (https://cwiki.apache.org/confluence/display/solr/Collections+API) this API is working only, when you are in a SolrCloud mode.
If you want to just delete core or just delete all docs in that core, take a look here - https://wiki.apache.org/solr/CoreAdmin
Or do this with the API instead:
http://localhost:8983/solr/admin/collections?action=DELETE&collection=collection1&shard=shard1&replica=core_node1
You can delete a collection in three ways in the recent versions of Solr.
You can delete the collection manually by using the bin/solr tool
You can delete the collection manually via Solr Admin
You can delete the collection by using the Collections API
You can delete the collection by using the V2 API
Deleting a collection using the bin/solr tool is simple. You go to your SOLR_HOME directory and you run:
bin/solr delete -c COLLECTION_NAME
To delete a collection using the Collections API you would run a command like this:
curl 'localhost:8983/solr/admin/collections?action=DELETE&name=COLLECTION_NAME'
Finally, to use the V2 API and delete a collection using it you would do the following:
curl -XDELETE 'http://localhost:8983/api/c/COLLECTION_NAME'
If you plan on removing the collection very rarely, you can do that manually. If that is something commonly used - for example with aliases and time-based data I would suggest using the V2 API as this is the newest one and will probably replace the old APIs at some point.
You could use curl
curl -X GET -H "Content-Type: application/json" "http://localhost:8983/solr/admin/cores?wt=json&action=UNLOAD&core=gettingstarted"
Where gettingstarted is the name of the core that you want to delete.
Please note that the above assumes that solr is running on port 8983.
Though Adam's response is correct, here's the documentation to help use it: https://lucene.apache.org/solr/guide/7_7/collections-api.html#delete
I got stuck on this one for a while and was only getting the invalid deleting of cores answer, which, I'm guessing used to work for collections, but does not in newer versions.

bulkupload without username/password prompt

I have a process which generates daily some data, which I would like to update to a java app running on the appengine using bulkupload, using the command:
appcfg.py upload_data
--url=http://your_app_id.appspot.com/_ah/remote_api --kind= --filename=
It works perfectly, but it always asks me for my username/password.
Is there any way to save the credentials, use certificates, to avoid the username prompt?
Add these options:
--email=
--passin
and at the end : < "your password file.txt"
Seems this technique no longer works with SDK 1.9.17. The updated docs include some new oauth2 command line options, but the instructions are rather confusing. Anyone able to use either the old passin or the new oauth2 techniques? How?

Resources