Linux centos服务器DNS域名解析慢,可以安装nscd缓存加速来解决
针对服务器解析慢,可以在服务器上安装nscd,就可以把解析缓存起来,不用每次都解析安装nscd:
yum -y install nscd
chkconfig nscd on
service nscd start
查看监听情况
netstat -apn | grep nscd
输出如下代表就成功了
udp 0 0 188.165.157.116:24545 8.8.8.8:53 ESTABLISHED 22127/nscd
udp 0 0 188.165.157.116:43234 8.8.4.4:53 ESTABLISHED 22127/nscd
udp 0 0 188.165.157.116:31341 8.8.4.4:53 ESTABLISHED 22127/nscd
udp 0 0 188.165.157.116:16768 8.8.8.8:53 ESTABLISHED 22127/nscd
udp 0 0 188.165.157.116:58117 8.8.8.8:53 ESTABLISHED 22127/nscd
udp 0 0 188.165.157.116:19847 8.8.4.4:53 ESTABLISHED 22127/nscd
udp 0 0 188.165.157.116:30984 8.8.4.4:53 ESTABLISHED 22127/nscd
udp 0 0 188.165.157.116:19857 8.8.4.4:53 ESTABLISHED 22127/nscd
udp 0 0 188.165.157.116:12826 8.8.8.8:53 ESTABLISHED 22127/nscd
udp 0 0 188.165.157.116:52894 8.8.4.4:53 ESTABLISHED 22127/nscd
udp 0 0 188.165.157.116:14240 8.8.8.8:53 ESTABLISHED 22127/nscd
udp 0 0 188.165.157.116:47410 8.8.8.8:53 ESTABLISHED 22127/nscd
udp 0 0 188.165.157.116:54326 8.8.8.8:53 ESTABLISHED 22127/nscd
udp 0 0 188.165.157.116:38711 8.8.4.4:53 ESTABLISHED 22127/nscd
udp 584 0 188.165.157.116:10689 8.8.8.8:53 ESTABLISHED 22127/nscd
udp 0 0 188.165.157.116:27465 8.8.4.4:53 ESTABLISHED 22127/nscd
unix2 [ ACC ] STREAM LISTENING 475452517 22127/nscd /var/run/nscd/socket
unix2 [ ] STREAM CONNECTED 3458199209 22127/nscd /var/run/nscd/socket
unix2 [ ] STREAM CONNECTED 3458199175 22127/nscd /var/run/nscd/socket
unix2 [ ] STREAM CONNECTED 3458198561 22127/nscd /var/run/nscd/socket
unix2 [ ] STREAM CONNECTED 3458198384 22127/nscd /var/run/nscd/socket
unix2 [ ] STREAM CONNECTED 3458197458 22127/nscd /var/run/nscd/socket
unix2 [ ] STREAM CONNECTED 3458197375 22127/nscd /var/run/nscd/socket
unix2 [ ] STREAM CONNECTED 3458197099 22127/nscd /var/run/nscd/socket
unix2 [ ] STREAM CONNECTED 3458196531 22127/nscd /var/run/nscd/socket
unix2 [ ] DGRAM 475452516 22127/nscd
如果有需要修改配置文件,vi /etc/nscd.conf,默认已经是yes
enable-cache hosts yes
这个服务除了dns缓存之外还可以缓存passwd,group,services,netgroup这几个东西的缓存暂时用不到
修改后记得重启nscd服务
service nscd restart
查看命中统计
nscd -g
显示结果如下
# nscd -g
nscd configuration:
0server debug level
35d 23h 21m 32sserver runtime
21current number of threads
32maximum number of threads
16number of times clients had to wait
noparanoia mode enabled
3600restart internal
5reload count
passwd cache:
yescache is enabled
yescache is persistent
yescache is shared
211suggested size
216064total data pool size
360used data pool size
600seconds time to live for positive entries
20seconds time to live for negative entries
0cache hits on positive entries
0cache hits on negative entries
1880cache misses on positive entries
17388cache misses on negative entries
0% cache hit rate
4current number of cached values
43maximum number of cached values
2maximum chain length searched
0number of delays on rdlock
0number of delays on wrlock
0memory allocations failed
yescheck /etc/passwd for changes
group cache:
yescache is enabled
yescache is persistent
yescache is shared
211suggested size
216064total data pool size
288used data pool size
3600seconds time to live for positive entries
60seconds time to live for negative entries
0cache hits on positive entries
0cache hits on negative entries
36cache misses on positive entries
79cache misses on negative entries
0% cache hit rate
2current number of cached values
5maximum number of cached values
1maximum chain length searched
0number of delays on rdlock
0number of delays on wrlock
0memory allocations failed
yescheck /etc/group for changes
hosts cache:
yescache is enabled
yescache is persistent
yescache is shared
211suggested size
216064total data pool size
19352used data pool size
3600seconds time to live for positive entries
20seconds time to live for negative entries
11160cache hits on positive entries
0cache hits on negative entries
122099cache misses on positive entries
35362cache misses on negative entries
6% cache hit rate
139current number of cached values
140maximum number of cached values
20maximum chain length searched
0number of delays on rdlock
0number of delays on wrlock
0memory allocations failed
yescheck /etc/hosts for changes
services cache:
yescache is enabled
yescache is persistent
yescache is shared
211suggested size
216064total data pool size
0used data pool size
28800seconds time to live for positive entries
20seconds time to live for negative entries
0cache hits on positive entries
0cache hits on negative entries
0cache misses on positive entries
0cache misses on negative entries
0% cache hit rate
0current number of cached values
0maximum number of cached values
0maximum chain length searched
0number of delays on rdlock
0number of delays on wrlock
0memory allocations failed
yescheck /etc/services for changes
netgroup cache:
yescache is enabled
yescache is persistent
yescache is shared
211suggested size
216064total data pool size
0used data pool size
28800seconds time to live for positive entries
20seconds time to live for negative entries
0cache hits on positive entries
0cache hits on negative entries
0cache misses on positive entries
0cache misses on negative entries
0% cache hit rate
0current number of cached values
0maximum number of cached values
0maximum chain length searched
0number of delays on rdlock
0number of delays on wrlock
0memory allocations failed
yescheck /etc/netgroup for changes
#
查看nscd数据库中的域名列表
strings /var/db/nscd/hosts | grep -P '[\w-]+\.\w+' | sort -u
如果没效果,reboot重启服务器
今天碰到一个用户使用cdnbest,用户在cdn添加记录,源ip的位置写的是域名,不是ip,结果造成不能访问,安装nscd后解决
DNS,是网络运转的最为根本的服务。在 Linux系统中,有一个名为nscd 的软件包,是专门缓存DNS的,试想如果是一台高并发的邮件服务器,对DNS的依赖程度更为重要。所以在系统上安装nscd进行DNS进行缓存时,原则上 效率会大大地提高
很多Linux发行版缺省状态都会关闭DNS缓存,诸多应用可以提供这个功能,nscd(Name Service Cache Daemon,名称服务缓存守护进程)是最容易安装的应用之一。
不过我感觉,效果还是不明显,特别是dig一下,还是多少延迟就是多少而不是0ms
在安装并启动nscd之后,如果没有真正了解它,可以使用ping和tcpdump之类的东西来验证DNS查询是否真的离开了主机。请注意,像nslookup,dig或host 这样的绑定工具总是直接查询DNS服务器,所以在运行这些服务器时你不会看到任何nscd的效果。
这里推荐效果更好的dnsmasq
http://bbs.itzmx.com/thread-85751-1-1.html
很有用,谢谢小樱{:130:}
页:
[1]