问题:
1.开始的时候程序说代码经常无法解析域名,第一反应是不是网络有问题、dns有问题、是不是ipv6导致,后来看了下网络正常、dns是用的腾讯自身的dns服务器、ipv6已关闭。
2. 后来又怀疑是不是对方域名、服务器有问题,或者有限制吧。在同地区其它服务器尝试,在不同地址其它服务器尝试都正常。有问题服务器上用ip访问也不会出现问题。而且dig看了下对方域名是使用CDN的。总不会是CDN有问题吧。。。
3. ip没问题的话,就开始怀疑是不是解析出问题了。
3.1 这域名还不是每次都解析失败,是偶尔会出现,一出现就大片失败。然后就慢慢curl试试了,可以看到前面还是正常的
# curl https://coolnull.com/member_third.action {"status":1,"userid":0,"username":""}# curl https://coolnull.com/member_third.action {"status":1,"userid":0,"username":""}# curl https://coolnull.com/member_third.action {"status":1,"userid":0,"username":""}# curl https://coolnull.com/member_third.action
然后又无法解析了
# curl https://coolnull.com/member_third.action curl: (6) Couldn't resolve host 'coolnull.com' # curl https://coolnull.com/member_third.action curl: (6) Couldn't resolve host 'coolnull.com' # curl https://coolnull.com/member_third.action curl: (6) Couldn't resolve host 'coolnull.com' # curl https://coolnull.com/member_third.action curl: (6) Couldn't resolve host 'coolnull.com' # curl https://coolnull.com/member_third.action curl: (6) Couldn't resolve host 'coolnull.com'
3.2 马上修改hosts指向coolnull.com,可以看到立马又正常了
# vim /etc/hosts 127.0.0.1 TENCENT64.site TENCENT64 218.59.186.128 coolnull.com "/etc/hosts" 2L, 61C written # curl https://coolnull.com/member_third.action {"status":1,"userid":0,"username":""}# curl https://coolnull.com/member_third.action {"status":1,"userid":0,"username":""}# curl https://coolnull.com/member_third.action {"status":1,"userid":0,"username":""}# curl https://coolnull.com/member_third.action {"status":1,"userid":0,"usevim /etc/hostshttps://coolnull.com/member_third.action
3.3 删除hosts中指向coolnull.com的记录,马上又失败了。
# vim /etc/hosts 127.0.0.1 TENCENT64.site TENCENT64 "/etc/hosts" 1L, 35C written # curl https://coolnull.com/member_third.action curl: (6) Couldn't resolve host 'coolnull.com' # curl https://coolnull.com/member_third.action curl: (6) Couldn't resolve host 'coolnull.com' # curl https://coolnull.com/member_third.action curl: (6) Couldn't resolve host 'coolnull.com' # curl https://coolnull.com/member_third.action curl: (6) Couldn't resolve host 'coolnull.com'
到这里,就怀疑是不是腾讯DNS有问题了,马上联系腾讯方面。
结果:
腾讯云服务器使用的都是自身的DNS服务器,而腾讯上海机房有限制dns请求的连接数,这会导致当解析请求过多时,腾讯的DNS服务器拒绝响应(这样说不知道正不正确),从而导致我们的服务器无法解析,出现curl: (6) Couldn’t resolve host ‘coolnull.com’。确实有点坑啊!广州机房就没看到有这访问的问题!等腾讯那边放开限制估计没那么快。所以以下是些临时解决方法:
1. 如果需要curl的网站url并不多,可以先暂时在/etc/hosts里添加ip、域名的解析记录;
2. 因为linux本身是不带DNS缓存的,所以也可以考虑通过nscd服务,来搭建dns缓存服务。
解决:
1.安装nscd
# yum install nscd
2.修改配置文件。nscd可以缓存很多其它务(如/etc/passwd,/etc/services),这里我们只需要缓存/etc/hosts
# egrep -v "^$|^#" /etc/nscd.conf server-user nscd debug-level 0 paranoia no enable-cache hosts yes positive-time-to-live hosts 3600 negative-time-to-live hosts 20 suggested-size hosts 211 check-files hosts yes persistent hosts yes shared hosts yes max-db-size hosts 33554432
3.启动NSCD服务
# /etc/init.d/nscd start
4.测试速度
暂空!
如图: