Dynadot Jtti 搬瓦工 腾讯云

CentOS 优化 DNS 设置:配置冗余 DNS 并开启 NSCD 缓存服务教程

GigsGigsCloud

今天看到 CentOS 上的 DNS 优化方法,可以通过配置冗余 DNS,并开启 DNS 解析缓存服务 NSCD,来达到更快更好的解析的目的。说实话还是挺好用的,因为之前也没试过,所以在此分享一下,可以有效解决 CentOS 上的一些 DNS 解析错误的问题,比如有时候解析卡住了,解析了很久,或者有时候就是解析失败。通过配置冗余 DNS,可以有效减少这种情况。

一、配置冗余 DNS

配置冗余 DNS 可防止 DNS Server 单点故障后,域名无法解析的情况。以 CentOS 为例,打开主机内 /etc/resolv.conf 文件,若文件中只配置了 1 个 IP,可以查询主机服务商是否提供其他 DNS 服务器,或者可以直接增加下面的若干个 DNS 服务器:

  • 8.8.8.8
  • 8.8.4.4
  • 114.114.114.114
  • 114.114.115.115

我们也可以网上查找其他更多的 DNS 服务器。

二、开启 NSCD 服务

在 Linux 中开启 NSCD 服务可在本地缓存 DNS 解析结果。在 TTL 时间内,无需去 DNS 服务器重复解析,从而加快 DNS 的解析速度,也缓解 DNS 服务器的压力。

以 CentOS 为例:

1、安装

yum install nscd

2、增加配置文件 /etc/nscd.conf

内容如下:

#
# /etc/nscd.conf
#
# An example Name Service Cache config file.  This file is needed by nscd.
#
# Legal entries are:
#
#       logfile                 <file>
#       debug-level             <level>
#       threads                 <initial #threads to use>
#       max-threads             <maximum #threads to use>
#       server-user             <user to run server as instead of root>
#               server-user is ignored if nscd is started with -S parameters
#       stat-user               <user who is allowed to request statistics>
#       reload-count            unlimited|<number>
#       paranoia                <yes|no>
#       restart-interval        <time in seconds>
#
#       enable-cache            <service> <yes|no>
#       positive-time-to-live   <service> <time in seconds>
#       negative-time-to-live   <service> <time in seconds>
#       suggested-size          <service> <prime number>
#       check-files             <service> <yes|no>
#       persistent              <service> <yes|no>
#       shared                  <service> <yes|no>
#       max-db-size             <service> <number bytes>
#       auto-propagate          <service> <yes|no>
#
# Currently supported cache names (services): passwd, group, hosts, services
#
#   logfile                 /var/log/nscd.log
    threads                 4
    max-threads             32
    server-user             nscd
    stat-user               somebody
    debug-level             5
    reload-count            5
    paranoia                no
    restart-interval        3600


    enable-cache            hosts           yes
    enable-cache            passwd          no
    enable-cache            group           no
    enable-cache            services        no
    positive-time-to-live   hosts           5
    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、启动服务

service nscd start

4、添加开机自启动

chkconfig nscd on

5、停止服务(如果需要)

service nscd stop

参考文献:https://docs.ucloud.cn/uhost/public/dns_setting

Dynadot Hostwinds
赞(1)
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《CentOS 优化 DNS 设置:配置冗余 DNS 并开启 NSCD 缓存服务教程
文章链接:https://oldtang.com/3317.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。