
首先下载最新版solr应用服务器压缩包,
1、下载 .zip 为windows版
我下载的最新版本地址:内嵌jeety服务器,solr5之前的版本都需要放到自己的tomcat里
下载:solr-8.2.0.zip
下载完成之后放在的D:\solr-8.2.0目录下,然后解压到当前目录

2、配置用户、密码、权限
配置的是Basic安全性验证:
Solr在5.0版本后,不再提供war包部署的方式,取而代之的是内置了jetty服务。但是我们发现其中并没有内置任何安全性相关检查,任何人如果知道了我们的外网地址就能直接访问并修改其中的索引。经过查找可以使用jetty的方式来限制web访问。
-
打开路径:solr-8.2.0\server\etc,在此目录下新建verify.properties 配置文件(名字随意),如图:
配置权限认证.png
打开文件进行编辑 , 内容如下:格式为-用户名:密码,权限
# 用户名 密码 权限
user: pass,admin
也可配置多用户,内容如下:
# 用户名 密码 权限
user: pass,admin
user1: pass,admin
user3: pass,admin
-
接着找到目录:solr-8.1\server\contexts,文件列表如图:
配置权限认证2.png
打开文件进行编辑,在文件configure中添加(添加配置权限认证)获取用户文件的配置:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath"><Property name="hostContext" default="/solr"/></Set>
<Set name="war"><Property name="jetty.base"/>/solr-webapp/webapp</Set>
<Set name="defaultsDescriptor"><Property name="jetty.base"/>/etc/webdefault.xml</Set>
<Set name="extractWAR">false</Set>
<!--添加配置权限认证:在文件configure中添加获取用户文件的配置,内容如下:-->
<Get name="securityHandler">
<Set name="loginService">
<New class="org.eclipse.jetty.security.HashLoginService">
<Set name="name">verify—name</Set>
<Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/verify.properties</Set>
</New>
</Set>
</Get>
</Configure>
-
第三处需要修改的地方为web.xml,如图:
配置权限认证3.png
在文件中找到security-constraint的配置,内容如下:
<!-- Get rid of error message -->
<security-constraint>
<web-resource-collection>
<web-resource-name>Disable TRACE</web-resource-name>
<url-pattern>/</url-pattern>
<http-method>TRACE</http-method>
</web-resource-collection>
<auth-constraint/>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Enable everything but TRACE</web-resource-name>
<url-pattern>/</url-pattern>
<http-method-omission>TRACE</http-method-omission>
</web-resource-collection>
</security-constraint>
重新配置 security-resource-collection (删除之前的security-constraint,会导致登录的配置无效)
在auth-constraint节点添加角色 admin,并添加登录配置,如图:
<!--重新配置 security-resource-collection (删除之前的security-constraint,会导致登录的配置无效)-->
<security-constraint>
<web-resource-collection>
<web-resource-name>Solr</web-resource-name>
<url-pattern>/</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>verify-name</realm-name>
</login-config>
效果:

之后启动solr,访问solr地址:
http://localhost:8983/solr/#/

输入:user/pass
登录成功!
springboot通过solr地址中加入用户名密码的方式连接,地址如下:
spring:
data:
solr: # 全文检索
# solr加上了用户名密码访问条件,参数中并没有地方设置username和password,那应该怎么办?
host: http://user:pass@127.0.0.1:8983/solr
网友评论