BIT451 Network and System Administration

Network and System AdministrationUnit 98 min read

Linux Server Admin: CUPS, Job Scheduling & Maintenance

Unit 9 of Network and System Administration covers Linux server administration fundamentals, focusing on CUPS (printing), job scheduling with Cron/Crontab, server monitoring, and maintenance processes—essential for managing enterprise servers in real-world IT environments.

TAKEAWAYS:

  • CUPS provides a standardized printing system in Linux, supporting network printers and advanced features like job queuing and authentication.
  • Cron automates repetitive tasks via scheduled jobs, while Crontab defines user-specific schedules using a 5-field time specification.
  • Linux server maintenance includes upgrades, log monitoring, and performance tuning to ensure reliability and security.
  • Job scheduling prioritizes tasks based on system load, user needs, and resource availability.
  • Server monitoring tools like top, htop, and nmon track CPU, memory, disk, and network usage in real-time.
  • Online upgrades minimize downtime by patching services incrementally, while offline upgrades require full system reboots.

Core Concepts: Linux Server Administration

1. CUPS (Common Unix Printing System)

CUPS is the default printing system in modern Linux distributions, replacing older systems like LPD (Line Printer Daemon). It supports:

  • Network printing (via IPP/HTTP)
  • Print job queuing and management
  • Authentication and access control
  • Driverless printing (using PPD files)
How CUPS Works
graph LR
    A["Client Application"] -->|"Print Request"| B["CUPS Scheduler"]
    B -->|"Queues Job"| C["CUPS Backend"]
    C -->|"Sends to Printer"| D["Printer"]
    D -->|"Prints"| E["Output"]
    F["CUPS Filter"] -->|"Converts Data"| C
    G["CUPS Admin"] -->|"Configures"| B

Key Components:

Component Role
cupsd Daemon that manages print requests and queues.
lp/lpr Command-line tools for submitting print jobs.
lpadmin Configures printers and classes.
lpstat Displays printer status and job queues.
CUPS Web Interface GUI for managing printers (port 631).
Worked Example: Setting Up a Network Printer
  1. Install CUPS (if not pre-installed):

    sudo apt install cups  # Debian/Ubuntu
    sudo dnf install cups  # Fedora/RHEL
    
  2. Add a Network Printer:

    lpadmin -p OfficePrinter -E -v ipp://192.168.1.100 -m everywhere
    
    • -p: Printer name.
    • -E: Encrypted connection.
    • -v: Printer URI (IPP protocol).
    • -m: Driver (e.g., everywhere for auto-detection).
  3. Test Printing:

    lp testpage
    

Real-World Tie-In:

  • eSewa’s Backend Systems: CUPS manages print jobs for receipts at eSewa kiosks, ensuring high availability and job prioritization during peak hours (e.g., Dashain/Tihar).
  • Bank ATM Receipts: CUPS handles thermal printer jobs for transaction receipts in Nabil Bank’s Linux-based ATM servers, with strict job scheduling to avoid delays.

2. Job Scheduling with Cron and Crontab

Cron is a time-based job scheduler in Linux, used to automate tasks like backups, log rotations, and system maintenance.

Cron Syntax

Crontab files use a 5-field time specification:

* * * * *  command_to_execute
│ │ │ │ │
│ │ │ │ └─ Day of the week (0-6, 0=Sunday)
│ │ │ └──── Month (1-12)
│ │ └────── Day of the month (1-31)
│ └──────── Hour (0-23)
└────────── Minute (0-59)

Example Crontab Entry:

0 3 * * * /usr/bin/backup.sh  # Runs daily at 3 AM
  • Special Characters:
    • * = Every time unit.
    • , = List items (e.g., 1,3,5 = 1st, 3rd, 5th hour).
    • - = Range (e.g., 10-15 = 10th to 15th minute).
    • / = Step value (e.g., */15 = every 15 minutes).
Worked Example: Scheduling a Database Backup
  1. Create a Backup Script (/usr/local/bin/db_backup.sh):
    #!/bin/bash
    mysqldump -u admin -pPassword database_name > /backups/db_$(date +\%Y-\%m-\%d).sql
    
  2. Add to Crontab:
    crontab -e
    
    Insert:
    0 2 * * 1 /usr/local/bin/db_backup.sh  # Weekly backup at 2 AM on Mondays
    

