問題描述:云主機可以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
配置完畢。