Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solrj cannot connect to zookeeper from Solr Cloud Example

I started a Solrcloud by running the included example bin/solr -e cloud, and in that case, I managed to start up a three nodes Solr cloud and created a gettingstarted collection:

http://localhost:8983/solr/admin/collections?action=CREATE&name=gettingstarted&numShards=3&replicationFactor=2&maxShardsPerNode=2&collection.configName=gettingstarted

I think it comes with a embedded zookeeper running on port 9983 because I saw this output when I started the cloud:

...
Starting up Solr on port 7574 using command:
bin/solr start -cloud -p 7574 -s "example/cloud/node2/solr" -z localhost:9983
Waiting up to 30 seconds to see Solr running on port 7574 [/] 
... 

However, when I tried to connect to the SolrCloud using SolrJ, it failed with the error message:

Exception in thread "main" org.apache.solr.common.SolrException: Cannot connect to cluster at localhost:9983/solr: cluster not found/not ready

enter image description here

Can anyone help me understand what is going on here?

like image 827
B.Mr.W. Avatar asked Mar 08 '16 18:03

B.Mr.W.


People also ask

Can't connect to ZooKeeper Solr?

To resolve this issue, start Zookeeper on another free port (that is, 3181). To configure the new port, change the port number from the default port 2181 to the new unused port (that is, 3181) and then restart the Application Server after clearing the cache.

How does ZooKeeper work with Solr?

SolrCloud is flexible distributed search and indexing, without a master node to allocate nodes, shards and replicas. Instead, Solr uses ZooKeeper to manage these locations, depending on configuration files and schemas. Queries and updates can be sent to any server.

How do I start Solr in cloud mode?

You either need to copy solr. xml to the solr_home directory, or keep in centrally in ZooKeeper /solr. xml . The previous command will start another Solr node on port 8987 with Solr home set to example/cloud/node3/solr .


2 Answers

The code fails because you are trying to point the CloudSolrServer to a znode that does not exist. Your zkhost is not configured with a /solr chroot. The configs seem to be stored at the root node.

So change the line

String zkHostString = "localhost:9983/solr";

to

String zkHostString = "localhost:9983";

and your code should work.

like image 107
Binoy Dalal Avatar answered Oct 21 '22 10:10

Binoy Dalal


It depends on your zkHost. If your zkHost contains /solr , then it should be localhost:2181/solr or localhost:9983/solr; Otherwise , localhost:yourport

like image 29
Hunter Avatar answered Oct 21 '22 10:10

Hunter