Real-World Tie-In:

  • NTC’s Network Monitoring: Cron schedules ping sweeps and log rotations on NTC’s Linux routers to detect outages before they affect internet traffic.
  • Khalti’s Payment Processing: Cron triggers nightly reconciliation jobs to match transactions with bank statements, ensuring financial accuracy.

3. Linux Server Maintenance

Maintenance ensures server reliability, security, and performance. Key tasks:

  1. Upgrades:
    • Online Upgrades: Patch services incrementally (e.g., apt upgrade).
    • Offline Upgrades: Full system reboot (e.g., kernel updates).
  2. Monitoring:
    • Tools:
      • top/htop: Real-time process monitoring.
      • nmon: Advanced system metrics (CPU, memory, disk, network).
      • journalctl: Log management (systemd).
    • Example:
      htop          # Interactive process viewer
      nmon          # Comprehensive system monitor
      
  3. Log Management:
    • Rotate logs with logrotate to prevent disk space issues.
    • Example /etc/logrotate.conf:
      /var/log/syslog {
          daily
          missingok
          rotate 7
          compress
          delaycompress
          notifempty
          create 640 root adm
          sharedscripts
          postrotate
              /usr/lib/rsyslog/rsyslog-rotate
          endscript
      }
      

Real-World Tie-In:

  • Daraz’s Order Fulfillment: Cron schedules inventory updates and logrotate ensures warehouse systems don’t crash from log bloat during Diwali sales.
  • NEPSE’s Trading Server: nmon tracks CPU usage on NEPSE’s Linux servers to prevent crashes during high-volume trading (e.g., budget speeches).

4. Job Scheduling Priorities

Linux uses nice values (nice/renice) and priority queues to manage task urgency:

  • Nice Value: -20 (highest priority) to 19 (lowest).
    nice -n -5 ./long_running_task  # Higher priority
    renice -n 10 -p 1234             # Lower priority for PID 1234
    
  • Workload Management: Use at for one-time delayed jobs:
    echo "/usr/bin/cleanup.sh" | at 3:00 AM tomorrow
    

Comparison Table: Scheduling Tools

Tool Use Case Syntax Example
Cron Recurring tasks 0 * * * * command
At One-time delayed tasks echo "cmd" | at 15:00
Nice Adjust process priority nice -n 10 ./script.sh
Batch Run when system load is low batch ./backup.sh

Visual Aids


sequenceDiagram
    participant Client
    participant CUPS
    participant Printer
    Client->>CUPS: lp testpage
    CUPS->>CUPS: Queue Job
    CUPS->>Printer: IPP Protocol
    Printer-->>CUPS: ACK
    CUPS-->>Client: Job ID
stateDiagram-v2
    [*] --> Idle
    Idle --> Running: Job Submitted
    Running --> Completed: Task Finishes
    Running --> Failed: Error Occurs
    Completed --> [*]
    Failed --> [*]
erDiagram
    CRONTAB ||--o{ JOB : "schedules"
    CRONTAB {
        string user
        string schedule
    }
    JOB {
        string command
        int priority
    }

Exam Tip

  1. CUPS Questions:

    • Expect configuration commands (e.g., lpadmin, cupsctl).
    • Know port numbers (631 for CUPS web interface).
    • Troubleshooting: Use lpstat -p to check printer status.
  2. Cron/Crontab:

    • Memorize the 5-field syntax and special characters.
    • Practice writing realistic crontab entries (e.g., daily backups, hourly log rotations).
    • Common Pitfalls:
      • Forgetting to use absolute paths in scripts.
      • Incorrect time zones (use TZ environment variable if needed).
  3. Server Maintenance:

    • Differentiate online vs. offline upgrades.
    • Know monitoring tools (top, nmon, journalctl) and their flags.
    • Logrotate: Understand rotate, compress, and postrotate directives.
  4. Job Priorities:

    • Explain nice values and their impact on system performance.
    • Compare Cron, At, and Batch for different use cases.

Pro Tip: For practical exams, always include command-line examples (e.g., lpstat -a, crontab -l) to demonstrate understanding. Use real-world scenarios (e.g., "How would you schedule a backup for a bank’s Linux server?") to structure long answers.

Based on the TU BIT syllabus for Network and System Administration (BIT451), unit 9.

Discussion

Loading…