Skip to main content

此版本的 GitHub Enterprise 将停止服务 2023-01-18. 即使针对重大安全问题,也不会发布补丁。 为了获得更好的性能、更高的安全性和新功能,请升级到最新版本的 GitHub Enterprise。 如需升级帮助,请联系 GitHub Enterprise 支持

Configuring a repository cache

You can configure a repository cache for GitHub Enterprise Server by creating a new instance, connecting the repository cache to your primary instance, and configuring replication of repository networks to the repository cache.

Note: Repository caching is currently in beta and subject to change.

About configuration for repository caching

可以通过创建名为“存储库缓存”的特殊类型的副本来配置存储库缓存。 Then, you can set data location policies that govern which repository networks are replicated to the repository cache.

Repository caching is not supported with clustering.

DNS for repository caches

The primary instance and repository cache should have different DNS names. For example, if your primary instance is at github.example.com, you might decide to name a cache europe-ci.github.example.com or github.asia.example.com.

To have your CI machines fetch from the repository cache instead of the primary instance, you can use Git's url.<base>.insteadOf configuration setting. For more information, see git-config in the Git documentation.

For example, the global .gitconfig for the CI machine would include these lines.

[url "https://europe-ci.github.example.com/"]
	insteadOf = https://github.example.com/

Then, when told to fetch https://github.example.com/myorg/myrepo, Git will instead fetch from https://europe-ci.github.example.com/myorg/myrepo.

Configuring a repository cache

  1. SSH into your GitHub Enterprise Server instance. If your instance comprises multiple nodes, for example if high availability or geo-replication are configured, SSH into the primary node. If you use a cluster, you can SSH into any node. For more information about SSH access, see "Accessing the administrative shell (SSH)."

    $ ssh -p 122 admin@HOSTNAME
  2. To enable repository caching, run the following command.

    $ ghe-config cluster.cache-enabled true
    
  3. Set up a new GitHub Enterprise Server instance on your desired platform. This instance will be your repository cache. For more information, see "Setting up a GitHub Enterprise Server instance."

  4. 设置与主设备密码匹配的管理员密码,然后继续。

  5. 单击“配置为副本”。 包含用于将新实例配置为副本的链接的安装选项

  6. 在“Add new SSH key”下,输入 SSH 密钥。 添加 SSH 密钥

  7. 单击“添加密钥”。

  8. Connect to the repository cache's IP address using SSH.

    $ ssh -p 122 admin@REPLICA-IP
  9. On your cache replica, enable the feature flag for repository caching.

    $ ghe-config cluster.cache-enabled true
    
  10. 要为副本生成密钥对,请使用包含主设备 IP 地址的 ghe-repl-setup 命令,并复制该命令返回的公钥。

    $ ghe-repl-setup PRIMARY IP
  11. 若要将公钥添加到主设备上的授权密钥列表中,请浏览到 https://PRIMARY-HOSTNAME/setup/settings 并将从副本复制的密钥添加到列表中。

  12. To verify the connection to the primary and enable replica mode for the repository cache, run ghe-repl-setup again.

    $ ghe-repl-setup PRIMARY-IP
  13. Set a cache-location for the repository cache, replacing CACHE-LOCATION with an alphanumeric identifier, such as the region where the cache is deployed. Also set a datacenter name for this cache; new caches will attempt to seed from another cache in the same datacenter.

    $ ghe-repl-node --cache CACHE-LOCATION --datacenter REPLICA-DC-NAME
  14. 要开始复制数据存储,请使用 ghe-repl-start 命令。

    $ ghe-repl-start

    警告:ghe-repl-start 会导致主服务器短暂中断,在此期间用户可能会看到内部服务器错误。 要提供更简便的消息,请先在主节点上运行 ghe-maintenance -s,然后再在副本节点上运行 ghe-repl-start,以将设备置于维护模式。 复制开始后,使用 ghe-maintenance -u 禁用维护模式。 当主节点处于维护模式时,Git 复制将无法进行。

  15. 要验证各个数据存储复制通道的状态,请使用 ghe-repl-status 命令。

    $ ghe-repl-status
  16. To enable replication of repository networks to the repository cache, set a data location policy. For more information, see "Data location policies."

Data location policies

You can control data locality by configuring data location policies for your repositories with the spokesctl cache-policy command. Data location policies determine which repository networks are replicated on which repository caches. By default, no repository networks will be replicated on any repository caches until a data location policy is configured.

Data location policies affect only Git content. Content in the database, such as issues and pull request comments, will be replicated to all nodes regardless of policy.

Note: Data location policies are not the same as access control. You must use repository roles to control which users may access a repository. For more information about repository roles, see "Repository roles for an organization."

You can configure a policy to replicate all networks with the --default flag. For example, this command will create a policy to replicate a single copy of every repository network to the set of repository caches whose cache_location is "kansas".

$ ghe-spokesctl cache-policy set --default 1 kansas

To configure replication for a repository network, specify the repository that is the root of the network. A repository network includes a repository and all of the repository's forks. You cannot replicate part of a network without replicating the whole network.

$ ghe-spokesctl cache-policy set <owner/repository> 1 kansas

You can override a policy that replicates all networks and exclude specific networks by specifying a replica count of zero for the network. For example, this command specifies that any repository cache in location "kansas" cannot contain any copies of that network.

$ ghe-spokesctl cache-policy set <owner/repository> 0 kansas

Replica counts greater than one in a given cache location are not supported.