⚠️ 注意:Snap 应用运行在沙箱中,默认不使用系统或终端环境变量(如 http_proxy),因此必须通过 snap set system proxy.* 显式配置 。

## 官方方法,个人用途时,据说麻烦。
snap-store-proxy
snap-store-proxy-client
sudo snap set system proxy.http="http://<proxy-ip>:<port>"
sudo snap set system proxy.https="http://<proxy-ip>:<port>"

       

----------------------------------------------------------

关联参考:

snap 更换国内镜像源 proxy.httpX / proxy.store :“镜像源”并非传统意义上的完整克隆,而是通过 ‌HTTP/HTTPS 代理机制‌ 实现流量中转 (***)  https://blog.csdn.net/ken2232/article/details/159351886 

(aaa-) snap 不走系统代理,也不走终端的代理?:ubuntu官方:snap-store-proxy 的使用方法 (***)  https://blog.csdn.net/ken2232/article/details/159355049 

(-aa-) 必要性:snap 关闭自动更新,snap包离线下载与安装的方法 (****)  https://blog.csdn.net/ken2232/article/details/159348171?spm=1011.2415.3001.5331 

multipass 虚拟机 离线安装  https://blog.csdn.net/ken2232/article/details/159321099?spm=1011.2415.3001.5331  

Snap 包的下载和离线安装方法  https://blog.csdn.net/ken2232/article/details/159215254?spm=1011.2415.3001.5331 

=================================

snap-store-proxy -h

usage: snap-proxy [-h] [-d] COMMAND ...

A smart caching proxy for the Snap Store

options:
  -h, --help            show this help message and exit
  -d, --debug           show debug logs and stacktraces

  COMMAND
    add-admin           Add a proxy admin
    check-connections   Run conn-check to test outgoing connections to
                        services
    config              Read or update the snap store proxy configuration.
    create-database     Create the database
    delete-override     Delete channel map overrides
    disable-airgap-mode
                        Disable airgapped operations
    enable-airgap-mode  Enable airgapped operations
    fetch-account-keys  Fetch account keys for brand devices authentication in
                        airgap mode. These should be Snap Store registered
                        account keys for the brand account, used to sign brand
                        device models and serial assertions.
    fetch-brand-store-metadata
                        Download brand store metadata for import into an
                        airgapped proxy. `snapcraft export-login --acls
                        store_admin` exported authentication file is needed.
    fetch-snaps         Download a list of snaps including blobs and
                        assertions
    generate-keys       Generate proxy keys
    import-certificate  Load TLS certificates securely
    list-overrides      List channel map overrides
    list-pushed-snaps   List snaps pushed to this air-gapped store
    make-offline-install
                        Prepare a bundle for offline installation
    migrate             Run DB migrations for internal services
    override            Set channel map overrides
    push-account-keys   Import account keys for brand devices authentication
                        in airgap mode. These keys are obtained using the
                        fetch-account-keys command on a machine with internet
                        access and then imported into an airgap proxy.
    push-brand-store-metadata
                        Import brand store metadata into this airgapped proxy.
                        The metadata file is obtained using `snap-proxy fetch-
                        brand-store-metadata`.
    push-charm-bundle   Push an exported charm bundle to the air-gapped
                        Charmhub
    push-charms         Push exported charms to the air-gapped Charmhub
    push-snap           Push a snap to this air-gapped store
    push-store          Import a store admin account into this airgapped
                        proxy. The metadata file is obtained using `store-
                        admin export store`.
    register            Register the store
    remove-admin        Remove a proxy admin
    remove-ca-certs     Remove CA certificate bundle
    reregister          Clear the store id and rerun register with the same
                        args
    status (registration)
                        Get the status of this store
    use-ca-certs        Import CA certificate bundle from stdin (PEM format)

snap-store-proxy 与 snap-store-proxy-client 分别是什么用途?它们的原理是什么?

在 Ubuntu 系统中,‌snap-store-proxy‌ 和 ‌snap-store-proxy-client‌ 是用于优化 Snap 软件包下载体验的工具,尤其适用于网络环境受限(如国内访问海外 Snap Store 缓慢)或需要在局域网内共享缓存、节省带宽的场景。


‌用途说明‌

  • ‌snap-store-proxy‌
    是一个‌代理服务器组件‌,运行在本地或内网服务器上,用于缓存从官方 Snap Store(api.snapcraft.io)下载的 Snap 包和元数据。其他设备(客户端)可通过配置指向该代理,复用已下载的内容,避免重复下载,从而提升安装速度并减少外网流量消耗 ‌6。
  • ‌snap-store-proxy-client‌
    是‌客户端组件‌,用于帮助客户端系统自动发现并连接到本地的 snap-store-proxy 服务。它简化了客户端配置过程,但实际使用中效果有限,官方更推荐直接通过命令行手动设置代理 ‌212。

​ 在Ubuntu上使用snap set system命令配置Snap系统全局代理-开发者社区-阿里云阿里云.​

​

​ Ubuntu Snap商店代理设置方法CSDN软件开发网​

​

‌工作原理‌

  1. ‌代理端(snap-store-proxy)‌
  • 部署在可稳定访问 Snap Store 的机器上(如企业内网或海外 VPS)。
  • 首次收到客户端请求时,从官方 Snap Store 下载所需 ​​.snap​​ 或断言文件,并缓存到本地。
  • 后续相同请求直接返回缓存内容,无需再次外联 ‌6。
  1. ‌客户端(snap-store-proxy-client)‌
  • 理论上应自动配置系统使用本地代理,但实际测试中常无效 ‌212。
  • 更可靠的方式是‌手动设置系统代理‌:
sudo snap set system proxy.http="http://<proxy-ip>:<port>"
sudo snap set system proxy.https="http://<proxy-ip>:<port>"
  • 设置后,所有 snap 命令和 Snap Store 的请求都将通过指定代理转发 ‌。

⚠️ 注意:Snap 应用运行在沙箱中,默认不使用系统或终端环境变量(如 ​​http_proxy​​),因此必须通过 ​​snap set system proxy.*​​ 显式配置 ‌。


‌典型使用场景‌

  • 国内用户因网络延迟导致 ​​snap install​​ 缓慢。
  • 多台 Linux 主机组成局域网,需避免重复下载相同 Snap 包 ‌6。
  • 离线或弱网环境部署统一软件环境。

‌推荐做法‌

由于 ​​snap-store-proxy-client​​ 实用性有限,‌优先采用手动配置方式‌:

# 设置代理(示例使用本地代理)
sudo snap set system proxy.http="http://192.168.1.100:8080"
sudo snap set system proxy.https="http://192.168.1.100:8080"

# 取消代理
sudo snap set system proxy.http=""
sudo snap set system proxy.https=""

如需搭建完整的代理服务,请参考 ​​Ubuntu 官方指南​​ ‌。

更多推荐