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

时间:2019-05-03 11:32:45

标签: amazon-ec2 apt-get

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

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.

我该如何解决?

3 个答案:

答案 0 :(得分:1)

听起来您的实例无法访问互联网。

您的实例都需要位于公共子网中,并具有到连接的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 :(得分:0)

我也有类似的问题。 EC2 确实可以访问 Internet,但无法连接 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 之外的网络/路由问题。

答案 2 :(得分:-1)

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

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