美文网首页Linux 进攻之路
linux开启nscd服务缓存加速

linux开启nscd服务缓存加速

作者: AllenWGZ | 来源:发表于2021-12-31 15:22 被阅读0次
前言: 前段在公司内部弄了一台DNS缓存服务器,但跑了一段时间后总感觉有点慢,希望加快缓存,记得上家公司的同事说过使用nscd可以加速DNS缓存速度,nscd会缓存三种服务passwd group hosts,所以它会记录三个库,分别对应源/etc/passwd, /etc/hosts 和 /etc/resolv.conf每个库保存两份缓存,一份是找到记录的,一份是没有找到记录的。每一种缓存都保存有生存时间(TTL)。其作用就是在本当中增加cache ,加快DNS的解析速度

一、nscd安装和配置
  1. 我这边使用的是CentOS,安装时候就一条命令
yum install nscd
  1. 安装完成,现在就进行配置,配置文件位置 /etc/nscd.conf,配置如下
# /etc/nscd.conf
logfile        /var/log/nscd.log


threads                 10
max-threads             128
server-user             nscd
debug-level             0
paranoia                no
enable-cache            passwd          no
enable-cache            group           no
enable-cache            hosts           yes
positive-time-to-live   hosts           60
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

我们只是开启DNS cache 缓存,所以最重要的一条配置是

enable-cache            hosts           yes
二、nscd启用和验证
  1. 进行设置开机自启和手动进行启动
    CentOS 7 以上的的系统可以使用以下命令
systemctl enable nscd
systemctl start nscd

   CentOS 7以下的系统可以使用以下命令

chkconfig nscd on
service nscd start
  1. 进行查看缓存信息,缓存DB文件在/var/db/nscd下,可以使用命令 nscd -g 进行查看
[root@gz--vm-dnscache-0001 ~]# nscd -g
nscd 配置:

              0  服务器调试级别
 91d 21h 49m  4s  server runtime
             10  current number of threads
            128  maximum number of threads
              0  number of times clients had to wait
             no  paranoia mode enabled
           3600  restart internal
              5  reload count

passwd cache:

             no  cache is enabled
             no  cache is persistent
             no  cache is shared
              0  suggested size
              0  total data pool size
              0  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/passwd for changes
            ......
  1. 清除缓存
nscd -i passwd
nscd -i group
nscd -i hosts
三、 nscd 部分配置说明

相关参数的解释如下:

logfile debug-file-name    指定调试信息写入的文件名。

debug-level value    设置希望的调试级别。

threads number    这是启动的等待请求的线程数。最少将创建5个线程。

server-user user    如果设置了该选项,nscd将作为该用户运行,而不是作为root。如果每个用户都使用一个单独的缓存(-S参数),将忽略该选项。

enable-cache service <yes|no>    启用或禁用制定的 服务 缓存。

positive-time-to-live service value    设置 service 在指定缓存中正的项目(成功的请求)的TTL(存活时间)。 Value 以秒为单位。较大的值将增加缓存命中率从而减低平均响应时间,但是将增加缓存的一致性问题。

negative-time-to-live service value    设置 service 在指定缓存中负的项目(失败的请求)的TTL(存活时间)。 Value 以秒为单位。如果存在由不在系统数据库中的uid(用户ID)(例如在以root身份解包linux 内核源代码时)所拥有的文件将明显改善性能;应该维持较小的值以降低缓存一致性问题。

suggested-size service value    这是内部散列表的大小, value 应该保持一个素数以达到优化效果。

check-files service <yes|no>    启用或禁用检查属于指定 服务 的文件的改变。这些文件是 /etc/passwd, /etc/group, 以及 /etc/hosts。

四、为什么配置 nscd 加速缓存
  • DNS 解析快慢严重影响了上网的体验,我们公司所有的办公设备DNS服务器都是使用内部DNS Cache服务器,两百台电脑不停向内部DNS Cache 发起请求解析,算不上特别繁忙,但是在高峰时候进行这个缓存确实是有些影响,提高一点

参考链接:http://www.361way.com/linux-nscd-dns-cache/4265.html

相关文章

  • linux开启nscd服务缓存加速

    前言: 前段在公司内部弄了一台DNS缓存服务器,但跑了一段时间后总感觉有点慢,希望加快缓存,记得上家公司的同事说过...

  • DNS缓存服务 — NSCD

    原文:https://www.fanhaobai.com/2017/06/nscd-dns-cache.html ...

  • Linux运维最佳实践笔记

    Linux运维最佳实践读书笔记 第一章 使用NSCD构建域名解析缓存的好处:优化DNS响应速度减少DNS对外部网络...

  • Redis 缓存优点、缺点、使用场景

    缓存的收益 1、加速读写 通过缓存加速读写速度:CPU L1/L2/L3 Cache 、Linux page Ca...

  • vue打包体积大:加载时间长

    加速nginx: 开启gzip和缓存 nginx 是一个高性能的 Web 服务器,之前也写过一些关于 nginx ...

  • SuperMap GIS服务加速解决方案

    ###1.简介SuperMapGIS服务加速方案采用服务代理与缓存,实现服务加速。服务代理是采用GIS分发服务器S...

  • Redis 缓存的使用和优化

    1.缓存收益 1.1加速读写 通过缓存加速读写速度 1.2降低后端负载 后端服务器通过前端缓存降低负载:业务端使用...

  • 云解析DNS(二)

    一、缓存加速ZONE 是一种基于DNS代理实现的公网权威DNS服务,接入缓存加速ZONE后,企业客户无需进行DNS...

  • Nuget 缓存加速服务

    废话一下: 国内的网络环境决定了访问国外服务器提供的服务, 注定是非常慢. 例如, 克隆Github上的仓库, 都...

  • RHCE.2021.学习笔记.17篇

    Red Hat Enterprise Linux 下使用Squid部署代理缓存服务

网友评论

    本文标题:linux开启nscd服务缓存加速

    本文链接:https://www.haomeiwen.com/subject/hdfyiftx.html