2016-07-24 112 views
0

我有一個本地的兩個實例Solr Cloud設置了一個zookeeper實例。我試圖通過SolrJ進行連接來執行查詢,但是我的代碼在執行查詢時掛起了2分鐘左右,然後失敗。我遵循Solr wiki上的基本示例。日誌/代碼如下SolrJ在連接到zookeeper時掛起

2016-07-24 13:29:01.932 INFO 83666 --- [qtp699221219-28] org.apache.zookeeper.ZooKeeper   : Initiating client connection, connectString=localhost:2181 sessionTimeout=10000 [email protected] 
2016-07-24 13:29:01.948 INFO 83666 --- [qtp699221219-28] o.a.solr.common.cloud.ConnectionManager : Waiting for client to connect to ZooKeeper 

2016-07-24 13:29:01.953 INFO 83666 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn   : Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) 

2016-07-24 13:29:01.955 INFO 83666 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn   : Socket connection established to localhost/127.0.0.1:2181, initiating session 

2016-07-24 13:29:01.967 INFO 83666 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn   : Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x1561cdd875e0004, negotiated timeout = 10000 

2016-07-24 13:29:01.972 INFO 83666 --- [back-3-thread-1] o.a.solr.common.cloud.ConnectionManager : Watcher [email protected] name:ZooKeeperConnection Watcher:localhost:2181 got event WatchedEvent state:SyncConnected type:None path:null path:null type:None 

2016-07-24 13:29:01.972 INFO 83666 --- [qtp699221219-28] o.a.solr.common.cloud.ConnectionManager : Client is connected to ZooKeeper 

2016-07-24 13:29:01.973 INFO 83666 --- [qtp699221219-28] o.apache.solr.common.cloud.SolrZkClient : Using default ZkACLProvider 

2016-07-24 13:29:01.974 INFO 83666 --- [qtp699221219-28] o.a.solr.common.cloud.ZkStateReader  : Updating cluster state from ZooKeeper... 



2016-07-24 13:29:01.990 INFO 83666 --- [qtp699221219-28] o.a.solr.common.cloud.ZkStateReader  : Loaded empty cluster properties 

2016-07-24 13:29:01.995 INFO 83666 --- [qtp699221219-28] o.a.solr.common.cloud.ZkStateReader  : Updated live nodes from ZooKeeper... (0) -> (2) 

2016-07-24 13:31:24.653 ERROR 83666 --- [qtp699221219-28] o.a.s.client.solrj.impl.CloudSolrClient : Request to collection foo failed due to (0) java.net.ConnectException: Operation timed out, retry? 0 

,我的代碼是:

String zkHostString = "localhost:2181"; 
    CloudSolrClient solr = new CloudSolrClient.Builder().withZkHost(zkHostString).build(); 
    solr.setDefaultCollection("foo"); 
    SolrQuery query = new SolrQuery(); 
    query.set("q", "*:*"); 
    QueryResponse response = null; 
    try { 
     response = solr.query(query); 
    } catch (SolrServerException e) { 
     return null; 
    } 
    //Do Something with the results... 
+0

這是Solr的6.1 – Sutty1000

回答

1

Urgh,我是個白癡,動物園管理員實例和Solr實例都在裏面泊塢窗,上面貼的代碼是沒有的。所以Zookeeper使用docker containers ip報告了solr url ...主機需要通過localhost而不是docker container ip連接。

如:動物園管理員響應[http://172.17.0.5:8983/solr/foo_shard1_replica2http://172.17.0.6:8984/solr/foo_shard1_replica1] 但我的代碼需要調用[http://localhost:8983/solr/foo_shard1_replica2http://localhost:8984/solr/foo_shard1_replica1]