solr默認可以直接訪問管理界面,這樣很危險,因此需要給配置上登錄授權。
說明:以下操作中是我本地機器的目錄,實際中要對應你們自己的路徑。
1、創建role.properties文件,
進入/picclife/soft/solr-7.4.0/server/etc目錄下,創建文件role.properties,並寫入登錄信息
格式:<username>: <password>[,<rolename> ...]
用戶名:密碼,角色
xxx: yyy,aaa #例如:user:passwd123,admin
2、修改solr-jetty-context.xml文件,改前備份一下
進入/picclife/soft/solr-7.4.0/server/contexts目錄下,將以下配置加入文件solr-jetty-context.xml中
<Get name="securityHandler">
<Set name="loginService">
<New class="org.eclipse.jetty.security.HashLoginService">
<Set name="name">TestRealm</Set>
<Set name="config">
<SystemProperty name="jetty.home" default="."/>/etc/role.properties</Set>
</New>
</Set>
</Get>
3、修改web.xml文件,改前備份一下
進入目錄/picclife/soft/solr-7.4.0/server/solr-webapp/webapp/WEB-INF目錄下,將以下配置加入文件web.xml中
<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> --驗證的角色,不是用戶名,有多個角色就寫多個role-name 標籤
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>TestRealm</realm-name>
</login-config>
這段配置放在<web-app>...</web-app>之內
4、配置完成後重啓一下solr,再次訪問的時候,就會提示需要賬號密碼才能可以