Solr專題(四)Solr安全設定
阿新 • • 發佈:2020-07-17
因為solr的admin介面預設只需要知道ip和埠就能直接訪問,如果被別有用心的人盯上就很容易給你的系統帶來重大的破壞,所以我們應該限制訪問。
請注意本例使用的是Solr7。
Solr集成了以下幾種驗證方式:
- Basic自定義身份驗證方式
- Kerberos身份驗證方式
- Hadoop身份驗證方式
最簡單的一種大概就是限制solr服務的訪問ip,如果使用tomcat當做容器,可以在server.xml中配置可訪問的ip:
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127.0.0.1,192.168.208.119"/>
使用Basic認證
新增使用者配置檔案realm.properties:
admin:admin123,solr_admin
在/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>solr_admin</role-name> <role-name>admin</role-name> </auth-constraint> <login-config> <auth-method>BASIC</auth-method> <realm-name>Solr Admin</realm-name> </login-config> </security-constraint>
在/server/contexts/solr-jetty-context.xml中的Configure屬性中新增:
<Get name="securityHandler"> <Set name="loginService"> <New class="org.eclipse.jetty.security.HashLoginService"> <Set name="name">admin</Set> <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set> </New> </Set> </Get>
重啟solr,訪問admin介面,提示需要輸入密碼才能訪問。