DEV Community

Janak Shrestha
Janak Shrestha

Posted on

Linux Services

As per details shared by the development team, the new application release has some dependencies on the back end. There are some packages/services that need to be installed on all app servers under Stratos Datacenter. As per requirements please perform the following steps:

a. Install nscd package on all the application servers.

b. Once installed, make sure it is enabled to start during boot.


Solution

Step 1: Connect to Each App Server and Install nscd

App Server 1 (stapp01) - User: tony

ssh tony@stapp01
# Password: Ir0nM@n
sudo su -
# Password: Ir0nM@n
yum install -y nscd
systemctl enable nscd
exit
exit
Enter fullscreen mode Exit fullscreen mode

App Server 2 (stapp02) - User: steve

ssh steve@stapp02
# Password: Am3ric@
sudo su -
# Password: Am3ric@
yum install -y nscd
systemctl enable nscd
exit
exit
Enter fullscreen mode Exit fullscreen mode

App Server 3 (stapp03) - User: banner

ssh banner@stapp03
# Password: BigGr33n
sudo su -
# Password: BigGr33n
yum install -y nscd
systemctl enable nscd
exit
exit
Enter fullscreen mode Exit fullscreen mode

One-Line Commands

App Server 1 (stapp01):

echo 'Ir0nM@n' | ssh tony@stapp01 "sudo -S bash -c 'yum install -y nscd && systemctl enable nscd'"
Enter fullscreen mode Exit fullscreen mode

App Server 2 (stapp02):

echo 'Am3ric@' | ssh steve@stapp02 "sudo -S bash -c 'yum install -y nscd && systemctl enable nscd'"
Enter fullscreen mode Exit fullscreen mode

App Server 3 (stapp03):

echo 'BigGr33n' | ssh banner@stapp03 "sudo -S bash -c 'yum install -y nscd && systemctl enable nscd'"
Enter fullscreen mode Exit fullscreen mode

Using Heredoc (Recommended)

App Server 1:

ssh tony@stapp01 << 'EOF'
echo 'Ir0nM@n' | sudo -S bash -c '
echo "=== Installing nscd on stapp01 ==="
yum install -y nscd
echo ""
echo "=== Enabling nscd ==="
systemctl enable nscd
echo ""
echo "=== Verification ==="
systemctl is-enabled nscd
rpm -qa | grep nscd
'
EOF
Enter fullscreen mode Exit fullscreen mode

App Server 2:

ssh steve@stapp02 << 'EOF'
echo 'Am3ric@' | sudo -S bash -c '
echo "=== Installing nscd on stapp02 ==="
yum install -y nscd
echo ""
echo "=== Enabling nscd ==="
systemctl enable nscd
echo ""
echo "=== Verification ==="
systemctl is-enabled nscd
rpm -qa | grep nscd
'
EOF
Enter fullscreen mode Exit fullscreen mode

App Server 3:

ssh banner@stapp03 << 'EOF'
echo 'BigGr33n' | sudo -S bash -c '
echo "=== Installing nscd on stapp03 ==="
yum install -y nscd
echo ""
echo "=== Enabling nscd ==="
systemctl enable nscd
echo ""
echo "=== Verification ==="
systemctl is-enabled nscd
rpm -qa | grep nscd
'
EOF
Enter fullscreen mode Exit fullscreen mode

Automated Script (Run from Jump Host)

#!/bin/bash

echo "========================================="
echo "Installing nscd on All App Servers"
echo "========================================="

# stapp01
echo ""
echo "=== stapp01 (tony) ==="
ssh tony@stapp01 << 'EOF'
echo 'Ir0nM@n' | sudo -S bash -c '
yum install -y nscd
systemctl enable nscd
echo "Status: $(systemctl is-enabled nscd)"
rpm -qa | grep nscd
'
EOF

# stapp02
echo ""
echo "=== stapp02 (steve) ==="
ssh steve@stapp02 << 'EOF'
echo 'Am3ric@' | sudo -S bash -c '
yum install -y nscd
systemctl enable nscd
echo "Status: $(systemctl is-enabled nscd)"
rpm -qa | grep nscd
'
EOF

# stapp03
echo ""
echo "=== stapp03 (banner) ==="
ssh banner@stapp03 << 'EOF'
echo 'BigGr33n' | sudo -S bash -c '
yum install -y nscd
systemctl enable nscd
echo "Status: $(systemctl is-enabled nscd)"
rpm -qa | grep nscd
'
EOF

echo ""
echo "========================================="
echo "✅ nscd installed and enabled on all servers!"
echo "========================================="
Enter fullscreen mode Exit fullscreen mode

Expected Output

[root@stapp01 ~]# yum install -y nscd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package nscd.x86_64 0:2.34-277.el9 will be installed
--> Finished Dependency Resolution

Dependencies Resolved
================================================================================
 Package          Arch          Version                 Repository      Size
================================================================================
Installing:
 nscd             x86_64        2.34-277.el9            baseos         157 k

Transaction Summary
================================================================================
Install  1 Package

Installed:
  nscd-2.34-277.el9.x86_64

Complete!

[root@stapp01 ~]# systemctl enable nscd
Created symlink /etc/systemd/system/multi-user.target.wants/nscd.service → /usr/lib/systemd/system/nscd.service.

[root@stapp01 ~]# systemctl is-enabled nscd
enabled

[root@stapp01 ~]# rpm -qa | grep nscd
nscd-2.34-277.el9.x86_64
Enter fullscreen mode Exit fullscreen mode

Step-by-Step Interactive Commands

# Connect to each server
ssh tony@stapp01
# Password: Ir0nM@n

# Become root
sudo su -
# Password: Ir0nM@n

# Install nscd
yum install -y nscd

# Enable nscd to start on boot
systemctl enable nscd

# Verify installation
rpm -qa | grep nscd

# Verify enabled status
systemctl is-enabled nscd

# Check service status (not started yet, only enabled)
systemctl status nscd

# Exit
exit
exit
Enter fullscreen mode Exit fullscreen mode

Verification Commands

# 1. Check package installation
rpm -qa | grep nscd

# 2. Check if service is enabled
systemctl is-enabled nscd
# Expected: enabled

# 3. Check service status
systemctl status nscd
# Expected: loaded, enabled (may not be running)

# 4. Check symlink created
ls -la /etc/systemd/system/multi-user.target.wants/nscd.service

# 5. Verify on all servers
for server in stapp01 stapp02 stapp03; do
    echo "=== $server ==="
    ssh tony@$server "systemctl is-enabled nscd && rpm -qa | grep nscd"
done
Enter fullscreen mode Exit fullscreen mode

Understanding nscd

What is nscd?

nscd (Name Service Cache Daemon) is a service that provides caching for name service requests. It caches passwd, group, hosts, services, and netgroup lookups, improving performance and reducing load on LDAP or NIS servers.

Service Management Commands

Command Purpose
systemctl start nscd Start the service immediately
systemctl enable nscd Enable to start on boot
systemctl status nscd Check current status
systemctl is-enabled nscd Check if enabled on boot
systemctl stop nscd Stop the service

Difference Between Start and Enable

  • Start: Runs the service now
  • Enable: Configures the service to start on boot

The task requires only enabling, not starting the service.

Alternative Methods

Method 1: Install and enable in one command

yum install -y nscd && systemctl enable nscd
Enter fullscreen mode Exit fullscreen mode

Method 2: Using dnf (if available)

dnf install -y nscd && systemctl enable nscd
Enter fullscreen mode Exit fullscreen mode

Method 3: Using service command (legacy)

yum install -y nscd
chkconfig nscd on
Enter fullscreen mode Exit fullscreen mode

Troubleshooting

  1. "Package nscd not found":
   # Search for the package
   yum search nscd
   # Check repositories
   yum repolist
Enter fullscreen mode Exit fullscreen mode
  1. "Failed to enable nscd":
   # Reload systemd
   systemctl daemon-reload
   # Try again
   systemctl enable nscd
Enter fullscreen mode Exit fullscreen mode
  1. "Permission denied":
   # Use sudo
   sudo yum install -y nscd
   sudo systemctl enable nscd
Enter fullscreen mode Exit fullscreen mode
  1. nscd already installed:
   # Just enable it
   systemctl enable nscd
Enter fullscreen mode Exit fullscreen mode

Complete Script (Run from Jump Host)

#!/bin/bash

echo "========================================="
echo "Installing nscd on All App Servers"
echo "========================================="

declare -A SERVERS=(
    ["stapp01"]="tony:Ir0nM@n"
    ["stapp02"]="steve:Am3ric@"
    ["stapp03"]="banner:BigGr33n"
)

for server in "${!SERVERS[@]}"; do
    IFS=':' read -r user pass <<< "${SERVERS[$server]}"
    echo ""
    echo "=== $server ($user) ==="

    ssh "$user@$server" << EOF
echo '$pass' | sudo -S bash -c '
echo "Installing nscd..."
yum install -y nscd

echo "Enabling nscd..."
systemctl enable nscd

echo "Verification:"
echo "  Package: \$(rpm -qa | grep nscd)"
echo "  Enabled: \$(systemctl is-enabled nscd)"
'
EOF
done

echo ""
echo "========================================="
echo "✅ nscd installed and enabled on all App servers!"
echo "========================================="
Enter fullscreen mode Exit fullscreen mode

Summary

  • nscd installed on stapp01, stapp02, stapp03
  • nscd enabled to start during boot on all servers
  • Package verified with rpm -qa | grep nscd
  • Enabled status verified with systemctl is-enabled nscd

The nscd package has been successfully installed and enabled on all App servers in the Stratos Datacenter.

Top comments (0)