问题描述:云主机可以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
配置完毕。