Solr专题(四)Solr安全设置

因为solr的admin界面默认只需要知道ip和端口就能直接访问,如果被别有用心的人盯上就很容易给你的系统带来重大的破坏,所以我们应该限制访问。

请注意本例使用的是Solr7

Solr集成了以下几种验证方式:

  1. Basic自定义身份验证方式

  2. Kerberos身份验证方式

  3. 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界面,提示需要输入密码才能访问。

扫描二维码关注公众号,回复: 11143774 查看本文章
原创文章 20 获赞 6 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_37171817/article/details/105661376
今日推荐