linglong/docs/mirrors.md

3.0 KiB
Raw Permalink Blame History

玲珑仓库 mirror 功能设计

在ll-cli和ll-builder中添加了enable-mirror和disable-mirror命令用于启用和禁用镜像功能。

在对某个仓库启用mirror功能时会更新ostree的config文件添加contenturl配置项

url=$repo_url/repos/$repo_name
gpg-verify=false
http2=false
+ contenturl=mirrorlist=$repo_url/api/v2/mirrors/$repo_name

当添加contenturl配置项后ostree会优先使用contenturl下载静态文件如files, url仅用于获取元数据如summary, contenturl支持file://、http://、https://三种协议

如果在url前面添加mirrorlist=则ostree会先从url获取按行分割的镜像列表然后从镜像列表中选择镜像用于下载文件具体逻辑见 ostree_pull 章节。

/api/v2/mirrors/$repo_name 是玲珑服务器的一个API接口通过客户端IP获取客户端所在国家从配置文件获取对应国家的镜像列表然后返回给ostree这样就实现了根据用户所在国家自动分流仓库文件下载的功能更。

镜像站配置

玲珑的镜像站只提供仓库静态文件的https访问即可玲珑仓库支持rsync和ostree两种同步协议。

使用 rsync 同步配置

优点是同步速度快缺点是需从支持rsync协议的镜像站或官方仓库同步仓库。

rsync rsync://rsync.linyaps.org.cn/repos/stable $www_root/repos/stable

使用 ostree 同步配置

优点是无需协议支持,可从任意镜像站同步仓库,缺点是同步速度较慢。

保存下面脚本,并命名为 sync.sh然后执行sh sync.sh https://mirror-repo-linglong.deepin.com/repos/stable/ $www_root/repos/stable

#!/bin/bash
set -e
url=$1
dir=$2
echo sync $url to $dir
sleep 3
ostree init --repo=$dir --mode archive
ostree --repo=$dir remote add --if-not-exists --no-sign-verify remote $url
for ref in $(ostree --repo=$dir remote refs remote); do
    echo pull $ref;
    ostree --repo=$dir pull --mirror $ref;
done

ostree pull 步骤

判断镜像是否可用

在pull时ostree 先从contenturl获取镜像列表然后从每个url获取/config文件如果获取不到/config文件则认为该mirror不可用如果获取到/config文件则认为该mirror可用。如果没有可用mirrorpull失败。

获取summary文件

ostree会从url获取summary文件如果获取不到summary文件或者summary文件不存在refpull失败。

delta-indexes文件获取

ostree会在每个可用的mirror中获取delta-indexes如果mirror服务器返回4xx或5xx则在下一个mirror中获取delta-indexes如果最后的mirror返回5xx则pull失败如果最后的mirror返回4xx则跳过dalta步骤直接拉取files。

files文件获取

ostree会按顺序从可用的mirror中获取files如果mirror服务器返回403, 404 410则认为错误不可恢复pull失败如果mirror服务器返回其他错误码则使用下一个mirror获取files。如果所有mirror都无法获取files则pull失败。