启动后直接执行 apt-get update 会导致多次 Ign 和 Hit,从而导致“无安装候选”错误

启动后直接执行 apt-get update 会导致多次 Ign 和 Hit,从而导致“无安装候选”错误

我在使用结构脚本引导 EC2 上的服务器时遇到了一个奇怪的问题。

我启动了原装的 Ubuntu 12.04 AMI (ami-3d4ff254),等待它启动,然后继续:

with settings(host_string="ubuntu@%s" % i.dns_name, 
              connection_attempts=30):
    sudo('apt-get -qy update')
    sudo('apt-get -qy install --no-install-recommends mdadm') # don't install postfix
    #etc...

似乎apt-get update运行正常并且没有错误,但是(大约 2/3 的时间)安装mdadm会引发“无安装候选项”错误。

当我通过 ssh 进入服务器并运行时,apt-get install mdadm我收到相同的错误。apt-get update手动运行,然后包安装正常。

对于可能发生的事情有什么想法,或者调试的想法吗?


编辑:事实证明,sleep(10)在 SSH 服务器启动后尝试之前添加一个apt-get update,效果很好。这似乎是此 AMI 上的 apt 配置问题,可能还与 Amazon 方面存在一些异常,或 DNS 问题有关。

以下是我的参赛作品/etc/apt/sources.list

deb http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ precise main
deb-src http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ precise main
deb http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ precise-updates main
deb-src http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ precise-updates main
deb http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ precise universe
deb-src http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ precise universe
deb http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ precise-updates universe
deb-src http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ precise-updates universe
deb http://security.ubuntu.com/ubuntu precise-security main
deb-src http://security.ubuntu.com/ubuntu precise-security main
deb http://security.ubuntu.com/ubuntu precise-security universe
deb-src http://security.ubuntu.com/ubuntu precise-security universe

apt-get update以下是搞砸我的安装的输出mdadm

