solr版本4.0.0
我的solr下載后解壓在d盤,你的隨意。
在D:\apache-solr-4.0.0\apache-solr-4.0.0\example\etc目錄下新建role.properties文件,名字可隨便。
內容如下:
# # 這個文件定義用戶名,密碼和角色 # # 格式如下 # <username>: <password>[,<rolename> ...] # #userName: password,role test: 123,admin
編輯D:\apache-solr-4.0.0\apache-solr-4.0.0\example\contexts\solr.xml文件如下,文件中插入安全處理程序設置標簽
<?xml version="1.0"?> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd"> <Configure class="org.eclipse.jetty.webapp.WebAppContext"> <Set name="contextPath">/solr</Set> <Set name="war"><SystemProperty name="jetty.home"/>/webapps/solr.war</Set> <Set name="defaultsDescriptor"><SystemProperty name="jetty.home"/>/etc/webdefault.xml</Set> <Set name="tempDirectory"><Property name="jetty.home" default="."/>/solr-webapp</Set> <!-- 安全處理程序設置 --> <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/realm.properties</Set> </New> </Set> </Get> </Configure>
編輯D:\apache-solr-4.0.0\apache-solr-4.0.0\example\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>
配置完成后,重啟solr服務器,重新訪問solr就需要用戶名和密碼了
可參考http://www.mossle.com/docs/auth/html/ch109-preauth.html