簡體   English   中英

如何設置 Apache solr 管理員密碼

[英]How to set Apache solr admin password

我對solr不是很熟悉。 我已經成功安裝了 solr。 它正在使用碼頭網絡服務器。 我的 solr 版本是 4.10.3。 它的管理頁面不受密碼保護。 任何人都可以訪問它。 我想在 solr admin 上應用 paaword。 我將如何做?

對於低於 5 的版本

如果您使用的是 solr-webapp,那么您需要修改web.xml文件並添加以下行:

<security-constraint>
    <web-resource-collection>
      <web-resource-name>Solr Lockdown</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>
  </security-constraint>
  <login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>Solr</realm-name>
  </login-config> 

對於 Jetty 服務器,您需要在/example/etc/webdefault.xml 中添加以下幾行

<security-constraint>
    <web-resource-collection>
      <web-resource-name>Solr authenticated application</web-resource-name>
      <url-pattern>/</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <role-name>**admin-role**</role-name>
    </auth-constraint>
  </security-constraint>

  <login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>Test Realm</realm-name>
  </login-config>

更新/example/etc/jetty.xml文件

<Call name="addBean">
      <Arg>
        <New class="org.eclipse.jetty.security.HashLoginService">
          <Set name="name">Test Realm</Set>
          <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set>
          <Set name="refreshInterval">0</Set>
        </New>
      </Arg>
    </Call>

/example/etc/realm.properties

admin: s3cr3t, admin-role

用戶名 =管理員密碼 = s3cr3t 角色名稱 = 管理員角色

Solr 版本 5+

在最新的 Solr 版本中,文件夾結構發生了變化。 您將在以下文件夾路徑中找到所有文件。

{SOLR_HOME}/server/etc/jetty.xml {SOLR_HOME}/server/etc/webdefault.xml

{SOLR_HOME}/server/etc/realm.properties創建新的憑證文件:

admin: s3cr3t, admin-role

有關更多信息,您可以幫助 solr wiki docs

在運行 solr 6.1 和 jetty 的 solr admin 中啟用身份驗證

前置條件:

  1. Solr 版本 6.1

  2. Solr在系統中運行成功

  3. Solr Admin 通過碼頭運行

過程:

1.編輯jetty.xml

編輯文件“server/etc/jetty.xml”在Configure標簽結束前添加以下內容

<Call name="addBean">
      <Arg>
        <New class="org.eclipse.jetty.security.HashLoginService">
          <Set name="name">Test Realm</Set>
          <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set>
          <Set name="refreshInterval">0</Set>
        </New>
      </Arg>
    </Call>

2. 編輯 webdefault.xml

編輯文件“server/etc/webdefault.xml”在web-app標簽結束前添加以下內容

<security-constraint>
    <web-resource-collection>
      <web-resource-name>Solr authenticated application</web-resource-name>
      <url-pattern>/</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <role-name>core1-role</role-name>
    </auth-constraint>
  </security-constraint>

  <login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>Test Realm</realm-name>
  </login-config>

特別說明:

role-name標簽中使用的值需要與“realm.properties”文件中使用的值相同

3. 創建新文件“realm.properties”

在“server/etc/”位置創建一個名為“realm.properties”的文件,並放置以下內容

admin: admin123,core1-role

用戶名: admin

密碼: admin123

角色名稱: core1-role

(這需要與 server/etc/webdefault.xml” 文件中的role-name標簽中使用的名稱相同)

4. 最后一步

重啟 Solr 服務器

現在在瀏覽器中訪問 Solr http://localhost:8983/solr/你會發現瀏覽器要求輸入usernamepassword 輸入usernamepassword

在此處輸入圖片說明

如果你使用的是tomcat,

Open [Tomcat install dir]\tomcat-users.xml for editing.

<tomcat-user>元素中添加以下幾行並保存更改(使用您自己的用戶名和密碼):

<role rolename="solr_admin"/><user username="your_username"  password="your_password"  roles="solr_admin"/>

打開Tomcat安裝目錄\\webapps\\solr\\WEB-INF\\web.xml進行編輯。 路徑中的“solr”是您要保護的實例的名稱。 通常這是“solr”,但如果您正在運行高級設置,則可能會有所不同。 <web-app>元素中添加以下幾行:

<security-constraint>
<web-resource-collection>
  <web-resource-name>Solr Lockdown</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>
</security-constraint>


<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Solr</realm-name></login-config>

保存更改並重新啟動 Tomcat。 通過啟動新的瀏覽器會話並導航到您的站點來測試您的更改,例如。 http://localhost:8080/solr/應該會提示您輸入憑據。

如果您的 Tomcat 安裝目錄 tomcat-users.xml 文件被修改,則轉到項目資源管理器中服務器下的 tomcat-users.xml 文件並在那里添加您的更改。

由於為 Solr 設置密碼很麻煩(抱歉,有時您必須按原樣命名),因此我提出了另一種解決方案:使用iptables限制對它的訪問。

如果您安裝 Apache Solr 服務器,通常服務器將偵聽端口 8983。因此服務器管理界面將在以下位置可用:

http://YOUR_SERVERS_IP:8983/solr/

所以我們可以限制連接到端口 8983 如下:

iptables -A INPUT -p tcp -s localhost --dport 8983 -j ACCEPT
iptables -A INPUT -p tcp -s YOUR_SERVERS_IP --dport 8983 -j ACCEPT
iptables -A INPUT -p tcp --dport 8983 -j DROP

這將接受來自本地主機(第一行)和服務器 IP 本身(第二行)的所有請求,但會刪除所有其他連接(最后一行)。 第二行不是必需的,但可以幫助我們輕松訪問 Solr 的管理界面。 要從本地機器訪問管理界面,我們必須首先將所有連接轉發到服務器。 最簡單的方法是使用 sshuttle (lazy mans VPN):

sshuttle --dns -r root@YOUR_SERVERS_IP 0/0

在我們想要訪問管理界面的本地機器上執行此命令。 另一種選擇是,將ssh隧道與開放的 ssh 客戶端一起使用:

ssh -D 1080 root@YOUR_SERVERS_IP

在瀏覽器中設置一個socks 代理到1080 端口。

我也在處理 Solr v.4.10,這真的很煩人。 沒有一個所謂的“解決方案”對我有用。 我最終在我的 Ubuntu 機器上安裝了 Nginx,並將 :8983 端口代理到 docker,其中 Nginx 需要密碼。 這對我有用。

我只需要告知我的情況是什么解決方案。 實際上我的網站是用ajax編寫的,這就是為什么通過設置密碼也可以保護我的網站。 因此,在開放互聯網必須使用 solr 的情況下,這不是解決方案。 因此,通過引導其最佳的解決方案Solr的維基是使用代理像node.js的,nginex等給出這里

使用 node.js 代理並應用 iptable 規則(如上所述)解決了我的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM