当我在 Amazon AWS 中配置 Ubuntu 14.04 时,我首先使用官方的 Canonical AMI(具体来说ami-f0c52390
),启动实例,然后运行配置脚本。脚本执行的第一件事之一是:
sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe restricted multiverse"
sudo apt-get update
sudo apt-get -y install python-dev python-virtualenv ruby
大多数情况下,这种方法效果很好。但有时,大概十分之一的情况,会出现apt-get install
以下错误:
$ sudo apt-get -y install python-dev python-virtualenv ruby
Reading package lists...
Building dependency tree...
Reading state information...
Package python-virtualenv is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
Package ruby is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
Package python-dev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
python
E: Package 'python-dev' has no installation candidate
E: Package 'python-virtualenv' has no installation candidate
E: Package 'ruby' has no installation candidate
如果我终止该实例并启动一个新实例——相同的 AMI、相同的 apt 源、相同的脚本,一切都一样,下次尝试时它通常就会起作用。
通常我可以通过观察 的输出来判断安装是否失败apt-get update
。成功运行和失败运行之间所使用的镜像明显不同。
好的:
$ sudo apt-get update
Ign http://us-west-2.ec2.archive.ubuntu.com trusty InRelease
Get:1 http://us-west-2.ec2.archive.ubuntu.com trusty-updates InRelease [65.9 kB]
Get:2 http://us-west-2.ec2.archive.ubuntu.com trusty-backports InRelease [65.9 kB]
Hit http://us-west-2.ec2.archive.ubuntu.com trusty Release.gpg
Hit http://security.ubuntu.com trusty-security InRelease
Ign http://archive.ubuntu.com trusty InRelease
Get:3 http://us-west-2.ec2.archive.ubuntu.com trusty-updates/main Sources [262 kB]
Get:4 http://us-west-2.ec2.archive.ubuntu.com trusty-updates/restricted Sources [5,352 B]
Get:5 http://archive.ubuntu.com trusty Release.gpg [933 B]
Get:6 http://security.ubuntu.com trusty-security/main Sources [106 kB]
Get:7 http://us-west-2.ec2.archive.ubuntu.com trusty-updates/universe Sources [151 kB]
Get:8 http://us-west-2.ec2.archive.ubuntu.com trusty-updates/multiverse Sources [5,946 B]
Get:9 http://us-west-2.ec2.archive.ubuntu.com trusty-updates/main amd64 Packages [713 kB]
Get:10 http://archive.ubuntu.com trusty Release [58.5 kB]
Get:11 http://us-west-2.ec2.archive.ubuntu.com trusty-updates/restricted amd64 Packages [15.9 kB]
Get:12 http://us-west-2.ec2.archive.ubuntu.com trusty-updates/universe amd64 Packages [339 kB]
Get:13 http://us-west-2.ec2.archive.ubuntu.com trusty-updates/multiverse amd64 Packages [13.2 kB]
Get:14 http://us-west-2.ec2.archive.ubuntu.com trusty-updates/main Translation-en [361 kB]
Get:15 http://us-west-2.ec2.archive.ubuntu.com trusty-updates/multiverse Translation-en [7,227 B]
Get:16 http://us-west-2.ec2.archive.ubuntu.com trusty-updates/restricted Translation-en [3,699 B]
Get:17 https://deb.nodesource.com trusty InRelease
Get:18 http://us-west-2.ec2.archive.ubuntu.com trusty-updates/universe Translation-en [182 kB]
Get:19 https://deb.nodesource.com trusty/main amd64 Packages
Get:20 http://us-west-2.ec2.archive.ubuntu.com trusty-backports/main Sources [8,661 B]
Get:21 http://us-west-2.ec2.archive.ubuntu.com trusty-backports/restricted Sources [28 B]
Get:22 https://deb.nodesource.com trusty/main Translation-en_US
Get:23 http://us-west-2.ec2.archive.ubuntu.com trusty-backports/universe Sources [34.0 kB]
Get:24 http://archive.ubuntu.com trusty/main amd64 Packages [1,350 kB]
Get:25 http://us-west-2.ec2.archive.ubuntu.com trusty-backports/multiverse Sources [1,898 B]
Get:26 http://us-west-2.ec2.archive.ubuntu.com trusty-backports/main amd64 Packages [9,787 B]
Get:27 http://us-west-2.ec2.archive.ubuntu.com trusty-backports/restricted amd64 Packages [28 B]
Get:28 http://us-west-2.ec2.archive.ubuntu.com trusty-backports/universe amd64 Packages [40.9 kB]
Get:29 http://us-west-2.ec2.archive.ubuntu.com trusty-backports/multiverse amd64 Packages [1,571 B]
Get:30 http://us-west-2.ec2.archive.ubuntu.com trusty-backports/main Translation-en [5,843 B]
Get:31 http://us-west-2.ec2.archive.ubuntu.com trusty-backports/multiverse Translation-en [1,215 B]
Ign https://deb.nodesource.com trusty/main Translation-en_US
Get:32 http://us-west-2.ec2.archive.ubuntu.com trusty-backports/restricted Translation-en [28 B]
Get:33 http://us-west-2.ec2.archive.ubuntu.com trusty-backports/universe Translation-en [35.5 kB]
Ign https://deb.nodesource.com trusty/main Translation-en
Hit http://us-west-2.ec2.archive.ubuntu.com trusty Release
Get:34 http://us-west-2.ec2.archive.ubuntu.com trusty/main Sources [1,064 kB]
Get:35 http://us-west-2.ec2.archive.ubuntu.com trusty/restricted Sources [5,433 B]
Get:36 http://us-west-2.ec2.archive.ubuntu.com trusty/universe Sources [6,399 kB]
Get:37 http://security.ubuntu.com trusty-security/universe Sources [34.0 kB]
Get:38 http://us-west-2.ec2.archive.ubuntu.com trusty/multiverse Sources [174 kB]
Hit http://us-west-2.ec2.archive.ubuntu.com trusty/main amd64 Packages
Hit http://us-west-2.ec2.archive.ubuntu.com trusty/restricted amd64 Packages
Hit http://us-west-2.ec2.archive.ubuntu.com trusty/universe amd64 Packages
Hit http://us-west-2.ec2.archive.ubuntu.com trusty/multiverse amd64 Packages
Hit http://security.ubuntu.com trusty-security/main amd64 Packages
Hit http://us-west-2.ec2.archive.ubuntu.com trusty/main Translation-en
Hit http://security.ubuntu.com trusty-security/universe amd64 Packages
Hit http://us-west-2.ec2.archive.ubuntu.com trusty/multiverse Translation-en
Hit http://us-west-2.ec2.archive.ubuntu.com trusty/restricted Translation-en
Hit http://security.ubuntu.com trusty-security/main Translation-en
Hit http://us-west-2.ec2.archive.ubuntu.com trusty/universe Translation-en
Hit http://security.ubuntu.com trusty-security/universe Translation-en
Ign http://us-west-2.ec2.archive.ubuntu.com trusty/main Translation-en_US
Ign http://us-west-2.ec2.archive.ubuntu.com trusty/multiverse Translation-en_US
Ign http://us-west-2.ec2.archive.ubuntu.com trusty/restricted Translation-en_US
Ign http://us-west-2.ec2.archive.ubuntu.com trusty/universe Translation-en_US
Get:39 http://archive.ubuntu.com trusty/universe amd64 Packages [5,859 kB]
Get:40 http://archive.ubuntu.com trusty/restricted amd64 Packages [13.0 kB]
Get:41 http://archive.ubuntu.com trusty/multiverse amd64 Packages [132 kB]
Get:42 http://archive.ubuntu.com trusty/main Translation-en [762 kB]
Get:43 http://archive.ubuntu.com trusty/multiverse Translation-en [102 kB]
Get:44 http://archive.ubuntu.com trusty/restricted Translation-en [3,457 B]
Get:45 http://archive.ubuntu.com trusty/universe Translation-en [4,089 kB]
Ign http://archive.ubuntu.com trusty/main Translation-en_US
Ign http://archive.ubuntu.com trusty/multiverse Translation-en_US
Ign http://archive.ubuntu.com trusty/restricted Translation-en_US
Ign http://archive.ubuntu.com trusty/universe Translation-en_US
Fetched 22.5 MB in 1min 36s (234 kB/s)
坏的:
$ sudo apt-get update
Ign http://archive.ubuntu.com trusty InRelease
Get:1 http://archive.ubuntu.com trusty-updates InRelease [65.9 kB]
Get:2 http://security.ubuntu.com trusty-security InRelease [65.9 kB]
Get:3 https://deb.nodesource.com trusty InRelease
Get:4 https://deb.nodesource.com trusty/main amd64 Packages
Hit http://archive.ubuntu.com trusty Release.gpg
Get:5 https://deb.nodesource.com trusty/main Translation-en
Get:6 http://archive.ubuntu.com trusty-updates/main amd64 Packages [713 kB]
Ign https://deb.nodesource.com trusty/main Translation-en
Get:7 http://archive.ubuntu.com trusty-updates/restricted amd64 Packages [15.9 kB]
Get:8 http://security.ubuntu.com trusty-security/main amd64 Packages [431 kB]
Get:9 http://archive.ubuntu.com trusty-updates/universe amd64 Packages [339 kB]
Get:10 http://archive.ubuntu.com trusty-updates/multiverse amd64 Packages [13.2 kB]
Get:11 http://archive.ubuntu.com trusty-updates/main Translation-en [361 kB]
Get:12 http://archive.ubuntu.com trusty-updates/multiverse Translation-en [7227 B]
Get:13 http://archive.ubuntu.com trusty-updates/restricted Translation-en [3699 B]
Get:14 http://archive.ubuntu.com trusty-updates/universe Translation-en [182 kB]
Get:15 http://archive.ubuntu.com trusty Release [58.5 kB]
Get:16 http://archive.ubuntu.com trusty/multiverse amd64 Packages [132 kB]
Get:17 http://security.ubuntu.com trusty-security/restricted amd64 Packages [13.0 kB]
Get:18 http://archive.ubuntu.com trusty/restricted amd64 Packages [13.0 kB]
Get:19 http://security.ubuntu.com trusty-security/universe amd64 Packages [125 kB]
Get:20 http://archive.ubuntu.com trusty/universe amd64 Packages [5859 kB]
Get:21 http://security.ubuntu.com trusty-security/multiverse amd64 Packages [4991 B]
Get:22 http://security.ubuntu.com trusty-security/main Translation-en [236 kB]
Get:23 http://security.ubuntu.com trusty-security/multiverse Translation-en [2570 B]
Get:24 http://security.ubuntu.com trusty-security/restricted Translation-en [3206 B]
Get:25 http://archive.ubuntu.com trusty/main amd64 Packages [1350 kB]
Get:26 http://security.ubuntu.com trusty-security/universe Translation-en [73.8 kB]
Get:27 http://archive.ubuntu.com trusty/main Translation-en [762 kB]
Get:28 http://archive.ubuntu.com trusty/multiverse Translation-en [102 kB]
Get:29 http://archive.ubuntu.com trusty/restricted Translation-en [3457 B]
Get:30 http://archive.ubuntu.com trusty/universe Translation-en [4089 kB]
Fetched 15.0 MB in 8s (1814 kB/s)
这是怎么回事?我有时会遇到坏镜像吗?实例的网络可能没有完全启动吗?为什么这种行为是不确定的,并且总是可以通过在新实例上再次尝试脚本来修复?