无法从 EC2 实例执行 sudo apt-get update

问题描述 投票:0回答:10

我无法通过 Ubuntu EC2 实例执行 sudo apt-get update。 当我跑步时 -

sudo apt-get update

我收到以下错误:-

Err:1 http://eu-central-1.ec2.archive.ubuntu.com/ubuntu bionic InRelease
  Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (52.59.228.109), connection timed out Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (52.59.244.233), connection timed out Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (18.196.1.133), connection timed out Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (35.158.129.174), connection timed out Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (35.159.12.228), connection timed out Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (52.59.220.169), connection timed out
Err:2 http://eu-central-1.ec2.archive.ubuntu.com/ubuntu bionic-updates InRelease
  Unable to connect to eu-central-1.ec2.archive.ubuntu.com:http:
Err:3 http://eu-central-1.ec2.archive.ubuntu.com/ubuntu bionic-backports InRelease
  Unable to connect to eu-central-1.ec2.archive.ubuntu.com:http:
Err:4 http://security.ubuntu.com/ubuntu bionic-security InRelease
  Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::19). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.88.161), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.162), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.23), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.26), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.149), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.152), connection timed out
Reading package lists... Done
W: Failed to fetch http://eu-central-1.ec2.archive.ubuntu.com/ubuntu/dists/bionic/InRelease  Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (52.59.228.109), connection timed out Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (52.59.244.233), connection timed out Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (18.196.1.133), connection timed out Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (35.158.129.174), connection timed out Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (35.159.12.228), connection timed out Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (52.59.220.169), connection timed out
W: Failed to fetch http://eu-central-1.ec2.archive.ubuntu.com/ubuntu/dists/bionic-updates/InRelease  Unable to connect to eu-central-1.ec2.archive.ubuntu.com:http:
W: Failed to fetch http://eu-central-1.ec2.archive.ubuntu.com/ubuntu/dists/bionic-backports/InRelease  Unable to connect to eu-central-1.ec2.archive.ubuntu.com:http:
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease  Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::19). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.88.161), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.162), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.23), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.26), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.149), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.152), connection timed out
W: Some index files failed to download. They have been ignored, or old ones used instead.

为了解决这个问题,我遵循了this并执行了以下操作-

sudo sed -i 's/eu-central-1\.ec2\.//g' /etc/apt/sources.list

我重新启动了系统并再次尝试。现在我在执行 sudo apt-get update 时遇到此错误 -

Err:1 http://archive.ubuntu.com/ubuntu bionic InRelease
  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable) Could not connect to archive.ubuntu.com:80 (91.189.88.161), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.88.162), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.91.23), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.88.149), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.88.152), connection timed out
Err:2 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable)
Err:3 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable)
Err:4 http://security.ubuntu.com/ubuntu bionic-security InRelease
  Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::19). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.88.162), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.23), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.26), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.149), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.152), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.161), connection timed out
Reading package lists... Done
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic/InRelease  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable) Could not connect to archive.ubuntu.com:80 (91.189.88.161), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.88.162), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.91.23), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.88.149), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.88.152), connection timed out
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic-updates/InRelease  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable)
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic-backports/InRelease  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable)
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease  Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::19). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.88.162), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.23), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.26), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.149), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.152), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.161), connection timed out
W: Some index files failed to download. They have been ignored, or old ones used instead.

我该如何解决这个问题?

amazon-ec2 apt-get
10个回答
12
投票

我遇到了同样的问题,为了解决它,我必须向所有流量添加另一个出站规则并将目的地设置为

anywhere


6
投票

听起来您的实例没有互联网访问权限。

您的实例需要位于公有子网中,并具有指向附加 Internet 网关的路由表:https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Internet_Gateway.html

或者您的实例位于私有子网中,需要一个到 nat 网关的路由表:https://aws.amazon.com/premiumsupport/knowledge-center/ec2-internet-connectivity/

编辑:如果您已确认上述内容已到位,请检查出站安全组规则是否允许在预期端口上进行传出互联网访问。


1
投票

假设您的 ec2 位于公共子网中,并附加了 nat 网关。根据错误消息,需要安全组出站 http 端口 80 规则。希望这有帮助


0
投票

噢,你的 ec2 实例需要 vpc 和子网,你可以从 aws vpc 管理中检查这些 https://ap-south-1.console.aws.amazon.com/vpc/home?region=ap-south-1 #子网: 或者如果您需要指导,请使用 https://docs.aws.amazon.com/batch/latest/userguide/create-public-private-vpc.html


