事件
- 添加了H3C路由器做内网上网使用,节省IP做集群IP.
- 调用微信接口 https://api.mch.weixin.qq.com/pay/unifiedorder 超时5秒多。
- php报错:cURL error 28: Resolving timed out after 5516 milliseconds (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)
1
2
3
4
5(1/1) ConnectException
cURL error 28: Resolving timed out after 5516 milliseconds (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)
in CurlFactory.php line 185
at CurlFactory::createRejection(object(EasyHandle), array('errno' => 28, 'error' => 'Resolving timed out after 5516 milliseconds', 'url' => 'https://api.mch.weixin.qq.com/pay/unifiedorder', 'content_type' => null, 'http_code' => 0, 'header_size' => 0, 'request_size' => 0, 'filetime' => -1, 'ssl_verify_result' => 0, 'redirect_count' => 0, 'total_time' => 5.515195, 'namelookup_time' => 0.0, 'connect_time' => 0.0, 'pretransfer_time' => 0.0, 'size_upload' => 0.0, 'size_download' => 0.0, 'speed_download' => 0.0, 'speed_upload' => 0.0, 'download_content_length' => -1.0, 'upload_content_length' => -1.0, 'starttransfer_time' => 0.0, 'redirect_time' => 0.0, 'redirect_url' => '', 'primary_ip' => '', 'certinfo' => array(), 'primary_port' => 0, 'local_ip' => '', 'local_port' => 0))
排查
- 使用IDC 外网IP curl 正常
- 使用H3C 内网IP curl 超时5秒多
修改resolv.conf
添加options single-request-reopen1
2
3
4
5
6cat << EOF> /etc/resolv.conf
options single-request-reopen
nameserver 114.114.114.114
nameserver 119.29.29.29
EOF
禁用IPV6
1 | cat /etc/sysconfig/network |
1 | cat /etc/sysconfig/network-scripts/ifcfg-xxx |
禁用NetworkManager
1 | systemctl disable NetworkManager |
修改前1
2
3
4
5
6
7
8
9
10
11
12
13time curl -I https://api.mch.weixin.qq.com/pay/unifiedorder
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 13 Feb 2019 08:16:17 GMT
Content-Type: text/plain
Content-Length: 110
Connection: keep-alive
Keep-Alive: timeout=8
real 0m5.75s
user 0m0.062s
sys 0m0.052s
修改后1
2
3
4
5
6
7
8
9
10
11
12
13time curl -I https://api.mch.weixin.qq.com/pay/unifiedorder
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 13 Feb 2019 08:16:17 GMT
Content-Type: text/plain
Content-Length: 110
Connection: keep-alive
Keep-Alive: timeout=8
real 0m0.255s
user 0m0.052s
sys 0m0.042s
若开启NetworkManager防止resolv被重置
- 创建一个脚本。
1 | cat << EOF > /etc/NetworkManager/dispatcher.d/15-resolv |
- 设置文件权限
1 | chmod u+x /etc/NetworkManager/dispatcher.d/15-resolv |
- 创建一个文件
1 | vi /etc/resolv.conf.custom |
- 重启服务
1 | service NetworkManager restart |
https://www.jianshu.com/p/d5b913783d4f
http://www.man7.org/linux/man-pages/man5/resolver.5.html