Amazon EC2实例无法更新或使用yum

And*_*son 41 yum amazon-ec2 amazon-web-services

我正在使用亚马逊的教程来安装LAMP服务器.前几个指令涉及使用yum,但我试图做的每一种方式都产生了相同的消息.我最近发现了一些关于同一问题的问题,这些问题都没有改变我的设置.

这是消息:

Loaded plugins: priorities, update-motd, upgrade-helper
Could not retrieve mirrorlist http://repo.us-east-1.amazonaws.com/latest/main/mirror.list error was
12: Timeout on http://repo.us-east-1.amazonaws.com/latest/main/mirror.list: (28, 'Connection timed out after 10001 milliseconds')


One of the configured repositories failed (Unknown),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:

 1. Contact the upstream for the repository and get them to fix the problem.

 2. Reconfigure the baseurl/etc. for the repository, to point to a working
    upstream. This is most often useful if you are using a newer
    distribution release than is supported by the repository (and the
    packages for the previous distribution release still work).

 3. Disable the repository, so yum won't use it by default. Yum will then
    just ignore the repository until you permanently enable it again or use
    --enablerepo for temporary usage:

        yum-config-manager --disable <repoid>

 4. Configure the failing repository to be skipped, if it is unavailable.
    Note that yum will try to contact the repo. when it runs most commands,
    so will have to try and fail each time (and thus. yum will be be much
    slower). If it is a very temporary problem though, this is often a nice
    compromise:

        yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

 Cannot find a valid baseurl for repo: amzn-main/latest
Run Code Online (Sandbox Code Playgroud)

我之前做过同样的事情,没有遇到任何问题,使用相同的教程,但是几个月前.我不知道发生了什么变化,但我微薄的经历让我无法搞清楚.

小智 38

看起来主机在联系yum服务器时遇到问题.确保实例具有出站Internet访问权限(检查安全组等).如果实例位于VPC中并且安全组看起来很好,则可能需要使用nat设备或附加弹性IP.

祝好运-

  • 在我的情况下,我在创建实例时取消选中"自动为您的实例分配公共IP地址". (3认同)
  • 除了Chadneal的答案。如果您创建了一个自定义/新安全组,请检查并配置实例的出站流量。 (2认同)
  • 没有出站互联网接入 (2认同)

phi*_*son 17

如果您的VPC上有S3端点,那么这将导致yum失败,因为repo文件存储在S3中.要解决此问题,请将以下策略添加到S3:

{
"Version": "2012-10-17",
"Statement": [
    {
        "Effect": "Allow",
        "Principal": "*",
        "Action": "*",
        "Resource": [
            "arn:aws:s3:::repo.eu-west-1.amazonaws.com",
            "arn:aws:s3:::repo.eu-west-1.amazonaws.com/*"
        ]
    }
]
}
Run Code Online (Sandbox Code Playgroud)

将eu-west-1替换为S3端点所在的相关区域代码.

  • 补充:https://aws.amazon.com/amazon-linux-ami/faqs/#vpc-endpoint on :: 如何配置 VPC 终端节点以允许连接到 Amazon Linux AMI 存储库? (2认同)

Rtm*_*tmY 11

如果您在 EC2 所在的子网上使用 NACL。


快速解决

您必须为此打开 站临时端口yum update

例如添加下面的 #100入站规则:

在此输入图像描述

请注意,即使出站规则允许所有流量,这仍然是必要的:

在此输入图像描述

为什么我们必须这样做?

  1. yum在端口上打开出站连接时,80/443它会在随机高端口(临时端口)返回。

  2. 网络 ACL 是无状态的(与安全组不同),默认情况下不允许在同一端口上返回连接。


您可以在这里阅读更多内容。


dav*_*w12 9

许多亚马逊EC2的首次使用者遇到了这个问题.根据我的经验,通常是不在其实例的安全组上设置允许的传出连接的结果.亚马逊用于配置Amazon Linux实例的教程仅提及设置传入连接,因此很容易忘记您从未设置允许的传出连接.只需允许HTTPHTTPS请求任何IP地址就可以解决问题.

  • 默认情况下,安全组允许所有出站流量。 (3认同)
  • 如果我错了,请纠正我,但安全组在 AWS 中是有状态的,这意味着入站流量中的任何设置也对出站流量执行相同的操作。但我想,如果您将其与单个 IP 地址绑定,那么它可能无法在出站模式下工作,对吗? (2认同)
  • @jarmod 默认情况下有一个允许所有流量的传出安全组,但如果您自己构建一个新的安全组(例如使用 Terraform),则默认情况下不会存在,除非您显式添加它。 (2认同)

Val*_*dão 5

我有同样的问题,并且与名称解析有关。我使用以下方法来更正:

EC2实例没有公共DNS

这是Mat的很好解释:

  • 转到console.aws.amazon.com
  • 转到服务-> VPC
  • 打开您的VPC
  • 选择连接到EC2的VPC,然后
  • 编辑摘要--->将DNS主机名更改为YES