溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

linux nscd怎么開啟

發(fā)布時間:2023-04-19 09:53:24 來源:億速云 閱讀:146 作者:iii 欄目:建站服務(wù)器

今天小編給大家分享一下linux nscd怎么開啟的相關(guān)知識點,內(nèi)容詳細(xì),邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。

linux nscd是服務(wù)緩存守護(hù)進(jìn)程,其英文全稱是“Name Service Cache Daemon”,它為NIS和LDAP等服務(wù)提供更快的驗證;緩存是一項非常重要的技術(shù)或機制,緩存的主旨就是提高客戶端訪問速度。

Linux下開啟緩存服務(wù)NSCD

NSCD(Name Service Cache Daemon)是服務(wù)緩存守護(hù)進(jìn)程,它為NIS和LDAP等服務(wù)提供更快的驗證。不管是什么系統(tǒng),緩存是一項非常重要的技術(shù)[或機制],緩存的主旨就是提高客戶端訪問速度。

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文件,每一行指定一個屬性和對應(yīng)的值,或者指定一個服務(wù)和對應(yīng)的值,#表示注釋。有效的服務(wù)設(shè)定是:passwd,group,hosts,services,ornetgroup五個。

NSCD配置文件相關(guān)參數(shù)解釋:

#設(shè)置日志文件 logfile debug-file-name
#設(shè)置debug記錄的級別,默認(rèn)是0 debug-level value
#程序啟動時,等待進(jìn)去請求的處理線程數(shù),至少5個 threads number
#最大線程數(shù),默認(rèn)32 max-threads number
#nscd程序以哪個用戶運行,如果設(shè)置了該選項,nscd將作為該用戶運行,而不是作為root。如果每個用戶都使用一個單獨的緩存(-S參數(shù)),將忽略該選項。 server-user user 
#哪個用戶可以請求統(tǒng)計用戶 stat-user user
#在一個緩存項被刪除之前允許使用的次數(shù),默認(rèn)是5 reload-count unlimited | number
#是否啟用偏執(zhí)模式,啟用會導(dǎo)致nscd周期性重啟,默認(rèn)是no paranoia <yes|no>
#如果啟用偏執(zhí)模式,設(shè)置的定期重啟nscd的時間間隔,默認(rèn)是3600秒 restart-interval time
#開啟或者關(guān)閉服務(wù)緩存,默認(rèn)是no enable-cache service <yes|no>
#為成功請求的元素設(shè)置緩存TTL,單位是秒,值越大緩存命中率越高,降低平均響應(yīng)時間,但會增加緩存的一致性問題 positive-time-to-live service value
#為失敗查詢元素設(shè)置緩存TTL,單位是秒,應(yīng)保持小值,減小緩存一致性問題 negative-time-to-live service value
#內(nèi)部的散列表大小,value應(yīng)該保持一個素數(shù)以達(dá)到優(yōu)化效果。默認(rèn)值是211 suggested-size service value
#啟用或者禁用檢查文件是否屬于指定的服務(wù),這些文件是/etc/passwd、/etc/group、/etc/hosts、/etc/services、/etc/netgroup等 check-files service <yes|no>
#設(shè)置緩存在服務(wù)器重啟后,仍舊能提供緩存服務(wù),在使用偏執(zhí)模式時有用,默認(rèn)是no persistent service <yes|no>
#為客戶端共享nscd數(shù)據(jù)庫在內(nèi)存中做的映射,使客戶端可以直接搜索,而不用每次都查詢守護(hù)進(jìn)行,默認(rèn)是no shared service <yes|no>
#該數(shù)據(jù)庫的最大大小,單位是bytes,默認(rèn)是33554432 max-db-size service bytes
#此選項僅使用于passwd和group服務(wù) auto-propagate service <yes|no>


使用NSCD對DNS進(jìn)行緩存

DNS在服務(wù)器上的作用:

在需要通過域名與外界進(jìn)行數(shù)據(jù)交互的時候,dns緩存就派上用場了,它可以減少域名解析的時間,提高效率。例如以下情況
    使用爬蟲采集網(wǎng)絡(luò)上的頁面數(shù)據(jù),
    使用auth3.0協(xié)議從其他平臺(如微博或QQ)獲取用戶數(shù)據(jù),
    使用第三方支付接口,
    使用短信通道下發(fā)短信等.

開啟NSCD DNS緩存服務(wù)的優(yōu)點和缺點

優(yōu)點:

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

DNS服務(wù)器掛了也沒有問題,在緩存服務(wù)時間范圍內(nèi),解析依舊正常

缺點:

DNS解析信息會滯后,如域名解析更改需要手動刷新緩存,NSCD不適合做實時的切換的應(yīng)用,目前對于依賴DNS切換的服務(wù),建議不要開啟DNS緩存。DNS Cache作為普通的DNS解析Cache那是沒問題的,如果你使用RDS云服務(wù)器,也不建議使用DNS緩存服務(wù)。

配置DNS緩存:

通過編輯/etc/nscd.conf文件,在其中增加如下一行可以開啟本地DNS Cache

enable-cache hosts yes #這個服務(wù)除了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服務(wù)查看和清除

NSCD緩存DB文件在/var/db/nscd下。可以通過nscd -g查看統(tǒng)計的信息:

# 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

以上就是“l(fā)inux nscd怎么開啟”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學(xué)習(xí)更多的知識,請關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI