0

0

linux nscd是什么

藏色散人

藏色散人

发布时间:2023-04-13 10:57:37

|

2993人浏览过

|

来源于php中文网

原创

linux nscd是服务缓存守护进程,其英文全称是“Name Service Cache Daemon”,它为NIS和LDAP等服务提供更快的验证;缓存是一项非常重要的技术或机制,缓存的主旨就是提高客户端访问速度。

linux nscd是什么

本教程操作环境:linux5.9.8系统、Dell G3电脑。

linux nscd是什么?

Linux下开启缓存服务NSCD

NSCD(Name Service Cache Daemon)是服务缓存守护进程,它为NIS和LDAP等服务提供更快的验证。不管是什么系统,缓存是一项非常重要的技术[或机制],缓存的主旨就是提高客户端访问速度。

NSCD命令选项:

# nscd --help 
Usage: nscd [OPTION...]
Name Service Cache Daemon.

  -d, --debug                Do not fork and display messages on the current
                             tty
  -f, --config-file=NAME     Read configuration data from NAME
  -F, --foreground           Do not fork, but otherwise behave like a daemon
  -g, --statistics           Print current configuration statistics
  -i, --invalidate=TABLE     Invalidate the specified cache
  -K, --shutdown             Shut the server down
  -t, --nthreads=NUMBER      Start NUMBER threads
  -?, --help                 Give this help list
      --usage                Give a short usage message
  -V, --version              Print program version

NSCD配置文件:

NSCD配置文件为/etc/nscd.conf,NSCD程序在启动的时候会读取/etc/nscd.conf文件,每一行指定一个属性和对应的值,或者指定一个服务和对应的值,#表示注释。有效的服务设定是:passwd,group,hosts,services,ornetgroup五个。

NSCD配置文件相关参数解释:

#设置日志文件 logfile debug-file-name
#设置debug记录的级别,默认是0 debug-level value
#程序启动时,等待进去请求的处理线程数,至少5个 threads number
#最大线程数,默认32 max-threads number
#nscd程序以哪个用户运行,如果设置了该选项,nscd将作为该用户运行,而不是作为root。如果每个用户都使用一个单独的缓存(-S参数),将忽略该选项。 server-user user 
#哪个用户可以请求统计用户 stat-user user
#在一个缓存项被删除之前允许使用的次数,默认是5 reload-count unlimited | number
#是否启用偏执模式,启用会导致nscd周期性重启,默认是no paranoia 
#如果启用偏执模式,设置的定期重启nscd的时间间隔,默认是3600秒 restart-interval time
#开启或者关闭服务缓存,默认是no enable-cache service 
#为成功请求的元素设置缓存TTL,单位是秒,值越大缓存命中率越高,降低平均响应时间,但会增加缓存的一致性问题 positive-time-to-live service value
#为失败查询元素设置缓存TTL,单位是秒,应保持小值,减小缓存一致性问题 negative-time-to-live service value
#内部的散列表大小,value应该保持一个素数以达到优化效果。默认值是211 suggested-size service value
#启用或者禁用检查文件是否属于指定的服务,这些文件是/etc/passwd、/etc/group、/etc/hosts、/etc/services、/etc/netgroup等 check-files service 
#设置缓存在服务器重启后,仍旧能提供缓存服务,在使用偏执模式时有用,默认是no persistent service 
#为客户端共享nscd数据库在内存中做的映射,使客户端可以直接搜索,而不用每次都查询守护进行,默认是no shared service 
#该数据库的最大大小,单位是bytes,默认是33554432 max-db-size service bytes
#此选项仅使用于passwd和group服务 auto-propagate service 

使用NSCD对DNS进行缓存

DNS在服务器上的作用:

在需要通过域名与外界进行数据交互的时候,dns缓存就派上用场了,它可以减少域名解析的时间,提高效率。例如以下情况
    使用爬虫采集网络上的页面数据,
    使用auth2.0协议从其他平台(如微博或QQ)获取用户数据,
    使用第三方支付接口,
    使用短信通道下发短信等.

开启NSCD DNS缓存服务的优点和缺点

优点:

本地缓存NDS解析信息,提高解析速度

阿里云-虚拟数字人
阿里云-虚拟数字人

阿里云-虚拟数字人是什么? ...

下载

DNS服务器挂了也没有问题,在缓存服务时间范围内,解析依旧正常

缺点:

DNS解析信息会滞后,如域名解析更改需要手动刷新缓存,NSCD不适合做实时的切换的应用,目前对于依赖DNS切换的服务,建议不要开启DNS缓存。DNS Cache作为普通的DNS解析Cache那是没问题的,如果你使用RDS云服务器,也不建议使用DNS缓存服务。

配置DNS缓存:

通过编辑/etc/nscd.conf文件,在其中增加如下一行可以开启本地DNS Cache

enable-cache hosts yes #这个服务除了dns缓存之外还可以缓存passwd,group,servers

完整配置如下:

        enable-cache            passwd          yes
        positive-time-to-live   passwd          600
        negative-time-to-live   passwd          20
        suggested-size          passwd          211
        check-files             passwd          yes
        persistent              passwd          yes
        shared                  passwd          yes
        max-db-size             passwd          33554432
        auto-propagate          passwd          yes

        enable-cache            group           yes
        positive-time-to-live   group           3600
        negative-time-to-live   group           60
        suggested-size          group           211
        check-files             group           yes
        persistent              group           yes
        shared                  group           yes
        max-db-size             group           33554432
        auto-propagate          group           yes

        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

        enable-cache            services        yes
        positive-time-to-live   services        28800
        negative-time-to-live   services        20
        suggested-size          services        211
        check-files             services        yes
        persistent              services        yes
        shared                  services        yes
        max-db-size             services        33554432

        enable-cache            netgroup        yes
        positive-time-to-live   netgroup        28800
        negative-time-to-live   netgroup        20
        suggested-size          netgroup        211
        check-files             netgroup        yes
        persistent              netgroup        yes
        shared                  netgroup        yes
        max-db-size             netgroup        33554432

NSCD服务查看和清除

NSCD缓存DB文件在/var/db/nscd下。可以通过nscd -g查看统计的信息:

# nscd -g 
nscd configuration:

              0  server debug level
 50d 14h 33m 40s  server runtime
              5  current number of threads
             32  maximum number of threads
              0  number of times clients had to wait
             no  paranoia mode enabled
           3600  restart internal
              5  reload count

passwd cache:

            yes  cache is enabled
            yes  cache is persistent
            yes  cache is shared
            211  suggested size
         216064  total data pool size
            544  used data pool size
            600  seconds time to live for positive entries
             20  seconds time to live for negative entries
         280382  cache hits on positive entries
          10047  cache hits on negative entries
           3260  cache misses on positive entries
            474  cache misses on negative entries
             98% cache hit rate
              6  current number of cached values
             52  maximum number of cached values
              2  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
清除指定类型缓存:

nscd -i passwd
nscd -i group 
nscd -i hosts

推荐学习:《linux视频教程

相关专题

更多
硬盘接口类型介绍
硬盘接口类型介绍

硬盘接口类型有IDE、SATA、SCSI、Fibre Channel、USB、eSATA、mSATA、PCIe等等。详细介绍:1、IDE接口是一种并行接口,主要用于连接硬盘和光驱等设备,它主要有两种类型:ATA和ATAPI,IDE接口已经逐渐被SATA接口;2、SATA接口是一种串行接口,相较于IDE接口,它具有更高的传输速度、更低的功耗和更小的体积;3、SCSI接口等等。

989

2023.10.19

PHP接口编写教程
PHP接口编写教程

本专题整合了PHP接口编写教程,阅读专题下面的文章了解更多详细内容。

50

2025.10.17

php8.4实现接口限流的教程
php8.4实现接口限流的教程

PHP8.4本身不内置限流功能,需借助Redis(令牌桶)或Swoole(漏桶)实现;文件锁因I/O瓶颈、无跨机共享、秒级精度等缺陷不适用高并发场景。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

195

2025.12.29

磁盘配额是什么
磁盘配额是什么

磁盘配额是计算机中指定磁盘的储存限制,就是管理员可以为用户所能使用的磁盘空间进行配额限制,每一用户只能使用最大配额范围内的磁盘空间。php中文网为大家提供各种磁盘配额相关的内容,教程,供大家免费下载安装。

1345

2023.06.21

如何安装LINUX
如何安装LINUX

本站专题提供如何安装LINUX的相关教程文章,还有相关的下载、课程,大家可以免费体验。

698

2023.06.29

linux find
linux find

find是linux命令,它将档案系统内符合 expression 的档案列出来。可以指要档案的名称、类别、时间、大小、权限等不同资讯的组合,只有完全相符的才会被列出来。find根据下列规则判断 path 和 expression,在命令列上第一个 - ( ) , ! 之前的部分为 path,之后的是 expression。还有指DOS 命令 find,Excel 函数 find等。本站专题提供linux find相关教程文章,还有相关

293

2023.06.30

linux修改文件名
linux修改文件名

本专题为大家提供linux修改文件名相关的文章,这些文章可以帮助用户快速轻松地完成文件名的修改工作,大家可以免费体验。

773

2023.07.05

linux系统安装教程
linux系统安装教程

linux系统是一种可以免费使用,自由传播,多用户、多任务、多线程、多CPU的操作系统。本专题提供linux系统安装教程相关的文章,大家可以免费体验。

571

2023.07.06

vlookup函数使用大全
vlookup函数使用大全

本专题整合了vlookup函数相关 教程,阅读专题下面的文章了解更多详细内容。

26

2025.12.30

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
PostgreSQL 教程
PostgreSQL 教程

共48课时 | 6.3万人学习

Git 教程
Git 教程

共21课时 | 2.3万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号