<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # Geo database replication > 原文:[https://docs.gitlab.com/ee/administration/geo/replication/database.html](https://docs.gitlab.com/ee/administration/geo/replication/database.html) * [PostgreSQL replication](#postgresql-replication) * [Step 1\. Configure the **primary** server](#step-1-configure-the-primary-server) * [Step 2\. Configure the **secondary** server](#step-2-configure-the-secondary-server) * [Step 3\. Initiate the replication process](#step-3-initiate-the-replication-process) * [PgBouncer support (optional)](#pgbouncer-support-optional) * [Troubleshooting](#troubleshooting) # Geo database replication[](#geo-database-replication-premium-only "Permalink") **注意:**如果您的 GitLab 安裝使用外部(不受 Omnibus 管理)PostgreSQL 實例,則 Omnibus 角色將無法執行所有必要的配置步驟. 在這種情況下,請[改用 Geo with external PostgreSQL instances 文檔](external_database.html) .**Note:** The stages of the setup process must be completed in the documented order. Before attempting the steps in this stage, [complete all prior stages](index.html#using-omnibus-gitlab). 本文檔介紹了將**主** GitLab 數據庫復制到**輔助**節點的數據庫時必須執行的最少步驟. 您可能需要根據數據庫設置,數據庫大小等來更改一些值. 我們鼓勵您先閱讀所有步驟,然后再在測試/生產環境中執行這些步驟. ## PostgreSQL replication[](#postgresql-replication "Permalink") 進行寫操作的 GitLab **主**節點將連接到**主**數據庫服務器, **輔助**節點將連接到他們自己的數據庫服務器(也是只讀的). 我們建議使用[PostgreSQL 復制插槽,](https://medium.com/@tk512/replication-slots-in-postgresql-b4b03d277c75)以確保**主**節點保留恢復**次**節點所需的所有數據. 請參閱下面的更多細節. The following guide assumes that: * 您使用的是 Omnibus,因此使用的是 PostgreSQL 11 或更高版本,其中包括[`pg_basebackup`工具](https://s0www0postgresql0org.icopy.site/docs/11/app-pgbasebackup.html)和改進的[Foreign Data Wrapper](https://s0www0postgresql0org.icopy.site/docs/11/postgres-fdw.html)支持. * 您已經設置了一個**主**節點(您要從中復制的 GitLab 服務器),并且正在運行 Omnibus 的 PostgreSQL(或等效版本),并且已經設置了一個新的**輔助**服務器,并且具有相同版本的 OS,PostgreSQL 和 GitLab.所有節點. **警告:** Geo 可用于流復制. 目前不支持邏輯復制. 在[討論支持問題](https://gitlab.com/gitlab-org/gitlab/-/issues/7420) . ### Step 1\. Configure the **primary** server[](#step-1-configure-the-primary-server "Permalink") 1. SSH 到您的 GitLab **主**服務器并以 root 用戶身份登錄: ``` sudo -i ``` 2. 編輯`/etc/gitlab/gitlab.rb`并為您的節點添加一個**唯一的**名稱: ``` # The unique identifier for the Geo node. gitlab_rails['geo_node_name'] = '<node_name_here>' ``` 3. 重新配置**主**節點以使更改生效: ``` gitlab-ctl reconfigure ``` 4. 執行以下命令以將節點定義**為主**節點: ``` gitlab-ctl set-geo-primary-node ``` 該命令將使用您在`/etc/gitlab/gitlab.rb`定義的`external_url` . 5. 僅限于 GitLab 10.4 及更高版本:執行以下操作以確保`gitlab`數據庫用戶已定義密碼: 生成所需密碼的 MD5 哈希值: ``` gitlab-ctl pg-password-md5 gitlab # Enter password: <your_password_here> # Confirm password: <your_password_here> # fca0b89a972d69f00eb3ec98a5838484 ``` Edit `/etc/gitlab/gitlab.rb`: ``` # Fill with the hash generated by `gitlab-ctl pg-password-md5 gitlab` postgresql['sql_user_password'] = '<md5_hash_of_your_password>' # Every node that runs Puma or Sidekiq needs to have the database # password specified as below. If you have a high-availability setup, this # must be present in all application nodes. gitlab_rails['db_password'] = '<your_password_here>' ``` 6. Omnibus GitLab 已經有一個名為`gitlab_replicator`的[復制用戶](https://wiki.postgresql.org/wiki/Streaming_Replication) . 您必須手動設置該用戶的密碼. 系統將提示您輸入密碼: ``` gitlab-ctl set-replication-password ``` 如果您已將`gitlab_replicator`用戶名更改為其他名稱,則此命令還將讀取`postgresql['sql_replication_user']` Omnibus 設置. 如果您使用的不是由 Omnibus GitLab 管理的外部數據庫,則需要創建復制器用戶并手動為其定義密碼: ``` --- Create a new user 'replicator' CREATE USER gitlab_replicator; --- Set/change a password and grants replication privilege ALTER USER gitlab_replicator WITH REPLICATION ENCRYPTED PASSWORD '<replication_password>'; ``` 7. 配置 PostgreSQL 以偵聽網絡接口: 出于安全原因,PostgreSQL 默認情況下不偵聽任何網絡接口. 但是,Geo 要求**輔助**節點能夠連接到**主**節點的數據庫. 因此,我們需要每個節點的地址. **注意:**對于外部 PostgreSQL 實例,請參見[其他說明](external_database.html) . 如果使用的是云提供商,則可以通過云提供商的管理控制臺查找每個地理節點的地址. 要查找 Geo 節點的地址,請 SSH 到 Geo 節點并執行: ``` ## ## Private address ## ip route get 255.255.255.255 | awk '{print "Private address:", $NF; exit}' ## ## Public address ## echo "External address: $(curl --silent ipinfo.io/ip)" ``` 在大多數情況下,以下地址將用于配置 GitLab Geo: | Configuration | Address | | --- | --- | | `postgresql['listen_address']` | **主**節點的公用或 VPC 專用地址. | | `postgresql['md5_auth_cidr_addresses']` | **輔助**節點的公用或 VPC 專用地址. | 如果您使用的是 Google Cloud Platform,SoftLayer 或提供虛擬私有云(VPC)的任何其他供應商,則可以將**主**節點和**輔助**節點的私有地址(對應于 Google Cloud Platform 的"內部地址")用于`postgresql['md5_auth_cidr_addresses']`和`postgresql['listen_address']` . `listen_address`選項打開 PostgreSQL 直至與給定地址對應的接口的網絡連接. 有關更多詳細信息,請參見[PostgreSQL 文檔](https://s0www0postgresql0org.icopy.site/docs/11/runtime-config-connection.html) . 根據您的網絡配置,建議的地址可能不正確. 如果您的**主**節點和**輔助**節點通過局域網或連接可用性區域的虛擬網絡(例如[Amazon 的 VPC](https://aws.amazon.com/vpc/)或[Google 的 VPC)進行連接](https://cloud.google.com/vpc/) ,則應將**輔助**節點的私有地址用于`postgresql['md5_auth_cidr_addresses']` . 編輯`/etc/gitlab/gitlab.rb`并添加以下內容,將 IP 地址替換為適合您的網絡配置的地址: ``` ## ## Geo Primary role ## - configure dependent flags automatically to enable Geo ## roles ['geo_primary_role'] ## ## Primary address ## - replace '<primary_node_ip>' with the public or VPC address of your Geo primary node ## postgresql['listen_address'] = '<primary_node_ip>' ## # Allow PostgreSQL client authentication from the primary and secondary IPs. These IPs may be # public or VPC addresses in CIDR format, for example ['198.51.100.1/32', '198.51.100.2/32'] ## postgresql['md5_auth_cidr_addresses'] = ['<primary_node_ip>/32', '<secondary_node_ip>/32'] ## ## Replication settings ## - set this to be the number of Geo secondary nodes you have ## postgresql['max_replication_slots'] = 1 # postgresql['max_wal_senders'] = 10 # postgresql['wal_keep_segments'] = 10 ## ## Disable automatic database migrations temporarily ## (until PostgreSQL is restarted and listening on the private address). ## gitlab_rails['auto_migrate'] = false ``` 8. 可選:如果要添加另一個**輔助**節點,則相關設置應如下所示: ``` postgresql['md5_auth_cidr_addresses'] = ['<primary_node_ip>/32', '<secondary_node_ip>/32', '<another_secondary_node_ip>/32'] ``` 您可能還需要編輯`wal_keep_segments`和`max_wal_senders`以匹配您的數據庫復制要求. 有關更多信息,請查閱[PostgreSQL-復制文檔](https://s0www0postgresql0org.icopy.site/docs/11/runtime-config-replication.html) . 9. 保存文件并重新配置 GitLab,以進行數據庫偵聽更改和要應用的復制插槽更改: ``` gitlab-ctl reconfigure ``` 重新啟動 PostgreSQL 以使其更改生效: ``` gitlab-ctl restart postgresql ``` 10. 現在,重新啟動 PostgreSQL 并重新偵聽私有地址,即可重新啟用遷移. 編輯`/etc/gitlab/gitlab.rb`并將配置**更改**為`true` : ``` gitlab_rails['auto_migrate'] = true ``` 保存文件并重新配置 GitLab: ``` gitlab-ctl reconfigure ``` 11. 現在,PostgreSQL 服務器已設置為接受遠程連接,請運行`netstat -plnt | grep 5432` `netstat -plnt | grep 5432` ,以確保 PostgreSQL 在端口`5432`上偵聽**主**服務器的私有地址. 12. 重新配置 GitLab 時會自動生成一個證書. 這將自動用于保護 PostgreSQL 流量免遭竊聽,但是為了防止主動(中間人)攻擊者, **輔助**節點需要證書的副本. 通過運行以下命令,在**主**節點上復制 PostgreSQL `server.crt`文件: ``` cat ~gitlab-psql/data/server.crt ``` 將輸出復制到剪貼板或本地文件中. 設置**輔助**節點時將需要它! 證書不是敏感數據. ### Step 2\. Configure the **secondary** server[](#step-2-configure-the-secondary-server "Permalink") 1. SSH 到您的 GitLab **輔助**服務器并以 root 用戶身份登錄: ``` sudo -i ``` 2. 停止應用程序服務器和 Sidekiq ``` gitlab-ctl stop puma gitlab-ctl stop sidekiq ``` **注意:**此步驟很重要,因此在完全配置節點之前,我們不要嘗試執行任何操作. 3. [檢查](../../raketasks/maintenance.html)與**主**節點的 PostgreSQL 服務器的[TCP 連接](../../raketasks/maintenance.html) : ``` gitlab-rake gitlab:tcp_check[<primary_node_ip>,5432] ``` **注意:**如果此步驟失敗,則可能是您使用了錯誤的 IP 地址,或者防火墻可能阻止了對服務器的訪問. 檢查 IP 地址,并密切注意公用地址和專用地址之間的區別,并確保(如果存在防火墻)允許**次**節點連接到端口 5432 上的**主**節點. 4. 在**輔助**服務器上創建文件`server.crt` ,其中包含在**主**節點設置的最后一步中獲得的內容: ``` editor server.crt ``` 5. 在**輔助**節點上設置 PostgreSQL TLS 驗證: 安裝`server.crt`文件: ``` install \ -D \ -o gitlab-psql \ -g gitlab-psql \ -m 0400 \ -T server.crt ~gitlab-psql/.postgresql/root.crt ``` 現在,PostgreSQL 將僅在驗證 TLS 連接時識別該確切證書. 只能由有權訪問私鑰的人復制證書,該私鑰**僅存**在于**主**節點上. 6. 測試`gitlab-psql`用戶可以連接到**主**節點的數據庫(默認的 Omnibus 數據庫名稱為`gitlabhq_production` ): ``` sudo \ -u gitlab-psql /opt/gitlab/embedded/bin/psql \ --list \ -U gitlab_replicator \ -d "dbname=gitlabhq_production sslmode=verify-ca" \ -W \ -h <primary_node_ip> ``` 出現提示時,輸入您在第一步中為`gitlab_replicator`用戶設置的密碼. 如果所有方法均正常工作,則應該看到**主**節點數據庫的列表. 此處連接失敗表示 TLS 配置不正確. 確保**主**節點上`~gitlab-psql/data/server.crt`的內容與**輔助**節點上`~gitlab-psql/.postgresql/root.crt`的內容匹配. 7. 配置 PostgreSQL 以啟用 FDW 支持: 此步驟類似于我們配置**主**實例的方式. 我們需要啟用它,以啟用 FDW 支持,即使使用單個節點也是如此. 編輯`/etc/gitlab/gitlab.rb`并添加以下內容,將 IP 地址替換為適合您的網絡配置的地址: ``` ## ## Geo Secondary role ## - configure dependent flags automatically to enable Geo ## roles ['geo_secondary_role'] ## ## Secondary address ## - replace '<secondary_node_ip>' with the public or VPC address of your Geo secondary node ## postgresql['listen_address'] = '<secondary_node_ip>' postgresql['md5_auth_cidr_addresses'] = ['<secondary_node_ip>/32'] ## ## Database credentials password (defined previously in primary node) ## - replicate same values here as defined in primary node ## postgresql['sql_user_password'] = '<md5_hash_of_your_password>' gitlab_rails['db_password'] = '<your_password_here>' ## ## Enable FDW support for the Geo Tracking Database (improves performance) ## geo_secondary['db_fdw'] = true ``` 對于外部 PostgreSQL 實例,請參見[其他說明](external_database.html) . 如果您使以前的**主**節點重新聯機以用作**輔助**節點,則還需要刪除`roles ['geo_primary_role']`或`geo_primary_role['enable'] = true` . 8. 重新配置 GitLab,以使更改生效: ``` gitlab-ctl reconfigure ``` 9. 重新啟動 PostgreSQL 以使 IP 更改生效并再次重新配置: ``` gitlab-ctl restart postgresql gitlab-ctl reconfigure ``` 最后的重新配置將提供 FDW 配置并啟用它. ### Step 3\. Initiate the replication process[](#step-3-initiate-the-replication-process "Permalink") 在下面,我們提供了一個腳本,該腳本將**輔助**節點上的數據庫連接到**主要**節點上的數據庫,復制數據庫,并創建流復制所需的文件. 使用的目錄是在 Omnibus 中設置的默認目錄. 如果更改了任何默認值,請根據需要配置它,替換目錄和路徑. **警告:**確保在**輔助**服務器上運行此命令,因為它會在運行`pg_basebackup`之前刪除所有 PostgreSQL 的數據. 1. SSH 到您的 GitLab **輔助**服務器并以 root 用戶身份登錄: ``` sudo -i ``` 2. 選擇一個數據庫友好名稱,以供您的**輔助**節點用作復制插槽名稱. 例如,如果您的域是`secondary.geo.example.com` ,則可以使用`secondary_example`作為插槽名稱,如以下命令所示. 3. 執行以下命令以開始備份/還原并開始復制 **警告:**每個 Geo **輔助**節點必須具有自己的唯一復制插槽名稱. 在兩個輔助節點之間使用相同的插槽名稱將破壞 PostgreSQL 復制. ``` gitlab-ctl replicate-geo-database \ --slot-name=<secondary_node_name> \ --host=<primary_node_ip> ``` **注意:**復制插槽名稱只能包含小寫字母,數字和下劃線字符. 出現提示時,輸入第一步中為`gitlab_replicator`用戶設置的*純文本*密碼. 此命令還帶有許多其他選項. 您可以使用`--help`列出所有內容,但是這里有一些提示: * 如果 PostgreSQL 在非標準端口上偵聽,則還要添加`--port=` . * 如果數據庫太大而無法在 30 分鐘內傳輸,則需要增加超時,例如`--backup-timeout=3600`如果您希望初始復制花費一個小時以下的話. * 通過`--sslmode=disable`可以完全跳過 PostgreSQL TLS 身份驗證(例如,您知道網絡路徑是安全的,或者您使用的是站點到站點 VPN). 這**不是**通過公共互聯網安全! * 您可以在[PostgreSQL 文檔中](https://s0www0postgresql0org.icopy.site/docs/11/libpq-ssl.html)閱讀有關每個`sslmode`更多詳細信息; 上面的說明均經過精心編寫,以確保既能防御被動的竊聽者,又能防御主動的"中間人"攻擊者. * 將`--slot-name`更改為要在**主**數據庫上使用的復制插槽的名稱. 該腳本將嘗試自動創建復制插槽(如果不存在). * If you’re repurposing an old server into a Geo **secondary** node, you’ll need to add `--force` to the command line. * 如果不在生產機器中,則可以通過添加`--skip-backup`確保確實`--skip-backup`從而禁用備份步驟 復制過程現已完成. ## PgBouncer support (optional)[](#pgbouncer-support-optional "Permalink") [PgBouncer](https://www.pgbouncer.org/)可以與 GitLab Geo 一起使用來合并 PostgreSQL 連接. 如果您在高可用性配置中使用 GitLab,且該群集的節點集群支持 Geo **主**節點,而另一個節點集群支持 Geo **輔助**節點,則建議使用 PgBouncer. 有關更多信息,請參見[Omnibus GitLab 的高可用性](../../postgresql/replication_and_failover.html) . 為了使 Geo **輔助**節點能夠與數據庫前面的 PgBouncer 一起正常使用,它將需要一個單獨的只讀用戶才能使[PostgreSQL FDW 查詢](https://s0www0postgresql0org.icopy.site/docs/11/postgres-fdw.html)起作用: 1. 在**主要的**地理數據庫上,以管理員用戶身份在控制臺上輸入 PostgreSQL. 如果使用的是 Omnibus 管理的數據庫,請登錄到運行 PostgreSQL 數據庫的**主**節點(默認的 Omnibus 數據庫名稱為`gitlabhq_production` ): ``` sudo \ -u gitlab-psql /opt/gitlab/embedded/bin/psql \ -h /var/opt/gitlab/postgresql gitlabhq_production ``` 2. 然后創建只讀用戶: ``` -- NOTE: Use the password defined earlier CREATE USER gitlab_geo_fdw WITH password 'mypassword'; GRANT CONNECT ON DATABASE gitlabhq_production to gitlab_geo_fdw; GRANT USAGE ON SCHEMA public TO gitlab_geo_fdw; GRANT SELECT ON ALL TABLES IN SCHEMA public TO gitlab_geo_fdw; GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO gitlab_geo_fdw; -- Tables created by "gitlab" should be made read-only for "gitlab_geo_fdw" -- automatically. ALTER DEFAULT PRIVILEGES FOR USER gitlab IN SCHEMA public GRANT SELECT ON TABLES TO gitlab_geo_fdw; ALTER DEFAULT PRIVILEGES FOR USER gitlab IN SCHEMA public GRANT SELECT ON SEQUENCES TO gitlab_geo_fdw; ``` 3. 在**輔助**節點上,更改`/etc/gitlab/gitlab.rb` : ``` geo_postgresql['fdw_external_user'] = 'gitlab_geo_fdw' ``` 4. 保存文件并重新配置 GitLab 以應用更改: ``` gitlab-ctl reconfigure ``` ## Troubleshooting[](#troubleshooting "Permalink") 閱讀[故障排除文檔](troubleshooting.html) .
                  <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>

                              哎呀哎呀视频在线观看