CentOS 7 无法yum安装解决方法

问题描述:云主机可以ping通外网,iptables及安全组关闭,但是无法yum安装软件


服务器测试如下:

# wget -d http://mirrors.aliyun.com/repo/Centos-7.repo

DEBUG output created by Wget 1.14 on linux-gnu.

URI encoding = “UTF-8”

URI encoding = “UTF-8”

Converted file name 'Centos-7.repo' (UTF-8) -> 'Centos-7.repo' (UTF-8)

Converted file name 'Centos-7.repo' (UTF-8) -> 'Centos-7.repo' (UTF-8)

--2017-06-13 11:30:43--  http://mirrors.aliyun.com/repo/Centos-7.repo

正在连接 182.61.111.208:3128... Closed fd 3

失败:拒绝连接。

Releasing 0x000000000112fb60 (new refcount 0).

Deleting unused 0x000000000112fb60.

# yum install -y httpd

已加载插件:langpacks, versionlock

http://repo.bcm.baidubce.com/yum/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to 182.61.111.208:3128; 拒绝连接"

正在尝试其它镜像。

# ping mirrors.aliyun.com -c 2

PING mirrors.aliyun.com (115.28.122.210) 56(84) bytes of data.

64 bytes from 115.28.122.210 (115.28.122.210): icmp_seq=1 ttl=48 time=34.8 ms

64 bytes from 115.28.122.210 (115.28.122.210): icmp_seq=2 ttl=48 time=34.5 ms

--- mirrors.aliyun.com ping statistics ---

2 packets transmitted, 2 received, 0% packet loss, time 1001ms

rtt min/avg/max/mdev = 34.593/34.744/34.896/0.240 ms

# ping 182.61.111.208 -c 2PING 182.61.111.208 (182.61.111.208) 56(84) bytes of data.

64 bytes from 182.61.111.208: icmp_seq=1 ttl=48 time=42.3 ms

64 bytes from 182.61.111.208: icmp_seq=2 ttl=48 time=41.4 ms

--- 182.61.111.208 ping statistics ---

2 packets transmitted, 2 received, 0% packet loss, time 1001ms

rtt min/avg/max/mdev = 41.436/41.882/42.328/0.446 ms

# telnet 182.61.111.208 3128Trying 182.61.111.208...

telnet: connect to address 182.61.111.208: Connection refused


排查思路:

1.检查防火墙设置,先关闭

# systemctl stop firewalld.service #停止firewall

# systemctl disable firewalld.service #禁止firewall开机启动

# systemctl restart iptables.service #重启防火墙使配置生效

# systemctl enable iptables.service #设置防火墙开机启动

2.telnet一个已知IP及端口,确定是服务端问题还是client问题

# curl -I http://180.76.148.122:80

curl: (7) Failed connect to 182.61.111.208:3128; 拒绝连接

发现拒绝的连接不是目标IP,被转发了,应该是使用了代理

3.查找可能的配置文件

# find /etc -type f | xargs grep -i '182.61.111.208'

/etc/profile:export http_proxy=http://182.61.111.208:3128/

4.编辑profile并重载

# vim /etc/profile

# tail -n 2 /etc/profile

#export LC_ALL=zh_CN.UTF-8

#export http_proxy=http://182.61.111.208:3128/

# source /etc/profile

5.重新ssh后下载查看

# wget http://mirrors.aliyun.com/repo/Centos-7.repo

--2017-06-13 12:01:47--  http://mirrors.aliyun.com/repo/Centos-7.repo

正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 112.124.140.210, 115.28.122.210

正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|112.124.140.210|:80... 已连接。

已发出 HTTP 请求,正在等待回应... 200 OK

长度:2573 (2.5K) [application/octet-stream]

正在保存至: “Centos-7.repo”

100%[==================================================================================================================================================================>] 2,573       --.-K/s 用时 0s

2017-06-13 12:01:47 (99.1 MB/s) - 已保存 “Centos-7.repo” [2573/2573])


分享一个好用的yum源(aliyun):

1)下载repo文件

wget http://mirrors.aliyun.com/repo/Centos-7.repo

2)备份并替换系统的repo文件

cp Centos-7.repo /etc/yum.repos.d/

cd /etc/yum.repos.d/

mv CentOS-Base.repo CentOS-Base.repo.bak

mv Centos-7.repo CentOS-Base.repo

3)执行yum源更新命令

yum clean all

yum makecache

yum update

配置完毕。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 目前能ping通的IP:216.58.193.51 59.18.44.245 59.18.44.53 59.18....
    StevenZack阅读 2,043评论 0 0
  • 用centos自带的yum源来安装nginx,mysql和php,超级方便,省去编译的麻烦,省去自己配置的麻烦,还...
    fd3a63aa507f阅读 1,356评论 0 5
  • 关于恋与暗恋 关于爱情,在我父母的故事里,并没有学到太多的东西,相反是建立了认知的扭曲。 他们的故事我听过无数个版...
    ian老湿阅读 263评论 0 0
  • 拒绝别人请求或要求是我们每个人都会经历的,不会拒绝早晚会让自己身心疲惫,但拒绝他人时要三思,冷冰冰的拒绝和委婉的拒...
    六正一阅读 251评论 0 0
  • 文|小豌豆 标题参考书籍《与不被眷顾的人生握手言和》 不知从什么时候开始,我发现自己是不被眷顾的那一个。若是命运不...
    小豌豆23阅读 803评论 1 1