org.apache.solr.client.solrj.SolrServerException: IOException occured when talking to server at:解决方案

时间:2022-03-25 08:28:18
在使用solrJ访问远程solr时出现该问题,而且相同的代码访问不同的solr,有的可以执行通过,有的会出现如下问题:
objc[10523]: Class JavaLaunchHelper is implemented in both 
/Library/Java/JavaVirtualMachines/ jdk1.8.0_40.jdk/Contents/Home/bin/java (0x106cb14c0) and 
/Library/Java/JavaVirtualMachines/ jdk1.8.0_40.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x107cf64e0). One of the two will be used. Which one is undefined.
Exception in thread "main" org.apache.solr.client.solrj.SolrServerException: IOException occured when talking to server at: https://192.168.0.101:8983/solr/test
 at org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:589)
 at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:240)
 at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:229)
 at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:149)
 at org.apache.solr.client.solrj.SolrClient.query(SolrClient.java:942)
 at org.apache.solr.client.solrj.SolrClient.query(SolrClient.java:957)
 at com.qunhe.instdeco.plan.config.SitSolrConfig.querySolr(SitSolrConfig.java:192)
 at com.qunhe.instdeco.plan.config.SitSolrConfig.main(SitSolrConfig.java:207)
Caused by: javax.net.ssl.SSLPeerUnverifiedException : Host name ' 192.168.0.101 ' does not match the certificate subject provided by the peer (CN=local, OU=chenyufeng, O=chenyufeng, L=Hangzhou, ST=Zhejiang, C=China)
 at org.apache.http.conn.ssl.SSLConnectionSocketFactory.verifyHostname(SSLConnectionSocketFactory.java:465)
 at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:395)
 at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353)
 at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
 at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
 at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
 at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
 at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
 at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
 at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
 at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
 at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
 at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
 at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
 at org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:481)
 ... 7 more



解决方案:
这是由于配置的https证书导致的。在配置证书时,会打进去IP地址,该IP地址也就是Solr服务所在的IP,客户端可以使用https的方式来访问该Solr。但是如果证书中的IP配置错误,不是Solr所在服务器的IP,那就客户端访问就可能出现上述的问题。所以请注意,想要用哪些IP来访问该Solr服务,就在证书创建时配置哪些IP。