Ign http://security.ubuntu.com precise-security InRelease
Get:1 http://security.ubuntu.com precise-security Release.gpg [198 B]
Ign http://archive.ubuntu.com precise InRelease
Get:2 http://security.ubuntu.com precise-security Release [49.6 kB]
Ign http://archive.ubuntu.com precise-updates InRelease
Hit http://archive.ubuntu.com precise Release.gpg
Get:3 http://archive.ubuntu.com precise-updates Release.gpg [198 B]
Hit http://archive.ubuntu.com precise Release
Get:4 http://security.ubuntu.com precise-security/main amd64 Packages [177 kB]
Get:5 http://archive.ubuntu.com precise-updates Release [49.6 kB]
Hit http://archive.ubuntu.com precise/main amd64 Packages
Hit http://archive.ubuntu.com precise/restricted amd64 Packages
Hit http://archive.ubuntu.com precise/universe amd64 Packages
Hit http://archive.ubuntu.com precise/multiverse amd64 Packages
Hit http://archive.ubuntu.com precise/main i386 Packages
Hit http://archive.ubuntu.com precise/restricted i386 Packages
Hit http://archive.ubuntu.com precise/universe i386 Packages
Hit http://archive.ubuntu.com precise/multiverse i386 Packages
Get:6 http://security.ubuntu.com precise-security/restricted amd64 Packages [3,969 B]
Hit http://archive.ubuntu.com precise/main TranslationIndex
Get:7 http://security.ubuntu.com precise-security/universe amd64 Packages [48.6 kB]
Hit http://archive.ubuntu.com precise/multiverse TranslationIndex
Get:8 http://security.ubuntu.com precise-security/multiverse amd64 Packages [2,188 B]
Get:9 http://security.ubuntu.com precise-security/main i386 Packages [183 kB]
Hit http://archive.ubuntu.com precise/restricted TranslationIndex
Get:10 http://archive.ubuntu.com precise/universe TranslationIndex [2,922 B]
Get:11 http://archive.ubuntu.com precise-updates/main amd64 Packages [405 kB]
Get:12 http://security.ubuntu.com precise-security/restricted i386 Packages [3,968 B]
Get:13 http://security.ubuntu.com precise-security/universe i386 Packages [48.7 kB]
Get:14 http://security.ubuntu.com precise-security/multiverse i386 Packages [2,357 B]
Get:15 http://security.ubuntu.com precise-security/main TranslationIndex [73 B]
Get:16 http://security.ubuntu.com precise-security/multiverse TranslationIndex [71 B]
Get:17 http://security.ubuntu.com precise-security/restricted TranslationIndex [71 B]
Get:18 http://security.ubuntu.com precise-security/universe TranslationIndex [73 B]
Get:19 http://archive.ubuntu.com precise-updates/restricted amd64 Packages [8,215 B]
Get:20 http://archive.ubuntu.com precise-updates/universe amd64 Packages [149 kB]
Get:21 http://security.ubuntu.com precise-security/main Translation-en [86.5 kB]
Get:22 http://archive.ubuntu.com precise-updates/multiverse amd64 Packages [8,948 B]
Hit http://security.ubuntu.com precise-security/multiverse Translation-en
Get:23 http://archive.ubuntu.com precise-updates/main i386 Packages [410 kB]
Hit http://security.ubuntu.com precise-security/restricted Translation-en
Get:24 http://security.ubuntu.com precise-security/universe Translation-en [30.3 kB]
Get:25 http://archive.ubuntu.com precise-updates/restricted i386 Packages [8,218 B]
Get:26 http://archive.ubuntu.com precise-updates/universe i386 Packages [149 kB]
Get:27 http://archive.ubuntu.com precise-updates/multiverse i386 Packages [9,930 B]
Get:28 http://archive.ubuntu.com precise-updates/main TranslationIndex [3,564 B]
Get:29 http://archive.ubuntu.com precise-updates/multiverse TranslationIndex [2,605 B]
Get:30 http://archive.ubuntu.com precise-updates/restricted TranslationIndex [2,461 B]
Get:31 http://archive.ubuntu.com precise-updates/universe TranslationIndex [2,850 B]
Get:32 http://archive.ubuntu.com precise/main Translation-en [726 kB]
Get:33 http://archive.ubuntu.com precise/multiverse Translation-en [93.4 kB]
Get:34 http://archive.ubuntu.com precise/restricted Translation-en [2,395 B]
Get:35 http://archive.ubuntu.com precise/universe Translation-en [3,341 kB]
Get:36 http://archive.ubuntu.com precise-updates/main Translation-en [202 kB]
Get:37 http://archive.ubuntu.com precise-updates/multiverse Translation-en [5,606 B]
Get:38 http://archive.ubuntu.com precise-updates/restricted Translation-en [2,048 B]
Get:39 http://archive.ubuntu.com precise-updates/universe Translation-en [87.4 kB]
Ign http://archive.ubuntu.com precise/main Translation-en_US
Ign http://archive.ubuntu.com precise/multiverse Translation-en_US
Ign http://archive.ubuntu.com precise/restricted Translation-en_US
Fetched 6,308 kB in 8s (786 kB/s)
Reading package lists...

下面是有效操作的输出(即等待几秒钟后再执行apt-get update):

