在部署服務的時候,不少程序須要使用域名解析的功能,通常配置/etc/resovl.conf去指定DNS服務器的IP,可是若是程序發起的請求量較大,那麼服務器就容易被DNS服務器禁止訪問(至於爲何會被禁止,你懂得),同事每次去外網請求DNS解析的話,時延也特別大,乃至發生請求超時的狀況,這個是,咱們就要配置一個透明的DNS解析緩存服務器,達到的效果以下:linux
NSCD(Name server caching Daemon 名稱服務緩存進程)不須要對應用程序或者解析器作任何修改,/etc/resovl.conf 也不須要作任何變化,對於系統部署的影響最小。所以NSCD成爲linux環境最爲普遍的域名緩存軟件,本次使用該軟件做爲域名緩存服務,在CentOS6.6上,安裝NSCD的方法比較簡單,使用yum安裝便可,命令以下:緩存
[root@localhost ~]# yum -y install nscd [root@localhost ~]# ls /etc/nscd.conf /etc/nscd.conf #nscd的配置文件
咱們看看配置文件,咱們主要關心下面這幾段,yum安裝好後在63行-70行:服務器
63 enable-cache hosts yes 64 positive-time-to-live hosts 3600 65 negative-time-to-live hosts 20 66 suggested-size hosts 211 67 check-files hosts yes 68 persistent hosts yes 69 shared hosts yes 70 max-db-size hosts 33554432
參數解釋網絡
啓動服務優化
[root@localhost store]# /etc/init.d/nscd start
[root@localhost store]# nscd -g ''''' hosts cache: yes cache is enabled yes cache is persistent yes cache is shared 211 suggested size 216064 total data pool size 520 used data pool size 3600 seconds time to live for positive entries 20 seconds time to live for negative entries 0 cache hits on positive entries 0 cache hits on negative entries 0 cache misses on positive entries 0 cache misses on negative entries 0% cache hit rate 0 current number of cached values 0 maximum number of cached values 0 maximum chain length searched 0 number of delays on rdlock 0 number of delays on wrlock 0 memory allocations failed yes check /etc/hosts for changes [root@localhost ~]# wget -SO /dev/null http://www.baidu.com/ #換不一樣的域名多wget幾回,就發現這數值上去了。 [root@localhost store]# nscd -g ''''' hosts cache: yes cache is enabled yes cache is persistent yes cache is shared 211 suggested size 216064 total data pool size 520 used data pool size 3600 seconds time to live for positive entries 20 seconds time to live for negative entries 0 cache hits on positive entries 0 cache hits on negative entries 15 cache misses on positive entries 0 cache misses on negative entries 0% cache hit rate 3 current number of cached values 5 maximum number of cached values 0 maximum chain length searched 0 number of delays on rdlock 0 number of delays on wrlock 0 memory allocations failed yes check /etc/hosts for changes [root@localhost ~]# nscd -i hosts # 清空hosts當前緩存條目的