使用apt-mirror搭建Ubuntu软件源的实例教程

2020-02-03 14:14:44王旭

deb [arch=amd64] http://自建源IP/archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse
deb [arch=amd64] http://自建源IP/archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse
deb [arch=amd64] http://自建源IP/archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse


复制代码
deb-src [arch=amd64] http://自建源IP/archive.ubuntu.com/ubuntu trusty main restricted universe multiverse
deb-src [arch=amd64] http://自建源IP/archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse
deb-src [arch=amd64] http://自建源IP/archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse
deb-src [arch=amd64] http://自建源IP/archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse
deb-src [arch=amd64] http://自建源IP/archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse


复制代码
# 配置MongoDB源
deb [arch=amd64] http://自建源IP/downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen

通过比较apt-mirror和source.list文件,其实就是把原有域名变成了一个目录。注意:以上客户端配置也多添加了[arch=amd64],用于指定架构,否则会出现

Err http://192.168.1.71 trusty/main i386 Packages
  404  Not Found
Err http://192.168.1.71 trusty/restricted i386 Packages
  404  Not Found
Err http://192.168.1.71 trusty/universe i386 Packages
  404  Not Found
...
类似错误,因为我的测试环境是x64,只同步了64位架构源,所以必须指定架构为64,现在客户端也无需i386的软件。
添加过source.list后,运行

复制代码
# sudo apt-get update

ubuntu部分正常更新,但是发现会出现以下错误提示

W: GPG error: http://192.168.1.111 dist Release:
 The following signatures couldn't be verified
 because the public key is not available: NO_PUBKEY 9ECBEC467F0CEB10
需要添加GPG key,添加某些package时,基本都需要添加GPG key,官方网站一般都会给出

复制代码
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

此时你就可以使用自建源安装软件啦~~
以下安装了MongoDB和htop来进行测试

复制代码
sudo apt-get install -y mongodb-org=2.6.5 htop