linux nscd怎么开启

66次阅读
没有评论

共计 4756 个字符,预计需要花费 12 分钟才能阅读完成。

今天丸趣 TV 小编给大家分享一下 linux nscd 怎么开启的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

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

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  yes|no
# 如果启用偏执模式,设置的定期重启 nscd 的时间间隔,默认是 3600 秒  restart-interval time
# 开启或者关闭服务缓存,默认是 no enable-cache service  yes|no
# 为成功请求的元素设置缓存 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  yes|no
# 设置缓存在服务器重启后,仍旧能提供缓存服务,在使用偏执模式时有用,默认是 no persistent service  yes|no
# 为客户端共享 nscd 数据库在内存中做的映射,使客户端可以直接搜索,而不用每次都查询守护进行,默认是 no shared service  yes|no
# 该数据库的最大大小,单位是 bytes,默认是 33554432 max-db-size service bytes
# 此选项仅使用于 passwd 和 group 服务  auto-propagate service  yes|no

使用 NSCD 对 DNS 进行缓存

DNS 在服务器上的作用:

在需要通过域名与外界进行数据交互的时候,dns 缓存就派上用场了, 它可以减少域名解析的时间, 提高效率。例如以下情况
    使用爬虫采集网络上的页面数据,
    使用 auth3.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 nscd 怎么开启”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,丸趣 TV 小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注丸趣 TV 行业资讯频道。

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-12发表,共计4756字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)