Linux OS Service ‘nscd’

This is the Name Service Cache Daemon. It takes care of group and password lookups for running programs and then caches the lookup results for the next query for services that can experience slowness in picking up changes such as NIS or LDAP. If you’re running these services, you may want to run nscd.

This daemon can cache data for name services, /etc/hosts, DNS, NIS, NIS+ etc. This is only for local users on the machine, because the cache is realized by wrapping the functions in glibc, remote user can never use this cache. It takes a time to change the cache even when the original DNS data is changed, therefore be careful to use this daemon.

Service Control

Example of “chkconfig –list [service]”

# chkconfig --list nscd
nscd            0:off   1:off   2:off   3:off   4:off   5:off   6:off

Available service usage options:

# service nscd
Usage: /etc/init.d/nscd {start|stop|status|restart|reload|condrestart}

Starting the service:

# service nscd start
Starting nscd:                                             [  OK  ]

Stopping the service:

# service nscd stop
Stopping nscd:                                             [  OK  ]

Check the status of the service:

# service nscd status
nscd (pid 15382) is running...

Restarting the service:

# service nscd restart
Stopping nscd:                                             [  OK  ]
Starting nscd:                                             [  OK  ]

Reloading the service to re-read the configuration file:

# service nscd reload
Reloading nscd:                                            [  OK  ]

Conditional restart of the service:

# service nscd condrestart
Stopping nscd:                                             [  OK  ]
Starting nscd:                                             [  OK  ]

– Which daemons does it run : /usr/sbin/nscd
– Which modules does it load : none

Configuration

Example configuration file:

# nscd will run as "nscd" user and not as root.
        server-user             nscd

# nscd set no debug output. if level is higher than 0, nscd will create some debug output, the higher the level, the more output is produced
        debug-level             0

# disable paranoia mode, nscd will not restart itself periodically
        paranoia                no

# enables the specified service "passwd" cache
        enable-cache            passwd          yes

# Sets the TTL (time-to-live) for positive entries (successful queries) in the specified cache for "passwd" to 600 seconds

        positive-time-to-live   passwd          600

# Sets the TTL (time-to-live) for negative entries (unsuccessful queries) in  the  specified  cache for "passwd" to 20 seconds
        negative-time-to-live   passwd          20

# Sets the internal hash table size to 211
        suggested-size          passwd          211

# Enables checking the file belonging to the specified service "passwd" for changes
        check-files             passwd          yes

# Keep the content of the cache for service "passwd" over server restarts;
        persistent              passwd          yes

# The memory mapping of the nscd databases for service "passwd" is shared with the clients
        shared                  passwd          yes

# The maximum allowable size for the service "passwd" set to be 33554432 bytes
        max-db-size             passwd          33554432

# The .byname requests will add to passwd.byuid or group.bygid cache.
        auto-propagate          passwd          yes

Troubleshooting

Sometimes restart, stop or start of the NSCD daemon, it will not flush it’s cache, you need use following method to explicitly flush the old cache:
Before CentOS/RHEL 7:

# service nscd reload

After CentOS/RHEL 7:

# systemctl restart nscd
Related Post