连接到zookeeper时SolrJ挂起

时间:2016-07-24 12:38:01

标签: java solr solrj

我有一个本地两个实例Solr Cloud设置,只有一个zookeeper实例。我试图通过SolrJ连接执行查询但是我的代码在执行查询时会挂起2分钟左右然后失败。我已经按照Solr wiki上的基本示例进行了操作。日志/代码在

之下
2016-07-24 13:29:01.932  INFO 83666 --- [qtp699221219-28] org.apache.zookeeper.ZooKeeper           : Initiating client connection, connectString=localhost:2181 sessionTimeout=10000 watcher=org.apache.solr.common.cloud.SolrZkClient$3@496eab9
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 org.apache.solr.common.cloud.ConnectionManager@4bb95d56 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...

2 个答案:

答案 0 :(得分:1)

Urgh,我是一个白痴,zookeeper实例和solr实例都在docker里面,上面发布的代码不是。所以Zookeeper使用docker containers ip报告了solr url ...主机需要通过localhost而不是docker容器ip连接。

例如:Zookeeper回复[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]

答案 1 :(得分:0)

我认为我也有类似的问题。我在端口8983 + 9983上的远程计算机(solr-1)上运行了Solr + Zookeeper-在内部,它们是具有172.22.X.X地址的docker-compose网络(可在该计算机上本地访问,但不能在我的代码运行的位置)。但是,端口8983和9983已暴露,并且访问Solr Admin UI(在solr-1:8983上运行)可以正常工作。

当我尝试使用SolrJ进行连接时,我正在使用CloudSolrClient-初始化如下:

 new CloudSolrClient.Builder(zkHosts, Optional.empty()).build()

其中zkHosts仅包含' solr-1:9983 “(转义)。我发送请求后,他立即调用getLiveNodes并返回本地地址(172.22.XX)而不是全局主机名(solr-1:9983)。因为我显然无法访问该主机名,所以我超时了。

听起来像您的问题吗?你有什么想法?您认为问题是SolrJ还是我设置Solr / Zookeeper + Docker的方式?

这是我的docker-compose文件的样子:

version: '2'
services:
    solr:
        image: solr
        container_name: solr    
        ports:
            - "9983:9983"
            - "8983:8983"
        networks:
            - solr 
        entrypoint:
            - docker-entrypoint.sh
            - solr
            - start
            - -c
            - -f
networks:
    solr: