java.net.SocketException: Socket is not connected 5C

solr集群测试
package com.taotao.search;

import java.io.IOException;

import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrServer;
import org.apache.solr.common.SolrInputDocument;
import org.junit.Test;

public class SolrCloudTest {

@Test
public void testAddDocument() throws Exception {
    // 创建一个和solr集群的连接
    // 参数就是zookeeper的地址列表,使用逗号分隔
    String zkHost = "192.168.248.135:2181,192.168.248.135:2182,192.168.248.135:2183";
    CloudSolrServer solrServer = new CloudSolrServer(zkHost);
    // 设置默认的collection
    solrServer.setDefaultCollection("collection2");
    // 创建一个文档对象
    SolrInputDocument document = new SolrInputDocument();
    // 向文档中添加域
    document.addField("id", "test001");
    document.addField("item_title", "测试商品");
    // 把文档添加到索引库
    solrServer.add(document);
    // 提交
    solrServer.commit();
}

@Test
public void deleteDocument() throws SolrServerException, IOException {
    // 创建一个和solr集群的连接
    // 参数就是zookeeper的地址列表,使用逗号分隔
    String zkHost = "192.168.248.135:2181,192.168.248.135:2182,192.168.248.135:2183";
    CloudSolrServer solrServer = new CloudSolrServer(zkHost);
    // 设置默认的collection
    solrServer.setDefaultCollection("collection2");

    solrServer.deleteByQuery("*:*");
    solrServer.commit();
}

}

出现异常
java.net.SocketException: Socket is not connected
at sun.nio.ch.Net.translateToSocketException(Net.java:123)
at sun.nio.ch.Net.translateException(Net.java:157)
at sun.nio.ch.Net.translateException(Net.java:163)
at sun.nio.ch.SocketAdaptor.shutdownInput(SocketAdaptor.java:401)
at org.apache.zookeeper.ClientCnxnSocketNIO.cleanup(ClientCnxnSocketNIO.java:200)
at org.apache.zookeeper.ClientCnxn$SendThread.cleanup(ClientCnxn.java:1185)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1110)
Caused by: java.nio.channels.NotYetConnectedException
at sun.nio.ch.SocketChannelImpl.shutdownInput(SocketChannelImpl.java:782)
at sun.nio.ch.SocketAdaptor.shutdownInput(SocketAdaptor.java:399)
... 3 more

3个回答

并不会solr,建议检查网络/防火墙/端口配置

那几个机器是否能ping通呢?

同样问题已解决!!!希望能帮助到你

1、关闭firewall:systemctl stop firewalld.service
#停止firewall:systemctl disable firewalld.service
#禁止firewall开机启动:firewall-cmd --state
#查看默认防火墙状态(关闭后显示notrunning,开启后显示running)

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