开发环境solrj8.2,solr7.7+tomcat8,配置的有账号密码。正常无bug出现
线上环境solrj8.2,solr8.9+tomcat8,配置的有账号密码。最初出现 IOException occured when talking to server at:xxxxx
出现原因:
shards原理时solr服务端解析客户端传递来的shards参数,再根据从shards参数解析来的solr地址去请求,再将响应结果合并返回到客户端。问题在于solr7.7依赖的时solrj7.7,而solrj7.7所使用的是Httpsolrclient,solrj8.9所使用的是Http2SolrClient,具体两者的去吧我就不赘述了,感兴趣的小伙伴可以去了解一下
解决办法:
在tomcat8的 catalina.sh 中添加环境参数
-Dsolr.http1=true
然后又出现问题:
Error from server at null: Expected mime type application/octet-stream but got text/html. <!doctype html><html lang="en"><head><title>HTTP Status 401 – Unauthorized</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 401 – Unauthorized</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Description</b> The request has not been applied because it lacks valid authentication credentials for the target resource.</p><hr class="line" /><h3>Apache Tomcat/8.5.72</h3></body></html>
出现原因:
Http2SolrClient 根据shards中的solr地址请求时未携带solr的账号密码 解决办法:
在tomcat8的 catalina.sh 中添加环境参数
-Dsolr.httpclient.builder.factory=org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory
-Dbasicauth=username:password