ubuntu的apt-get镜像配置

771 阅读2分钟

apt的工作原理

Ubuntu采用集中式的软件仓库机制,将各式各样的软件包分门别类地存放在软件仓库中,进行有效地组织和管理。然后,将软件仓库置于许许多多的镜像服务器中,并保持基本一致。这样,所有的Ubuntu用户随时都能获得最新版本的安装软件包。因此,对于用户,这些镜像服务器就是他们的软件源(Reposity)。

然而,由于每位用户所处的网络环境不同,不可能随意地访问各镜像站点。为了能够有选择地访问,在Ubuntu系统中,使用软件源配置文件/etc/apt/sources.list列出最合适访问的镜像站点地址。

执行apt-get update ,程序分析/etc/apt/sources.list,自动连网寻找list中对应的Packages/Sources/Release列表文件,如果有更新则下载之,存入/var/lib/apt/lists/目录
然后 apt-get install 相应的包 ,下载并安装。

使用“apt-get install”下载软件包大体分为4步:第一步,扫描本地存放的软件包更新列表(由“apt-get update”命令刷新更新列表,也就是/var/lib/apt/lists/),找到最新版本的软件包;第二步,进行软件包依赖关系检查,找到支持该软件正常运行的所有软件包;第三步,从软件源所指 的镜像站点中,下载相关软件包;第四步,解压软件包,并自动完成应用程序的安装和配置。

apt-get的软件源配置

有很多的镜像,我使用的是aliyun的软件源,在/etc/apt/sources.list中配置 developer.aliyun.com/article/704…

deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

apt的代理服务器

可以使用gost工具,mac直接brew install gost。建议在本机自建代理、供虚拟机访问.

  1. 在本机(如mbp)启动代理:

    • gost -L "http://:8118/192.168.112.133:8118"-> 在 8118 端口启动一个http代理
    • 建议使用 screen -dmS proxy /path/to/gost -L "http://:8118" 在后台启动代理
    • 放在crontab里效果更佳: */10 * * * * screen -dmS ...
  2. 在虚拟机中的~/.bashrc文件中添加

function Proxy() {
    ip=${SSH_CLIENT/ */}
    if [ "$1" == "on" ]; then
        export https_proxy=$ip:8118
        export http_proxy=$ip:8118
        echo Proxy On
    else
        unset https_proxy
        unset http_proxy
        echo Proxy Off
    fi
}

📄复制

$SSH_CLIENT 是一个环境变量,存的是提供代理的ip地址,在这里就是mbp的ip地址。如ip=192.168.0.101。 使用source ~/.bashrc 保存配置文件。 使用Proxy on打开代理。 3. 在虚拟机的/etc/apt/apt.conf中添加配置

Acquire::http::Proxy "http://192.168.0.101:8118";
Acquire::https::Proxy "http://192.168.0.101:8118";

文章首发: zerlina-ysl.github.io/posts/blog/…

开启掘金成长之旅!这是我参与「掘金日新计划 · 2 月更文挑战」的第 27 天,点击查看活动详情