第一部分:Solr配置账户密码
创建配置文件
/data/solr-8.3.0/server/etc
创建realm.properties
1 2 3 4 5 6 7 8
| # # 这个文件定义用户名,密码和角色 # # 格式如下 # <username>: <password>[,<rolename> ...] # #userName: password,role admin: passwd1219,admin
|
安全处理程序设置
/data/solr-8.3.0/server/contexts
修改solr-jetty-context.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <?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> <Get name="securityHandler"> <Set name="loginService"> <New class="org.eclipse.jetty.security.HashLoginService"> <Set name="name">realm</Set> <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set> </New> </Set> </Get> </Configure>
|
添加验证拦截
/data/solr-8.3.0/server/solr-webapp/webapp/WEB-INF
编辑web.xml
1 2 3 4 5 6 7 8 9 10 11 12 13
| <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>realm</realm-name> </login-config>
|
第二部分:测试与验证
再次访问已经要输入用户名密码才可以操作了

如果Java集成solr地址如下:
http://admin:passwd1219@localhost:8983/solr/new_core