Ign http://us-east-1.ec2.archive.ubuntu.com precise InRelease
Ign http://us-east-1.ec2.archive.ubuntu.com precise-updates InRelease
Get:1 http://us-east-1.ec2.archive.ubuntu.com precise Release.gpg [198 B]
Get:2 http://us-east-1.ec2.archive.ubuntu.com precise-updates Release.gpg [198 B]
Get:3 http://us-east-1.ec2.archive.ubuntu.com precise Release [49.6 kB]
Ign http://security.ubuntu.com precise-security InRelease
Get:4 http://us-east-1.ec2.archive.ubuntu.com precise-updates Release [49.6 kB]
Get:5 http://security.ubuntu.com precise-security Release.gpg [198 B]
Get:6 http://us-east-1.ec2.archive.ubuntu.com precise/main Sources [934 kB]
Get:7 http://security.ubuntu.com precise-security Release [49.6 kB]
Get:8 http://us-east-1.ec2.archive.ubuntu.com precise/universe Sources [5,019 kB]
Get:9 http://us-east-1.ec2.archive.ubuntu.com precise/main amd64 Packages [1,273 kB]
Get:10 http://security.ubuntu.com precise-security/main Sources [50.1 kB]
Get:11 http://us-east-1.ec2.archive.ubuntu.com precise/universe amd64 Packages [4,786 kB]
Get:12 http://security.ubuntu.com precise-security/universe Sources [14.5 kB]
Get:13 http://security.ubuntu.com precise-security/main amd64 Packages [177 kB]
Get:14 http://us-east-1.ec2.archive.ubuntu.com precise/main i386 Packages [1,274 kB]
Get:15 http://security.ubuntu.com precise-security/universe amd64 Packages [48.6 kB]
Get:16 http://us-east-1.ec2.archive.ubuntu.com precise/universe i386 Packages [4,796 kB]
Get:17 http://security.ubuntu.com precise-security/main i386 Packages [183 kB]
Get:18 http://us-east-1.ec2.archive.ubuntu.com precise/main TranslationIndex [3,706 B]
Get:19 http://us-east-1.ec2.archive.ubuntu.com precise/universe TranslationIndex [2,922 B]
Get:20 http://us-east-1.ec2.archive.ubuntu.com precise-updates/main Sources [178 kB]
Get:21 http://security.ubuntu.com precise-security/universe i386 Packages [48.7 kB]
Get:22 http://us-east-1.ec2.archive.ubuntu.com precise-updates/universe Sources [60.2 kB]
Get:23 http://security.ubuntu.com precise-security/main TranslationIndex [73 B]
Get:24 http://us-east-1.ec2.archive.ubuntu.com precise-updates/main amd64 Packages [405 kB]
Get:25 http://us-east-1.ec2.archive.ubuntu.com precise-updates/universe amd64 Packages [149 kB]
Get:26 http://security.ubuntu.com precise-security/universe TranslationIndex [73 B]
Get:27 http://security.ubuntu.com precise-security/main Translation-en [86.5 kB]
Get:28 http://security.ubuntu.com precise-security/universe Translation-en [30.3 kB]
Get:29 http://us-east-1.ec2.archive.ubuntu.com precise-updates/main i386 Packages [410 kB]
Get:30 http://us-east-1.ec2.archive.ubuntu.com precise-updates/universe i386 Packages [149 kB]
Get:31 http://us-east-1.ec2.archive.ubuntu.com precise-updates/main TranslationIndex [3,564 B]
Get:32 http://us-east-1.ec2.archive.ubuntu.com precise-updates/universe TranslationIndex [2,850 B]
Get:33 http://us-east-1.ec2.archive.ubuntu.com precise/main Translation-en [726 kB]
Get:34 http://us-east-1.ec2.archive.ubuntu.com precise/universe Translation-en [3,341 kB]
Get:35 http://us-east-1.ec2.archive.ubuntu.com precise-updates/main Translation-en [202 kB]
Get:36 http://us-east-1.ec2.archive.ubuntu.com precise-updates/universe Translation-en [87.4 kB]
Fetched 24.6 MB in 12s (1,976 kB/s)
Reading package lists...

我不知道为什么前者充满了更多的Hits和Igns。

答案1

如果没有更深入的测试(我现在不打算这么做),很难说确切地发生了什么事,但总体情况是:

当您首次在 EC2 上启动 Ubuntu 云实例时,会运行一个脚本,该脚本会针对 EC2 环境对其进行一些自定义。其中一件事是,您的脚本/etc/apt/sources.list被重写以指向托管在 Amazon S3 中的 Ubuntu 镜像(这意味着您无需为安装/更新软件支付带宽费用)。

我的猜测是,亚马逊档案和一般档案之间存在一些微妙的差异,导致了您所看到的奇怪现象;经过更多的测试和探索,您可能会发现它到底是什么。

我为了让您的部署脚本正常工作,建议等到 Ubuntu 的所有初始化工作完成后再运行您自己的脚本。

相关内容