<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # Elasticsearch integration > 原文:[https://docs.gitlab.com/ee/integration/elasticsearch.html](https://docs.gitlab.com/ee/integration/elasticsearch.html) * [Version Requirements](#version-requirements) * [Installing Elasticsearch](#installing-elasticsearch) * [Elasticsearch repository indexer](#elasticsearch-repository-indexer) * [Omnibus GitLab](#omnibus-gitlab) * [From source](#from-source) * [Debian / Ubuntu](#debian--ubuntu) * [CentOS / RHEL](#centos--rhel) * [Mac OSX](#mac-osx) * [Building and installing](#building-and-installing) * [System Requirements](#system-requirements) * [Enabling Elasticsearch](#enabling-elasticsearch) * [Limiting namespaces and projects](#limiting-namespaces-and-projects) * [Disabling Elasticsearch](#disabling-elasticsearch) * [Adding GitLab’s data to the Elasticsearch index](#adding-gitlabs-data-to-the-elasticsearch-index) * [Indexing through the administration UI](#indexing-through-the-administration-ui) * [Indexing through Rake tasks](#indexing-through-rake-tasks) * [Indexing small instances](#indexing-small-instances) * [Indexing large instances](#indexing-large-instances) * [Indexing limitations](#indexing-limitations) * [GitLab Elasticsearch Rake tasks](#gitlab-elasticsearch-rake-tasks) * [Environment variables](#environment-variables) * [Indexing a specific project](#indexing-a-specific-project) * [Elasticsearch index scopes](#elasticsearch-index-scopes) * [Tuning](#tuning) * [Guidance on choosing optimal cluster configuration](#guidance-on-choosing-optimal-cluster-configuration) * [Elasticsearch integration settings guidance](#elasticsearch-integration-settings-guidance) * [Deleted documents](#deleted-documents) * [Troubleshooting](#troubleshooting) * [Common issues](#common-issues) * [Low-level troubleshooting](#low-level-troubleshooting) * [Known Issues](#known-issues) * [Reverting to basic search](#reverting-to-basic-search) # Elasticsearch integration[](#elasticsearch-integration-starter-only "Permalink") 版本歷史 * 在 GitLab [Starter](https://about.gitlab.com/pricing/) 8.4 中[引入](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/109 "Elasticsearch 合并請求") . * 在 GitLab [Starter](https://about.gitlab.com/pricing/) 9.0 中[引入](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/1305)了對[Amazon Elasticsearch 的](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-gsg.html)支持. 本文檔介紹了如何使用 GitLab 設置 Elasticsearch. 啟用后,您將受益于快速的搜索響應時間以及兩個特殊搜索的優點: * [Advanced Global Search](../user/search/advanced_global_search.html) * [Advanced Syntax Search](../user/search/advanced_search_syntax.html) ## Version Requirements[](#version-requirements "Permalink") | GitLab 版本 | Elasticsearch 版本 | | --- | --- | | GitLab 企業版 8.4-8.17 | Elasticsearch 2.4 with [Delete By Query Plugin](https://www.elastic.co/guide/en/elasticsearch/plugins/2.4/plugins-delete-by-query.html) installed | | GitLab 企業版 9.0-11.4 | 彈性搜索 5.1-5.5 | | GitLab 企業版 11.5-12.6 | Elasticsearch 5.6-6.x | | manbetx 客戶端打不開企業版 12.7+ | Elasticsearch 6.x-7.x | ## Installing Elasticsearch[](#installing-elasticsearch "Permalink") Omnibus 軟件包中*不*包括 Elasticsearch. 無論您使用的是 Omnibus 軟件包還是從源代碼安裝的 GitLab,您都必須[自行安裝](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/install-elasticsearch.html "Elasticsearch 6.8 安裝文檔") . 提供有關安裝 Elasticsearch 的詳細信息超出了本文檔的范圍. **注意:** Elasticsearch 應該安裝在單獨的服務器上,無論您自己安裝還是使用云托管產品,例如 Elastic 的[Elasticsearch Service](https://www.elastic.co/elasticsearch/service) (在 AWS,GCP 或 Azure 上可用)或[Amazon Elasticsearch](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-gsg.html) Service. 不建議在與 GitLab 相同的服務器上運行 Elasticsearch,這可能會導致 GitLab 實例性能下降.**注意:** **對于單節點 Elasticsearch 集群,功能集群的運行狀況為黃色** (永遠不會為綠色),因為已分配了主要分片,但副本卻無法存在,因為沒有其他節點可以為 Elasticsearch 分配副本. 將數據添加到數據庫或存儲庫中并[在管理區域中啟用 Elasticsearch 后](#enabling-elasticsearch) ,搜索索引將自動更新. ## Elasticsearch repository indexer[](#elasticsearch-repository-indexer "Permalink") 為了索引 Git 存儲庫數據,GitLab 使用了[Go 語言編寫](https://gitlab.com/gitlab-org/gitlab-elasticsearch-indexer)的[索引器](https://gitlab.com/gitlab-org/gitlab-elasticsearch-indexer) . Go 索引器的安裝方式取決于您的 GitLab 版本: * 對于 Omnibus GitLab 11.8 及更高版本,請參見[Omnibus GitLab](#omnibus-gitlab) . * For installations from source or older versions of Omnibus GitLab, install the indexer [From Source](#from-source). ### Omnibus GitLab[](#omnibus-gitlab "Permalink") 從 GitLab 11.8 開始,Omnibus GitLab 中包含了 Go 索引器. 以前的基于 Ruby 的索引器已在[GitLab 12.3](https://gitlab.com/gitlab-org/gitlab/-/issues/6481)中刪除. ### From source[](#from-source "Permalink") 首先,我們需要安裝一些依賴項,然后構建并安裝索引器本身. 該項目依靠[ICU](http://site.icu-project.org/)進行文本編碼,因此我們需要確保在運行`make`之前安裝了適用于您平臺的開發包. #### Debian / Ubuntu[](#debian--ubuntu "Permalink") 要在 Debian 或 Ubuntu 上安裝,請運行: ``` sudo apt install libicu-dev ``` #### CentOS / RHEL[](#centos--rhel "Permalink") 要在 CentOS 或 RHEL 上安裝,請運行: ``` sudo yum install libicu-devel ``` ##### Mac OSX[](#mac-osx "Permalink") 要在 macOS 上安裝,請運行: ``` brew install icu4c export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig:$PKG_CONFIG_PATH" ``` ### Building and installing[](#building-and-installing "Permalink") 要構建和安裝索引器,請運行: ``` indexer_path=/home/git/gitlab-elasticsearch-indexer # Run the installation task for gitlab-elasticsearch-indexer: sudo -u git -H bundle exec rake gitlab:indexer:install[$indexer_path] RAILS_ENV=production cd $indexer_path && sudo make install ``` The `gitlab-elasticsearch-indexer` will be installed to `/usr/local/bin`. 您可以使用`PREFIX` env 變量更改安裝路徑. 如果這樣做,請記住將`-E`標志傳遞給`sudo` . Example: ``` PREFIX=/usr sudo -E make install ``` 安裝完成后,請在您實例的 Elasticsearch 設置下啟用, [如下所述](#enabling-elasticsearch) . ## System Requirements[](#system-requirements "Permalink") Elasticsearch 需要的資源超出了[GitLab 系統要求中](../install/requirements.html)記錄的資源. 這些會因安裝大小而異,但是,根據[官方指南](https://www.elastic.co/guide/en/elasticsearch/guide/current/hardware.html) ,您應確保每個 Elasticsearch 節點**至少至少**有**8 GiB RAM** . 請記住,這是 Elasticsearch 的**最低要求** . 對于生產實例,他們建議使用更多的資源. 所需的存儲空間在很大程度上取決于要存儲在 GitLab 中的存儲庫的大小,但是根據經驗,由于所有存儲庫加起來,您應該至少有 50%的可用空間. ## Enabling Elasticsearch[](#enabling-elasticsearch "Permalink") 為了啟用 Elasticsearch,您需要具有管理員權限. 導航到**管理區域** (扳手圖標),然后導航到**設置>集成**并展開**Elasticsearch**部分. 單擊**保存更改**以使更改生效. 可以使用以下 Elasticsearch 設置: | Parameter | Description | | --- | --- | | `Elasticsearch indexing` | 啟用/禁用 Elasticsearch 索引編制. 例如,您可能想要啟用索引編制但禁用搜索以使索引有時間完全完成. 另外,請記住,此選項對現有數據沒有任何影響,僅啟用/禁用跟蹤數據更改的后臺索引器. 因此,通過啟用此功能,您將不會為現有數據建立索引,請按照[將 GitLab 的數據添加到 Elasticsearch 索引中所述的](#adding-gitlabs-data-to-the-elasticsearch-index)那樣,使用特殊的 Rake 任務. | | `Elasticsearch pause indexing` | 啟用/禁用臨時索引暫停. 這對于群集遷移/重新索引很有用. 仍會跟蹤所有更改,但是直到未暫停它們才提交給 Elasticsearch 索引. | | `Search with Elasticsearch enabled` | 在搜索中使用 Elasticsearch 啟用/禁用. | | `URL` | 用于連接到 Elasticsearch 的 URL. 使用逗號分隔的列表來支持群集(例如, `http://host1, https://host2:9200` ). 如果您的 Elasticsearch 實例受密碼保護,請在 URL 中傳遞`username:password` (例如, `http://<username>:<password>@<elastic_host>:9200/` ). | | `Number of Elasticsearch shards` | 出于性能原因,Elasticsearch 索引分為多個碎片. 通常,較大的索引需要具有更多的分片. 在重新創建索引之前,對該值所做的更改才會生效. 您可以在[Elasticsearch 文檔中](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html#create-index-settings)閱讀有關權衡的更多信息 | | `Number of Elasticsearch replicas` | 每個 Elasticsearch 分片可以具有多個副本. 這些是分片的完整副本,可以提高查詢性能或抵御硬件故障. 增大該值將大大增加索引所需的總磁盤空間. | | `Limit namespaces and projects that can be indexed` | 啟用此選項將允許您選擇要索引的名稱空間和項目. 所有其他名稱空間和項目將改為使用數據庫搜索. 請注意,如果啟用此選項但未選擇任何名稱空間或項目,則不會為它們建立索引. [在下面閱讀更多內容](#limiting-namespaces-and-projects) . | | `Using AWS hosted Elasticsearch with IAM credentials` | 使用[AWS IAM 授權](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html)或[AWS EC2 實例配置文件憑證](https://docs.aws.amazon.com/codedeploy/latest/userguide/getting-started-create-iam-instance-profile.html#getting-started-create-iam-instance-profile-cli)對 Elasticsearch 請求進行簽名. 必須將策略配置為允許`es:*`操作. | | `AWS Region` | 您的 Elasticsearch 服務所在的 AWS 區域. | | `AWS Access Key` | AWS 訪問密鑰. | | `AWS Secret Access Key` | AWS 秘密訪問密鑰. | | `Maximum field length` | See [the explanation in instance limits.](../administration/instance_limits.html#maximum-field-length). | | `Maximum bulk request size (MiB)` | 最大批量請求大小由 GitLab 基于 Golang 的索引器流程使用,并指示在將有效負載提交給 Elasticsearch 的批量 API 之前,它應在給定的索引過程中收集(并存儲在內存中)多少數據. 此設置應與批量請求并發設置一起使用(請參見下文),并且需要通過`gitlab-rake`命令或通過`gitlab-rake`命令來適應 Elasticsearch 主機和運行 GitLab 基于 Golang 的索引器的主機的資源限制. Sidekiq 任務. | | `Bulk request concurrency` | 批量請求并發指示可以并行運行多少個 GitLab 基于 Golang 的索引器進程(或線程)來收集數據,然后將其提交給 Elasticsearch 的批量 API. 這可以提高索引編制性能,但可以更快地填充 Elasticsearch 批量請求隊列. 此設置應與最大批量請求大小設置(請參見上文)一起使用,并且需要容納`gitlab-rake`的 Elasticsearch 主機和運行 GitLab 基于 Golang 的索引器的主機的資源限制命令或 Sidekiq 任務. | ### Limiting namespaces and projects[](#limiting-namespaces-and-projects "Permalink") 如果選擇" `Limit namespaces and projects that can be indexed`更多選項可用 [![限制名稱空間和項目選項](https://img.kancloud.cn/b4/e2/b4e2eae1d2b6b6c43ace465e5d7f662d_843x212.png)](img/limit_namespaces_projects_options.png) 您可以選擇名稱空間和項目以排他索引. 請注意,如果名稱空間是一個組,它將包括所有子組以及屬于這些子組的要被索引的項目. 如果所有名稱空間都已建立索引,Elasticsearch 僅提供跨組代碼/提交搜索(全局). 在僅對名稱空間的子集進行索引的特定情況下,全局搜索將不提供代碼或提交范圍. 這僅在索引命名空間的范圍內才有可能. 當前,無法對多個已索引的名稱空間進行編碼/提交搜索(當僅對名稱空間的子集進行索引時). 例如,如果兩個組都已建立索引,則無法在兩個組上運行單個代碼搜索. 您只能在第一組上然后在第二組上運行代碼搜索. 您可以通過編寫感興趣的部分名稱空間或項目名稱來過濾選擇下拉列表. [![limit namespace filter](https://img.kancloud.cn/01/8c/018c1423e21f80447da430dc2b4f2fa8_398x163.png)](img/limit_namespace_filter.png) **注意:**如果未選擇名稱空間或項目,則不會進行 Elasticsearch 索引.**警告:**如果您已經為實例建立索引,則必須重新生成索引,才能刪除所有現有數據以進行過濾以使其正常工作. 為此,請運行 Rake 任務`gitlab:elastic:recreate_index`和`gitlab:elastic:clear_index_status` . 然后,從列表中刪除名稱空間或項目將按預期從 Elasticsearch 索引中刪除數據. ## Disabling Elasticsearch[](#disabling-elasticsearch "Permalink") 要禁用 Elasticsearch 集成: 1. 導航到**管理區域** (扳手圖標),然后導航到**設置>集成** . 2. 展開**Elasticsearch**部分,然后取消選中**Elasticsearch 索引**和**啟用** **Elasticsearch 的** **搜索** . 3. 單擊**保存更改**以使更改生效. 4. (可選)刪除現有索引: ``` # Omnibus installations sudo gitlab-rake gitlab:elastic:delete_index # Installations from source bundle exec rake gitlab:elastic:delete_index RAILS_ENV=production ``` ## Adding GitLab’s data to the Elasticsearch index[](#adding-gitlabs-data-to-the-elasticsearch-index "Permalink") 啟用 Elasticsearch 索引編制后,您的 GitLab 實例中的新更改將在發生更改時自動進行索引. 要回填現有數據,可以使用以下方法之一在后臺作業中對其進行索引. ### Indexing through the administration UI[](#indexing-through-the-administration-ui "Permalink") [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/15390) in [GitLab Starter](https://about.gitlab.com/pricing/) 12.3. 通過管理區域建立索引: 1. [Configure your Elasticsearch host and port](#enabling-elasticsearch). 2. 創建空索引: ``` # Omnibus installations sudo gitlab-rake gitlab:elastic:create_empty_index # Installations from source bundle exec rake gitlab:elastic:create_empty_index RAILS_ENV=production ``` 3. [Enable **Elasticsearch indexing**](#enabling-elasticsearch). 4. Click **索引所有項目** in **管理區域>設置>集成> Elasticsearch**. 5. 單擊確認消息中的**檢查進度** ,以查看后臺作業的狀態. 6. 個人摘要需要手動編制索引: ``` # Omnibus installations sudo gitlab-rake gitlab:elastic:index_snippets # Installations from source bundle exec rake gitlab:elastic:index_snippets RAILS_ENV=production ``` 7. 索引完成后,啟用[**Search with Elasticsearch**](#enabling-elasticsearch) . ### Indexing through Rake tasks[](#indexing-through-rake-tasks "Permalink") 可以使用 Rake 任務執行索引. #### Indexing small instances[](#indexing-small-instances "Permalink") **警告:**這將刪除您現有的索引. 如果數據庫大小小于 500 MiB,并且所有托管存儲庫的大小小于 5 GiB: 1. [Configure your Elasticsearch host and port](#enabling-elasticsearch). 2. 索引您的數據: ``` # Omnibus installations sudo gitlab-rake gitlab:elastic:index # Installations from source bundle exec rake gitlab:elastic:index RAILS_ENV=production ``` 3. 索引完成后,啟用[**Search with Elasticsearch**](#enabling-elasticsearch) . #### Indexing large instances[](#indexing-large-instances "Permalink") **警告:**執行異步索引編制將生成很多 Sidekiq 作業. 確保具有[可擴展和高度可用的設置](README.html)或創建[額外的 Sidekiq 進程](../administration/operations/extra_sidekiq_processes.html)以為該任務做準備 1. [Configure your Elasticsearch host and port](#enabling-elasticsearch). 2. 創建空索引: ``` # Omnibus installations sudo gitlab-rake gitlab:elastic:create_empty_index # Installations from source bundle exec rake gitlab:elastic:create_empty_index RAILS_ENV=production ``` 3. 如果這是您的 GitLab 實例的重新索引,請清除索引狀態: ``` # Omnibus installations sudo gitlab-rake gitlab:elastic:clear_index_status # Installations from source bundle exec rake gitlab:elastic:clear_index_status RAILS_ENV=production ``` 4. [Enable **Elasticsearch indexing**](#enabling-elasticsearch). 5. 索引大型 Git 存儲庫可能需要一段時間. 為了加快此過程,您可以暫時禁用自動刷新和復制. 根據我們的經驗,您可以預期索引編制時間將減少 20%. 索引完成后,我們將啟用它們. 此步驟是可選的! ``` curl --request PUT localhost:9200/gitlab-production/_settings --header 'Content-Type: application/json' --data '{ "index" : { "refresh_interval" : "-1", "number_of_replicas" : 0 } }' ``` 6. 索引項目及其相關數據: ``` # Omnibus installations sudo gitlab-rake gitlab:elastic:index_projects # Installations from source bundle exec rake gitlab:elastic:index_projects RAILS_ENV=production ``` 這為需要索引的每個項目加入了一個 Sidekiq 作業. 您可以在**管理區域>監視>后臺作業>隊列選項卡中**查看作業,然后單擊`elastic_indexer` ,也可以使用 Rake 任務查詢索引狀態: ``` # Omnibus installations sudo gitlab-rake gitlab:elastic:index_projects_status # Installations from source bundle exec rake gitlab:elastic:index_projects_status RAILS_ENV=production Indexing is 65.55% complete (6555/10000 projects) ``` 如果要將索引限制為一定范圍的項目,可以提供`ID_FROM`和`ID_TO`參數: ``` # Omnibus installations sudo gitlab-rake gitlab:elastic:index_projects ID_FROM=1001 ID_TO=2000 # Installations from source bundle exec rake gitlab:elastic:index_projects ID_FROM=1001 ID_TO=2000 RAILS_ENV=production ``` 其中`ID_FROM`和`ID_TO`是項目 ID. 這兩個參數都是可選的. 上面的示例將索引從 ID `1001`到(并包括)ID `2000`所有項目. **故障排除:**有時`gitlab:elastic:index_projects`排隊的項目索引作業可能會中斷. 出于多種原因可能會發生這種情況,但是再次運行索引任務始終是安全的. 它將跳過已經建立索引的存儲庫. 當索引器在數據庫中存儲每個已索引存儲庫的最后一次提交 SHA 時,您可以使用特殊參數`UPDATE_INDEX`運行索引器,它將再次檢查每個項目存儲庫以確保對存儲庫中的每個提交都進行了索引,這很有用.如果您的索引已過時: ``` # Omnibus installations sudo gitlab-rake gitlab:elastic:index_projects UPDATE_INDEX=true ID_TO=1000 # Installations from source bundle exec rake gitlab:elastic:index_projects UPDATE_INDEX=true ID_TO=1000 RAILS_ENV=production ``` 您還可以使用`gitlab:elastic:clear_index_status` Rake 任務來強制索引器"忘記"所有進度,因此它將從頭開始重試索引過程. 7. 個人代碼段與項目無關,需要單獨編制索引: ``` # Omnibus installations sudo gitlab-rake gitlab:elastic:index_snippets # Installations from source bundle exec rake gitlab:elastic:index_snippets RAILS_ENV=production ``` 8. 在建立索引后再次啟用復制和刷新(僅在您之前禁用它的情況下): ``` curl --request PUT localhost:9200/gitlab-production/_settings --header 'Content-Type: application/json' --data '{ "index" : { "number_of_replicas" : 1, "refresh_interval" : "1s" } }' ``` 啟用上述刷新后,應調用強制合并. 對于 Elasticsearch 6.x,在進行強制合并之前,索引應處于只讀模式: ``` curl --request PUT localhost:9200/gitlab-production/_settings --header 'Content-Type: application/json' --data '{ "settings": { "index.blocks.write": true } }' ``` 然后,啟動強制合并: ``` curl --request POST 'localhost:9200/gitlab-production/_forcemerge?max_num_segments=5' ``` 此后,如果索引處于只讀模式,請切換回讀寫模式: ``` curl --request PUT localhost:9200/gitlab-production/_settings --header 'Content-Type: application/json' --data '{ "settings": { "index.blocks.write": false } }' ``` 9. 索引完成后,啟用[**Search with Elasticsearch**](#enabling-elasticsearch) . ### Indexing limitations[](#indexing-limitations "Permalink") 對于存儲庫和摘要文件,GitLab 最多只能索引 1 MiB 的內容,以避免索引超時. ## GitLab Elasticsearch Rake tasks[](#gitlab-elasticsearch-rake-tasks "Permalink") 耙任務可用于: * [生成并安裝](#building-and-installing)索引器. * [禁用 Elasticsearch](#disabling-elasticsearch)時刪除索引. * [將 GitLab 數據添加](#adding-gitlabs-data-to-the-elasticsearch-index)到索引. 以下是一些可用的 Rake 任務: | Task | Description | | --- | --- | | [`sudo gitlab-rake gitlab:elastic:index`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | 啟用 Elasticsearch 索引并運行`gitlab:elastic:create_empty_index` , `gitlab:elastic:clear_index_status` , `gitlab:elastic:index_projects`和`gitlab:elastic:index_snippets` . | | [`sudo gitlab-rake gitlab:elastic:index_projects`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | 遍歷所有項目并在 Sidekiq 作業中排隊以在后臺對它們進行索引. | | [`sudo gitlab-rake gitlab:elastic:index_projects_status`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | 確定索引的總體狀態. 通過計算索引項目的總數,除以項目總數,然后乘以 100 即可完成. | | [`sudo gitlab-rake gitlab:elastic:clear_index_status`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | 刪除所有項目的 IndexStatus 的所有實例. | | [`sudo gitlab-rake gitlab:elastic:create_empty_index[<TARGET_NAME>]`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | 生成一個空索引,并為該索引分配一個別名(僅當該索引不存在時). | | [`sudo gitlab-rake gitlab:elastic:delete_index[<TARGET_NAME>]`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | 刪除 Elasticsearch 實例上的 GitLab 索引和別名(如果存在). | | [`sudo gitlab-rake gitlab:elastic:recreate_index[<TARGET_NAME>]`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | `gitlab:elastic:delete_index[<TARGET_NAME>]`和`gitlab:elastic:create_empty_index[<TARGET_NAME>]`包裝器任務. | | [`sudo gitlab-rake gitlab:elastic:index_snippets`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | 執行 Elasticsearch 導入,對片段數據進行索引. | | [`sudo gitlab-rake gitlab:elastic:projects_not_indexed`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | 顯示未索引的項目. | | [`sudo gitlab-rake gitlab:elastic:reindex_cluster`](https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/tasks/gitlab/elastic.rake) | 安排零停機群集重新索引編制任務. 此功能應與在 GitLab 13.0 之后創建的索引一起使用. | **注意:** `TARGET_NAME`參數是可選的,如果未設置,它將使用當前`RAILS_ENV`的默認索引/別名. ### Environment variables[](#environment-variables "Permalink") 除了 Rake 任務,還有一些環境變量可用于修改過程: | 環境變量 | 數據類型 | 它能做什么 | | --- | --- | --- | | `UPDATE_INDEX` | Boolean | 告訴索引器覆蓋任何現有索引數據(對/錯). | | `ID_TO` | Integer | 告訴索引器僅索引小于或等于該值的項目. | | `ID_FROM` | Integer | 告訴索引器僅索引大于或等于該值的項目. | ### Indexing a specific project[](#indexing-a-specific-project "Permalink") 因為`ID_TO`和`ID_FROM`環境變量使用`or equal to`比較,所以您可以通過使用兩個具有相同項目 ID 號的變量來僅索引一個項目: ``` root@git:~# sudo gitlab-rake gitlab:elastic:index_projects ID_TO=5 ID_FROM=5 Indexing project repositories...I, [2019-03-04T21:27:03.083410 #3384] INFO -- : Indexing GitLab User / test (ID=33)... I, [2019-03-04T21:27:05.215266 #3384] INFO -- : Indexing GitLab User / test (ID=33) is done! ``` ## Elasticsearch index scopes[](#elasticsearch-index-scopes "Permalink") 執行搜索時,GitLab 索引將使用以下范圍: | 范圍名稱 | What it searches | | --- | --- | | `commits` | 提交數據 | | `projects` | 項目數據(默認) | | `blobs` | Code | | `issues` | 發行數據 | | `merge_requests` | 合并請求數據 | | `milestones` | 里程碑數據 | | `notes` | 筆記數據 | | `snippets` | 片段數據 | | `wiki_blobs` | 維基內容 | ## Tuning[](#tuning "Permalink") ### Guidance on choosing optimal cluster configuration[](#guidance-on-choosing-optimal-cluster-configuration "Permalink") 有關選擇集群配置的基本指導,請參考[Elastic Cloud Calculator](https://cloud.elastic.co/pricing) . 您可以在下面找到更多信息. * 通常,您將希望至少將一個 2 節點群集配置與一個副本一起使用,這將使您具有彈性. 如果存儲使用量快速增長,則可能需要預先計劃水平擴展(添加更多節點). * 不建議將 HDD 存儲與搜索群集一起使用,因為它會影響性能. 最好使用 SSD 存儲(例如 NVMe 或 SATA SSD 驅動器). * 您可以使用[GitLab Performance Tool](https://gitlab.com/gitlab-org/quality/performance)來對不同搜索集群大小和配置的搜索性能進行基準測試. * `Heap size`應設置為不超過物理 RAM 的 50%. 此外,不應將其設置為超過基于零的壓縮 oop 的閾值. 確切的閾值會有所不同,但是在大多數系統上 26 GB 是安全的,但在某些系統上也可能高達 30 GB. 有關更多詳細信息,請參見[設置堆大小](https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html#heap-size) . * 每個節點的 CPU(CPU 核心)數通常對應于以下所述`Number of Elasticsearch shards`設置. * 一個好的指導方針是確保每個節點的已配置 GB 堆中的碎片數保持在 20 個以下. 因此,具有 30GB 堆的節點最多應具有 600 個分片,但是越低于此限制,您可以使其越好. 通常,這將有助于群集保持良好的運行狀況. * 小碎片會導致小段,這會增加開銷. 旨在將平均分片大小保持在至少幾 GB 到幾十 GB 之間. 另一個考慮因素是文檔數量,您應該針對此簡單的分片`number of expected documents / 5M +1`公式: `number of expected documents / 5M +1` . * `refresh_interval`是每個索引設置. 如果您不需要實時數據,則可能需要將其從默認的`1s`調整為更大的值. 這將改變您看到新結果的時間. 如果這對您很重要,則應使其盡可能接近默認值. * 如果您有大量繁重的索引操作,則可能需要將[`indices.memory.index_buffer_size`](https://www.elastic.co/guide/en/elasticsearch/reference/current/indexing-buffer.html)提高到 30%或 40%. ### Elasticsearch integration settings guidance[](#elasticsearch-integration-settings-guidance "Permalink") * The `Number of Elasticsearch shards` setting usually corresponds with the number of CPUs available in your cluster. For example, if you have a 3-node cluster with 4 cores each, this means you will benefit from having at least 3*4=12 shards in the cluster. Please note, it’s only possible to change the shards number by using [Split index API](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-split-index.html) or by reindexing to a different index with a changed number of shards. * `Number of Elasticsearch replicas`設置在大多數情況下應等于`1` (每個分片將具有 1 個副本). 不建議使用`0` ,因為丟失一個節點會破壞索引. ### Deleted documents[](#deleted-documents "Permalink") 每當對索引的 GitLab 對象進行更改或刪除時(合并請求描述發生更改,從存儲庫中的 master 分支中刪除文件,刪除項目等),索引中的文檔也會被刪除. 但是,由于這些是"軟"刪除,因此"已刪除文檔"的總數增加了,因此浪費了空間. Elasticsearch 進行段的智能合并,以刪除這些已刪除的文檔. 但是,根據 GitLab 安裝中活動的數量和類型,可能會在索引中看到多達 50%的浪費空間. 通常,我們建議僅使用默認設置讓 Elasticsearch 自動合并和回收空間. 在[Lucene 的"已刪除文檔處理"中](https://www.elastic.co/blog/lucenes-handling-of-deleted-documents "Lucene 處理已刪除文件的方法") , *"總的來說,除了減小最大段大小外,最好將 Lucene 的默認值保持原樣,并且不要對回收刪除時感到擔心."* 但是,某些較大的安裝可能希望調整合并策略設置: * 考慮將`index.merge.policy.max_merged_segment`大小從默認的 5 GB 減小到 2 GB 或 3 GB. 僅當段中至少有 50%的刪除時才進行合并. 較小的段大小將允許合并更頻繁地發生. ``` curl --request PUT localhost:9200/gitlab-production/_settings ---header 'Content-Type: application/json' --data '{ "index" : { "merge.policy.max_merged_segment": "2gb" } }' ``` * 您還可以調整`index.merge.policy.reclaim_deletes_weight` ,它控制如何積極地定位刪除. 但是,這可能會導致代價高昂的合并決策,因此,除非您了解取舍,否則我們建議不要更改此決策. ``` curl --request PUT localhost:9200/gitlab-production/_settings ---header 'Content-Type: application/json' --data '{ "index" : { "merge.policy.reclaim_deletes_weight": "3.0" } }' ``` * 不要[強制合并](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html "強制合并")以刪除已刪除的文檔. [文檔中](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html "強制合并")的警告指出,這可能導致很大的網段,這些網段可能永遠都無法收回,并且還可能導致嚴重的性能或可用性問題. ## Troubleshooting[](#troubleshooting "Permalink") ### Common issues[](#common-issues "Permalink") 以下是一些常見的陷阱以及如何克服它們: * **如何驗證我的 GitLab 實例正在使用 Elasticsearch?** 最簡單的方法是通過運行以下`sudo gitlab-rails console`通過 rails 控制臺( `sudo gitlab-rails console` ): ``` u = User.find_by_username('your-username') s = SearchService.new(u, {:search => 'search_term'}) pp s.search_objects.class.name ``` 如果看到`"ActiveRecord::Relation"` ,則說明您**未**使用 Elasticsearch. If you see `"Kaminari::PaginatableArray"` you are using Elasticsearch. **注意:**以上說明僅用于在索引所有名稱空間時驗證 GitLab 是否正在使用 Elasticsearch. 這僅用于僅索引[命名空間子集的](#limiting-namespaces-and-projects)方案. * **我更新了 GitLab,現在找不到任何東西** 我們會不斷更新索引策略,并致力于支持新版本的 Elasticsearch. 進行索引更改時,更新 GitLab 后可能需要重新編制[索引](#adding-gitlabs-data-to-the-elasticsearch-index) . * **我索引了所有存儲庫,但找不到任何內容** 確保[如上所述對](#adding-gitlabs-data-to-the-elasticsearch-index)所有數據庫數據建立索引. 除此之外,通過[Elasticsearch Search API](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html)檢查數據是否在 Elasticsearch 端顯示. 如果通過[Elasticsearch Search API](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html)顯示,請檢查是否通過 rails 控制臺( `sudo gitlab-rails console` )顯示: ``` u = User.find_by_username('your-username') s = SearchService.new(u, {:search => 'search_term', :scope => 'blobs'}) pp s.search_objects.to_a ``` **注意:**以上說明不適用于僅索引[命名空間子集的情況](#limiting-namespaces-and-projects) . 有關搜索特定數據類型的更多信息,請參見[Elasticsearch 索引范圍](#elasticsearch-index-scopes) . * **我索引了所有存儲庫,但隨后切換了 Elasticsearch 服務器,現在什么也找不到** 您將需要重新運行所有 Rake 任務,以重新索引數據庫,存儲庫和 Wiki. * **索引過程需要很長時間** GitLab 實例中存在的數據越多,索引過程花費的時間就越長. * **有些項目未編入索引,但我們不知道哪些項目** 您可以運行`sudo gitlab-rake gitlab:elastic:projects_not_indexed`以顯示未建立索引的項目. * **"如果未配置父字段,則無法指定父"** 如果您在 GitLab 8.12 之前啟用了 Elasticsearch 并且尚未重建索引,則在許多不同情況下,您將獲得異常: ``` Elasticsearch::Transport::Transport::Errors::BadRequest([400] { "error": { "root_cause": [{ "type": "illegal_argument_exception", "reason": "Can't specify parent if no parent field has been configured" }], "type": "illegal_argument_exception", "reason": "Can't specify parent if no parent field has been configured" }, "status": 400 }): ``` 這是因為我們在 GitLab 8.12 中更改了索引映射,并且應該刪除舊索引并再次從頭開始構建,請參閱[8-11-to-8-12 更新指南中的](https://gitlab.com/gitlab-org/gitlab/blob/master/doc/update/8.11-to-8.12.md#11-elasticsearch-index-update-if-you-currently-use-elasticsearch)詳細信息. * Exception `Elasticsearch::Transport::Transport::Errors::BadRequest` 如果您有此例外情況(就像上面的情況一樣,但實際消息有所不同),請檢查您是否具有正確的 Elasticsearch 版本并滿足其他[要求](#system-requirements) . 還有一種簡單的方法可以使用`sudo gitlab-rake gitlab:check`命令自動檢查它. * Exception `Elasticsearch::Transport::Transport::Errors::RequestEntityTooLarge` ``` [413] {"Message":"Request size exceeded 10485760 bytes"} ``` 當您將 Elasticsearch 集群配置為拒絕某個大小以上的請求(在這種情況下為 10MiB)時,會看到此異常. 這相當于`http.max_content_length`在設置`elasticsearch.yml` . 將其增大到更大的大小,然后重新啟動您的 Elasticsearch 集群. AWS 根據基礎實例的大小對此設置有[固定的限制](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/aes-limits.html) (" HTTP 請求有效負載的最大大小"). * **即使一切似乎都正常運行,我的單節點 Elasticsearch 集群狀態也從未從`yellow`變為`green`** **對于單節點 Elasticsearch 集群,功能集群的運行狀況為黃色** (永遠不會為綠色),因為已分配了主要分片,但副本卻無法存在,因為沒有其他節點可為 Elasticsearch 分配副本. 如果您使用的是[Amazon Elasticsearch](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/aes-handling-errors.html#aes-handling-errors-yellow-cluster-status) Service,這也適用. **警告:**建議不要將副本數設置為`0` (GitLab Elasticsearch 集成菜單中不允許這樣做). 如果您計劃添加更多的 Elasticsearch 節點(總共超過 1 個 Elasticsearch 節點),則副本數將需要設置為大于`0`的整數值. 否則,將導致缺乏冗余(丟失一個節點將破壞索引). 如果您**對單節點 Elasticsearch 集群有綠色狀態**的**嚴格要求** ,請確保您了解上一段概述的風險,然后只需運行以下查詢將副本數設置為`0` (集群將不會再嘗試創建任何碎片副本): ``` curl --request PUT localhost:9200/gitlab-production/_settings --header 'Content-Type: application/json' --data '{ "index" : { "number_of_replicas" : 0 } }' ``` * **我正在`health check timeout: no Elasticsearch node available`索引編制過程中 Sidekiq 中`health check timeout: no Elasticsearch node available`錯誤** ``` Gitlab::Elastic::Indexer::Error: time="2020-01-23T09:13:00Z" level=fatal msg="health check timeout: no Elasticsearch node available" ``` 您可能沒有在 Elasticsearch 集成菜單的**" URL"**字段中使用`http://`或`https://`作為值的一部分. 請確保在此字段中使用`http://`或`https://`作為我們使用的[Go](https://github.com/olivere/elastic)的[Elasticsearch 客戶端,](https://github.com/olivere/elastic) [需要將該 URL 的前綴接受為有效](https://github.com/olivere/elastic/commit/a80af35aa41856dc2c986204e2b64eab81ccac3a) . 更正了網址格式后,請刪除索引(通過[專用的 Rake 任務](#gitlab-elasticsearch-rake-tasks) ),然后[為實例的內容重新編制索引](#adding-gitlabs-data-to-the-elasticsearch-index) . ### Low-level troubleshooting[](#low-level-troubleshooting "Permalink") 當您遇到其他問題(包括性能不佳)時[,](../administration/troubleshooting/elasticsearch.html)可以使用[結構化的低級故障排除文檔](../administration/troubleshooting/elasticsearch.html) . ### Known Issues[](#known-issues "Permalink") * **[Elasticsearch `code_analyzer` doesn’t account for all code cases](https://gitlab.com/gitlab-org/gitlab/-/issues/10693)** 正在評估`code_analyzer`模式和過濾器配置以進行改進. 我們注意到由于我們的模式和過濾器配置, [一些邊緣情況](https://gitlab.com/gitlab-org/gitlab/-/issues/10693#note_158382332)未返回預期的搜索結果. 在[問題 29443](https://gitlab.com/gitlab-org/gitlab/-/issues/29443)中,討論了`code_analyzer`模式和過濾器的改進策略. ### Reverting to basic search[](#reverting-to-basic-search "Permalink") 有時,您的 Elasticsearch 索引數據可能存在問題,因此,如果沒有搜索結果并且假定該范圍內支持基本搜索,則 GitLab 將允許您恢復為"基本搜索". 這種"基本搜索"的行為就像您根本沒有為實例啟用 Elasticsearch 并使用其他數據源(即 PostgreSQL 數據和 Git 數據)進行搜索一樣.
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看