0
投票

如果您已经尝试了发布的所有解决方案,然后更改区域,它将起作用,我在两个不同的区域中执行了完全相同的步骤,并且它在一个区域中起作用,而另一个区域则不起作用,这个问题面临很多人。


0
投票

我建议查看安全配置,即安全组和子网 NACL。这些是超时和无法解释的连接问题的常见嫌疑 - 特别是如果它们尚未配置或评估。

对于安全组,因为没有到 EC2 实例的传入连接,因此在更新存储库和服务器之间创建有状态连接。这意味着我们需要向实例的安全组显式添加出站规则。这可以是一般规则(出站到任何地方:0.0.0.0/0 或 ::0),也可以是针对预期 IP 集的显式规则。

对于 NACL,确保允许流量流向 NACL 和流量将流经的子网的任何地方。再说一遍,这可能是一般规则(从实例入站,出站到任何地方),或者是针对预期 IP 集的显式规则。


0
投票

好吧,非常确定您的 nat 网关存在一些问题。从概念上讲,如果您要去,那么您的计算机现在位于私有子网中,并且要与外界通信,它需要通过 nat 网关与互联网网关通信,所以这就是问题。您的 nat 网关无法从互联网网关访问互联网。因此解决方案是您只需删除您的 nat 网关并重新创建它,并在创建时将其连接到公共子网。下一步是转到路由表并将其附加到私有路由表 -> 编辑路由 -> 和 0.0.0.0/0(允许来自任何地方的请求)并在下拉列表中选择 nat 网关,它将自动显示您创建的 nat 网关 -> 单击保存更改。您完成后只需重新启动计算机运行命令 sudo apt-get update。


-1
投票

我也有类似的问题。 EC2确实可以访问互联网,但无法连接Ubuntu存储库:

root@ip-10-0-8-82:~# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=1.91 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=111 time=1.94 ms
^C
--- 8.8.8.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 1.911/1.928/1.945/0.017 ms

root@ip-10-0-8-82:~# host archive.ubuntu.com
archive.ubuntu.com has address 91.189.88.152
archive.ubuntu.com has address 91.189.88.142
archive.ubuntu.com has IPv6 address 2001:67c:1360:8001::23
archive.ubuntu.com has IPv6 address 2001:67c:1360:8001::24

root@ip-10-0-8-82:~# ping 91.189.88.152
PING 91.189.88.152 (91.189.88.152) 56(84) bytes of data.
^C
--- 91.189.88.152 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2032ms

root@ip-10-0-8-82:~# tracepath 91.189.88.152
 1?: [LOCALHOST]                      pmtu 9001
 1:  10.0.0.1                                              0.248ms pmtu 1500
 1:  no reply
 2:  no reply
 3:  no reply
 4:  no reply
 5:  no reply
 6:  100.65.10.1                                           0.552ms asymm  7 
 7:  52.95.65.144                                          1.531ms asymm 13 
 8:  52.95.66.86                                           4.035ms asymm 13 
 9:  52.95.66.163                                          1.765ms asymm 12 
10:  100.92.58.40                                         50.536ms asymm 19 
11:  52.93.135.225                                        48.973ms asymm 18 
12:  150.222.246.119                                      57.410ms asymm 17 
13:  100.91.182.0                                         48.686ms asymm 16 
14:  52.93.9.18                                           50.418ms asymm 19 
15:  52.93.9.37                                           52.182ms asymm 17 
16:  no reply
17:  no reply
18:  no reply
19:  no reply
20:  no reply
21:  no reply
22:  no reply
23:  no reply
24:  no reply
25:  no reply
26:  no reply
27:  no reply
28:  no reply
29:  no reply
30:  no reply
     Too many hops: pmtu 1500
     Resume: pmtu 1500 

我之前确实在具有相同 IP 地址的同一 EC2 内运行过

apt-get update
。未对 EC2 进行任何更改或重新启动。突然就停止工作了。

看起来 EC2 外部存在网络/路由问题。


-1
投票

从本地系统停止或删除防病毒软件并停止防火墙。重新处理安装。现在效果很好。


-4
投票

我也面临着同样的问题。我已经通过更改安全规则修复了这个问题。 只需将您的设置更改为默认安全规则即可。

与入站一样,仅配置了 8080 端口和 22 端口。删除其余的安全法。

© www.soinside.com 2019 - 2024. All rights reserved.