0% found this document useful (0 votes)
2 views39 pages

DevOps Interview Notes

Notes for anyone doing a DevOps interview.

Uploaded by

Muazu Modibbo
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views39 pages

DevOps Interview Notes

Notes for anyone doing a DevOps interview.

Uploaded by

Muazu Modibbo
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DevOps Interview Notes

Linux
Managing files effectively is crucial in a DevOps role. Below are key commands
for handling files and directories:
1.1 Listing Files and Directories
• ls: Lists files and directories in the current directory.
o ls -l: Displays detailed information including permissions,
ownership, size, and modification date.
o ls -a: Shows all files, including hidden ones (those starting with a
dot .).
1.2 Creating and Removing Files
• touch: Creates an empty file or updates the timestamp of an existing file.
o Example: touch [Link]
• rm: Removes files.
o Example: rm [Link]
o Use rm -r to remove directories and their contents recursively.
1.3 Copying and Moving Files
• cp: Copies files or directories.
o Example: cp [Link] [Link]
o Use cp -r to copy directories recursively.
• mv: Moves or renames files or directories.
o Example: mv [Link] [Link]
1.4 Viewing File Contents
• cat: Concatenates and displays file content.
o Example: cat [Link]
• less: Allows scrolling through file content page by page.
o Example: less [Link]
• head: Displays the first few lines of a file.
o Example: head -n 10 [Link] (shows the first 10 lines)
• tail: Displays the last few lines of a file.
o Example: tail -n 10 [Link] (shows the last 10 lines)
1.5 Searching Within Files
• grep: Searches for patterns within files.
o Example: grep 'search_term' [Link]
o Use grep -r 'search_term' /path/to/directory to search recursively in
directories.
1.6 File Permissions and Ownership
• chmod: Changes file permissions.
o Example: chmod 755 [Link]
• chown: Changes file ownership.
o Example: chown user:group [Link]

2. Text Editing with vi/vim


vi (Visual Editor) and its improved version vim (Vi IMproved) are powerful text
editors commonly used in Unix-like systems. Proficiency in these editors is
valuable for editing configuration files and scripts.
2.1 Modes in vi/vim
vi/vim operates in multiple modes:
• Normal Mode: For navigation and command execution.
o Default mode upon opening a file.
• Insert Mode: For inserting and editing text.
o Enter by pressing i (insert before cursor) or a (insert after cursor).
• Visual Mode: For selecting text.
o Enter by pressing v.
• Command-Line Mode: For executing commands.
o Enter by pressing :.
2.2 Basic Commands
• Opening a File: vi [Link]
• Saving and Exiting:
o Save changes and exit: :wq
o Exit without saving: :q!
• Navigation:
o Move cursor up, down, left, right: Arrow keys or k, j, h, l respectively.
o Move to the beginning of the line: 0
o Move to the end of the line: $
• Editing:
o Delete a character: x
o Delete a line: dd
o Undo last change: u
o Redo undone change: Ctrl + r
• Searching:
o Search for a pattern: /pattern
o Navigate to next occurrence: n
o Navigate to previous occurrence: N
• Copying and Pasting:
o Copy (yank) a line: yy
o Paste below cursor: p
o Paste above cursor: P

3. Understanding the Unix/Linux File System

3.1 Inodes
An inode (index node) is a data structure that stores information about files and
directories, excluding their names or actual data. It contains metadata such as
permissions, ownership, timestamps, and pointers to data blocks. Each file or
directory is associated with an inode identified by a unique inode number.

3.1 Inodes (continued)


Key Characteristics of Inodes:
• Metadata Stored in an Inode:
o File type (regular file, directory, symbolic link, etc.).
o Permissions (read, write, execute for owner, group, others).
o Owner and group IDs (UID and GID).
o File size.
o Number of hard links (how many names point to the inode).
o Timestamps (creation, last modification, last access).
o Pointers to data blocks storing the file's actual content.
• Inode Number:
o Each inode is uniquely identified by a number within a file system.
o You can view inode numbers with ls -i.
Relationship Between Inodes and File Names:
• File names are stored in directory entries, which map to inodes.
• This separation allows multiple file names (hard links) to point to the
same inode.
Commands to Work with Inodes:
• ls -i: Displays the inode number of files and directories.
o Example: ls -i filename
• find with inodes:
o Find a file by its inode number: find /path -inum inode_number -
exec ls -ld {} \;
df -i : to list available inodes in filesystems
Practical DevOps Applications:
• Understanding inodes is crucial for managing files and diagnosing issues
like "disk full" errors when inodes are exhausted (even if space is
available).
• When migrating or backing up data, tools like rsync maintain inode-
related metadata.

3.2 File System Hierarchy Standard (FHS)


The Unix/Linux file system follows a standardized hierarchy for organizing files
and directories.
Key Directories:
1. / (Root):
o Top-level directory; contains all other directories.
o Only accessible by the root user for sensitive operations.
2. /home:
o Contains user-specific directories (e.g., /home/username).
o Stores personal files and configurations for each user.
3. /etc:
o Contains system-wide configuration files.
o Examples: /etc/fstab (file system table), /etc/passwd (user
accounts).
4. /var:
o Stores variable data like logs, caches, and mail spools.
o Example: /var/log/syslog.
5. /tmp:
o Temporary files created by applications.
o Automatically cleared at reboot or after a certain period.
6. /usr:
o Stores user-installed software and libraries.
o Subdirectories include:
▪ /usr/bin: Binary executables.
▪ /usr/lib: Libraries for installed software.
▪ /usr/share: Shared data (e.g., icons, documentation).
7. /dev:
o Contains device files representing hardware like disks, terminals,
and USB devices.
o Example: /dev/sda (first hard disk).
8. /proc and /sys:
o Virtual file systems that provide real-time system information.
o Example: /proc/cpuinfo (CPU details), /sys/class/net (network
interfaces).

3.3 File Links (Hard vs. Soft Links)


Hard Links:
• A hard link is an additional name for an existing inode.
• All hard links share the same inode number.
• Changes to one hard link affect the underlying file.
• Deleting one hard link does not remove the file unless all hard links are
deleted.
Commands:
• Create a hard link: ln file1 file2
• Example: ln [Link] [Link]
Soft (Symbolic) Links:
• A soft link is a shortcut or pointer to another file or directory.
• It has a different inode from the original file.
• If the original file is deleted, the soft link becomes broken.
Commands:
• Create a soft link: ln -s target_file link_name
• Example: ln -s [Link] [Link]
Practical Differences:
Feature Hard Link Soft Link
Inode Same as the original file Different inode
Cross-file systems Not supported Supported
Link breaks No Yes (if target is deleted)

3.4 Common File System Commands


df (Disk Free Space):
• Displays available disk space on file systems.
• Example: df -h
Output in human-readable format (e.g., GB, MB).
du (Disk Usage):
• Shows the size of files and directories.
• Example: du -sh /path/to/dir
mount and umount:
• mount: Attaches a file system to a directory.
o Example: mount /dev/sda1 /mnt
• umount: Detaches a file system.
o Example: umount /mnt
fsck (File System Check):
• Checks and repairs file system errors.
• Example: fsck /dev/sda1

# Resource Management in Linux: Processes, cgroups, init, and systemd

Resource management in Linux involves efficiently allocating and managing


system resources like CPU, memory, disk I/O, and network bandwidth. This is
crucial for maintaining system stability and performance, especially in multi-
user environments or containerized systems.

## 1. Processes
A **process** is an instance of a program in execution. Processes are the
foundation of Linux's resource management.

### Process Lifecycle


1. **Creation**:
- Processes are created using the `fork()` system call, which duplicates the
parent process.
- The `exec()` system call replaces the process image with a new program.
2. **States**:
- **Running (`R`)**: Actively executing on the CPU.
- **Sleeping (`S`)**: Waiting for an event (e.g., I/O).
- **Stopped (`T`)**: Stopped by a signal or for debugging.
- **Zombie (`Z`)**: Process terminated but parent hasn’t collected its exit
status.

### Parent-Child Relationships


- Every process has a **parent** and can spawn **child processes**.
- Use commands like `pstree`, `ps -ef`, or `/proc/<PID>/stat` to analyze
process hierarchies.

### Process Management


- **`ps`**: Displays active processes.
- **`kill`**: Sends signals to processes (e.g., `kill -9 <PID>`).
- **`nice`/`renice`**: Adjusts process priority.
- **`htop`**: Interactive process monitoring tool.

---

## 2. cgroups (Control Groups)


Control Groups (cgroups) are a Linux kernel feature that provides resource
management by grouping processes. It allows fine-grained control over
resources like CPU, memory, and I/O.

### Features
1. **Resource Limiting**:
- Restrict resources for specific processes.
- Example: Limit a group to use only 1GB of RAM.
2. **Resource Monitoring**:
- Track how much of a resource a group is using.
3. **Resource Isolation**:
- Isolate processes to prevent interference.
4. **Hierarchy**:
- cgroups are structured hierarchically, allowing inheritance of resource rules.

### Controllers
- **CPU**: Limits CPU time.
- **Memory**: Restricts memory usage.
- **BlkIO**: Controls disk I/O bandwidth.
- **NetCls**: Manages network bandwidth.

### Commands
- **`systemd-cgls`**: Displays the cgroup hierarchy.
- ‘systemd-cgtop’ : displays real time resource usage of cgroup
- **`cgcreate`**: Creates a new cgroup.
- **`cgexec`**: Runs a process in a specific cgroup.
- **`/proc/<PID>/cgroup`**: Shows cgroup details of a process.

### Practical Usage


- Container orchestration systems like Docker and Kubernetes use cgroups for
resource isolation.

--- PID = Process Identification

## 3. `init` and System Initialization


In Linux systems, the init process is the first process that the kernel starts
during booting. It has a process ID (PID) of 1 and is responsible for initializing
the system, setting up the user environment, and managing system processes.
Traditionally, the init system used a simple, linear approach to start services,
which could lead to slower boot times.

### Historical Context


1. **SysVinit**:
- Traditional initialization system.
- Used a configuration file `/etc/inittab` to define runlevels.
- Sequential service startup.
2. **Modern Init Systems**:
- Address limitations of SysVinit.
- Examples: `systemd`, `Upstart`, `OpenRC`.

### Role of `init`


- Starts essential services and daemons.
- Manages runlevels or targets (in `systemd`).
- Reaps zombie processes.

---

## 4. systemd
`systemd` is a modern init system and service manager used by most Linux
distributions. It provides advanced features for managing system resources
and services.

### Features
1. **Parallel Service Startup**:
- Speeds up boot time by starting services in parallel.
2. **Service Management**:
- Manages services using `systemctl`.
- Example: `systemctl start nginx`.
3. **Socket-Based Activation**:
- Starts services on-demand when their socket is accessed.
4. **Logging**:
- Integrated logging via `journald`.

### Key Components


- **Units**:
- Represent resources like services (`.service`), targets (`.target`), and mount
points (`.mount`).
- **Targets**:
- Group services to achieve a specific state (e.g., `[Link]`).
- **Timers**:
- Replace cron jobs with `.timer` units.

### Commands
- **`systemctl`**:
- Manage services: `systemctl start/stop/restart <service>`.
- Check status: `systemctl status <service>`.
- **`journalctl`**:
- View logs: `journalctl -u <service>`.

In Linux systems managed by systemd, processes are organized and managed


using units, each serving a specific purpose in resource control and process
management. Here's a brief overview of the key unit types and resource
controllers:
Service Units (.service):
• Definition: Represent system services, typically involving processes
started and managed by systemd based on unit configuration files.
• Purpose: Encapsulate one or more processes to be managed
collectively, allowing for controlled startup, monitoring, and termination.
Scope Units (.scope):
• Definition: Represent groups of externally created processes that are
managed by systemd but not initiated by it.
• Purpose: Allow systemd to manage and supervise processes started
outside its control, such as those initiated by user commands or scripts.
Slice Units (.slice):
• Definition: Organize and hierarchically group service and scope units,
forming a tree structure for resource management.
• Purpose: Distribute system resources among groups of units, enabling
administrators to set resource limits and priorities across different slices.
Resource Controllers (Cgroup Controllers):
• Definition: Kernel components that enforce resource limits and
constraints on cgroups (control groups).
• Purpose: Manage and allocate system resources like CPU, memory, and
I/O bandwidth among different cgroups to ensure fair distribution and
prevent resource starvation.
Commonly Used Cgroup Controllers:
• CPU Controller: Manages CPU access and scheduling.
• Memory Controller: Limits and accounts for memory usage.
• IO Controller: Controls and monitors input/output access to block
devices.
To manage cgroups (control groups) integrated with systemd, several
commands are available to set and modify resource parameters. Here's a
summary of key commands:
1. Setting Properties with systemctl set-property:
o Adjust resource control settings for systemd units.
o Example: To set the CPU weight for a service: systemctl set-
property <service_name> CPUWeight=<value>
Replace <service_name> with the name of the service and <value> with the
desired CPU weight.
2. Creating Transient Units with systemd-run:
o Start a transient service or scope unit with specific resource limits.
o Example: To run a command in a transient scope with a memory
limit: systemd-run --scope -p MemoryLimit=<value> <command>
Replace <value> with the memory limit (e.g., '500M') and <command> with the
command to execute.
3. Viewing the Control Group Hierarchy with systemd-cgls:
o Display the cgroup hierarchy and running processes.
o Example: systemd-cgls
This command shows the hierarchy of control groups and their associated
processes.
4. Monitoring Resource Usage with systemd-cgtop:
o Monitor resource usage by cgroups.
o Example: systemd-cgtop
This provides a top-like interface displaying resource usage per cgroup.
5. Listing Units with systemctl list-units:
o List active systemd units, including slices and services.
o Example: systemctl list-units --type=slice
This lists all active slice units.
6. Displaying Unit Status with systemctl status:
o Show detailed status of a specific unit, including cgroup
information.
o Example: systemctl status <unit_name>
Replace <unit_name> with the name of the unit to view its status.

7. Modifying Unit Files for Persistent Changes:


o Edit unit files to set resource limits persistently.
o Example: To set a memory limit for a service:
▪ Edit the unit file or create a drop-in file: systemctl edit
<service_name>

▪ Add the following lines:


[Service]
MemoryLimit=<value>
Replace <value> with the desired memory limit.

8. Reloading Systemd Configuration:


o Apply changes made to unit files.
o Example: systemctl daemon-reload
o This reloads systemd manager configuration.

### Example Process Tree


Using `pstree`:
```
systemd─┬─NetworkManager
├─cron
├─sshd───bash───pstree
├─nginx───nginx
├─dbus-daemon
├─systemd-journald
└─systemd-logind
```

## 5. Importance in DevOps
1. **Resource Management**:
- cgroups ensure containers or processes do not overuse resources.
- Use `systemd` for advanced service management.
2. **Monitoring and Troubleshooting**:
- Tools like `htop`, `ps`, and `journalctl` help diagnose performance issues.
3. **Automation**:
- `systemd` timers and units simplify recurring tasks.
4. **Containerization**:
- cgroups and namespaces isolate containers in Docker or Kubernetes.

---

## Summary
Resource management in Linux is a cornerstone of system performance and
stability. Understanding processes, cgroups, `init`, and `systemd` equips
DevOps engineers to manage resources efficiently, automate tasks, and
ensure system reliability.
Understanding Systemd Units and Unit Files
Systemd is a system and service manager for Linux operating systems,
designed to provide a unified interface for managing system resources. A
fundamental concept within systemd is the "unit," which represents a resource
that systemd can manage. Each unit is defined by a unit file, specifying how
systemd should handle the resource.
Types of Systemd Units:
Systemd categorizes units based on the type of resource they represent. Each
unit type is identified by a specific suffix:
• .service: Manages services or applications, detailing how to start, stop,
and manage the service.
• .socket: Defines network or IPC sockets, often paired with a
corresponding .service unit for socket-based activation.
• .device: Represents hardware devices recognized by udev or sysfs,
allowing systemd to manage device-related events.
• .mount: Specifies mount points for filesystems, enabling systemd to
manage mounting and unmounting operations.
• .automount: Configures mount points that are automatically mounted
when accessed, working in conjunction with .mount units.
• .swap: Manages swap space on the system, defining how swap areas are
activated and deactivated.
• .target: Groups units to reach a specific system state, similar to runlevels
in traditional init systems.
• .path: Monitors file system paths and triggers actions when specified
conditions are met, utilizing inotify for monitoring.
• .timer: Schedules tasks to run at specific times or intervals, analogous
to cron jobs but integrated with systemd.
• .snapshot: Captures the current state of units, allowing the system to
return to this state later; primarily used for system recovery.
• .slice: Associates with Linux Control Groups (cgroups) to manage and
allocate system resources among processes.
• .scope: Represents externally created processes that systemd manages,
typically not started by systemd itself.
Structure of a Unit File:
Unit files are plain text files divided into sections, each containing directives
that define the unit's behavior:
• [Unit]: Provides general information about the unit, including a
description and dependencies.
• [Service]: Specific to service units; defines how the service should start,
stop, and behave during execution.
• [Install]: Contains information related to the installation of the unit, such
as when it should be enabled or started.
Each section contains directives in the format DirectiveName=value. For
example, in the [Service] section, the ExecStart directive specifies the
command to start the service.
Unit File Locations and Overrides:
Systemd searches for unit files in multiple directories, with precedence
determined by the directory's priority:
1. /etc/systemd/system/: Highest priority; contains user-defined unit files
and overrides.
2. /run/systemd/system/: Runtime units, typically generated during
system operation.
3. /lib/systemd/system/: Standard unit files installed by the distribution's
packages.
To modify a unit's behavior without altering the original unit file, administrators
can create "drop-in" files. These are placed in a directory named after the unit
with a .d suffix (e.g., [Link].d/) and contain .conf files with the desired
overrides.
Managing Units with systemctl:
The systemctl command is the primary tool for interacting with systemd and its
units:
• Start a unit: systemctl start unit_name
• Stop a unit: systemctl stop unit_name
• Restart a unit: systemctl restart unit_name
• Reload a unit's configuration: systemctl reload unit_name
• Enable a unit to start at boot: systemctl enable unit_name
• Disable a unit from starting at boot: systemctl disable unit_name
• Check the status of a unit: systemctl status unit_name
• Listing All Active Units: systemctl list-units
• Listing All Unit Files (Loaded and Not Loaded): systemctl list-unit-files

Replace unit_name with the actual name of the unit, including its suffix (e.g.,
[Link]).
Advantages of Systemd Units:
Systemd units offer several benefits over traditional init systems:
• Parallel Service Startup: Systemd can start services in parallel,
reducing boot times.
• On-Demand Activation: Units can be activated based on socket, path,
device, or timer events, leading to efficient resource utilization.
• Dependency Management: Systemd automatically handles
dependencies between units, ensuring services start in the correct order.
• Resource Control: Integration with cgroups allows for precise resource
allocation and limitation for services.
• Extensibility: Drop-in files and templates enable easy customization
and scaling of unit configurations.

Understanding Targets:
• Definition: Targets are special unit files that group other units together,
allowing the system to be brought to a specific state. They are similar to
runlevels in traditional init systems.
• Common Targets:
o [Link]: Multi-user environment with a graphical
interface.
o [Link]: Multi-user, non-graphical (command line)
environment.
o [Link]: Single-user mode for rescue operations.
o [Link]: Emergency shell with the most minimal
environment.
• Changing the Active Target: systemctl isolate <target_name>
Example: systemctl isolate [Link]
• Setting the Default Target: systemctl set-default <target_name>
Example: systemctl set-default [Link]

D-Bus, short for Desktop Bus, is an inter-process communication (IPC)


system that allows different programs and processes within the same
computer to communicate and share information efficiently.
Key Concepts of D-Bus:
1. Inter-Process Communication (IPC):
o IPC refers to the methods and mechanisms that allow different
processes (running programs) to exchange data and signals. This is
essential for coordinating actions and sharing information
between separate applications or system components.
2. Message Bus:
o D-Bus operates on a message bus model, where a central daemon
(background service) facilitates communication by routing
messages between processes. This setup simplifies the
communication process, as each application only needs to
connect to the bus rather than establishing direct connections with
every other application.
3. Bus Types:
o System Bus: Used for communication between system services
and user applications, handling tasks like hardware events and
system notifications.
o Session Bus: Handles communication between applications
within a user's session, enabling desktop applications to interact
and coordinate with each other.
4. Bus Names and Object Paths:
o Each service connected to the D-Bus is identified by a unique bus
name, typically following a reverse domain name notation (e.g.,
[Link]).
o Within each service, specific functionalities are exposed through
objects identified by object paths (e.g.,
/org/freedesktop/NetworkManager).
5. Interfaces, Methods, and Signals:
o Interfaces: Define a set of methods and signals that an object
implements, similar to interfaces in object-oriented programming.
o Methods: Actions that can be invoked on an object (e.g., a method
to connect to a network).
o Signals: Notifications sent by objects to indicate events or
changes in state (e.g., a signal indicating a new device has been
connected).
How D-Bus Works:
• When an application wants to communicate with another via D-Bus, it
sends a message to the bus daemon. The daemon then routes this
message to the appropriate recipient based on the bus name and object
path specified. Messages can be of different types, including method
calls, method returns, errors, and signals.
Disk Management
The partition table tells the operating system how the partitions and files on the
disk are organized. MBR stands for Master Boot Record, which is a special
place at the start of the drive that contains information on how to partition it.
The MBR also contains the code that starts the operating system, sometimes
called the boot loader. GPT stores information about how all partitions are
organized and how the operating system is displayed on all drives.

Firmware acts as the intermediary between the hardware and the higher-level
software. It initializes hardware components and provides basic functions.

Boot loader is the program/code that load the kernel which starts the operating
system.
UEFI (Unified Extensible Firmware Interface) initializes hardware components
and loads the operating system.

1. /boot/efi Directory:
o UEFI systems use the /boot/efi directory to store boot loaders (like
GRUB2 or systemd-boot).
o This partition is formatted with vfat because:
▪ UEFI firmware requires a FAT32-compatible file system for
compatibility.
▪ FAT32 is simple, widely supported, and efficient for small
bootloader files.
2. BIOS and MBR:
o On older systems using BIOS, there’s no /boot/efi. Instead:
▪ The boot loader (e.g., GRUB) resides in the MBR (Master Boot
Record) or in a separate /boot partition.
o MBR only supports disks up to 2TB and allows up to 4 primary
partitions.
3. UEFI and GPT:
o UEFI systems typically use GPT (GUID Partition Table) for disk
partitioning.
o GPT supports larger disks and more partitions than MBR.
o The /boot/efi partition is mandatory in UEFI, and it must use FAT32
(vfat) to be recognized by the firmware.

FAT32 stands for File Allocation Table 32-bit and is an older file system widely
used for its simplicity and compatibility across operating systems. Works with
almost every operating system (Windows, macOS, Linux, etc.). EFI System
Partitions for UEFI boot loaders use FAT32 (formatted as vfat in Linux).

vfat (Virtual File Allocation Table) is an implementation of FAT32 on Linux.


Provides Linux support for FAT32, allowing you to mount and use FAT32
partitions.

xfs is a high-performance journaling file system developed by Silicon Graphics.


It’s optimized for speed and scalability, especially with large files and storage
systems.

ext4 (fourth extended file system) is the most widely used file system on Linux
systems. It’s the successor to ext3, with better performance and features.
Journaling is a feature of many modern file systems, like ext4 and xfs, that
helps ensure data integrity by keeping a record (or journal) of changes to the file
system before they are made permanent. Types: Metadata and Full journaling

GPT (GUID (Globally Unique Identifier) Partition Table) defines the layout of
partitions on a disk (e.g., where the /boot partition is located).

How GPT and EFI Boot Loader Work Together


1. Disk Setup with GPT:
o GPT defines partitions, including the EFI System Partition (ESP),
which stores the EFI boot loader.
2. UEFI Firmware and EFI Boot Loader:
o The UEFI firmware reads the GPT table to locate the ESP.
o It then executes the EFI boot loader stored in the ESP to load the
operating system.
free -h : to check free ram space
Differences between Centos and Ubuntu
File Types in Linux
There are three primary file types in Linux: regular files, directories, and special
files.
1. Regular files: These are the most common type of files, containing data
such as text, images, and program binaries.
2. Directories: Directories are containers that store and organize other files
and directories.
3. Special files: These files represent devices, such as hard drives,
terminals, or network interfaces, and facilitate communication between
the kernel and the device

Web Server
Check Apache for configuration errors again: sudo apachectl -t
This creates a symbolic link to the virtual host file in the sites-
enabled directory: sudo a2ensite [Link]

A web server is a system that delivers web content to clients over the internet
or an intranet. It processes incoming network requests over HTTP and several
other related protocols. Examples: Apache HTTP Server, Nginx, Microsoft IIS.

2. FTP Servers
An FTP (File Transfer Protocol) server facilitates the transfer of files between
computers over a network. Examples: vsftpd, ProFTPD, FileZilla Server. FTP
commands: ftp hostname, pwd, cd, put local_file remote_file, ls, get
remote_file local_file, delete remote_file

3. Client-Server Architecture
Client-server architecture is a network design where multiple clients (user
devices) request and receive services from centralized servers.
• Components:
o Client: The user interface that requests services or resources.
o Server: Provides services or resources to clients.
Add/Remove a Group from a User
usermod -aG <group> <user> # Add
gpasswd -d <user> <group> # Remove

Find files with specific perms


find /path -perm <mode>
find /var/www -perm 777
What is a Bash Alias?
• Shortcut for long commands: alias ll='ls -l'
Filesystem Errors
1. "Filesystem is full" but df shows free space:
o Cause: Inodes are exhausted. Check with:
bash
Copy code
df -i
2. Deleting a file but df not showing freed space:
o Cause: File is still held by a process. Use:
bash
Copy code
lsof | grep <filename>

Process and Thread


• Process: Independent execution unit with its own memory space.
• Thread: Lightweight unit within a process, sharing memory.

What Happens to Orphaned Processes?


• Orphaned processes are adopted by the init process (PID=1).
1. Understanding Linux Package Management
Linux package management encompasses the processes of installing,
updating, configuring, and removing software packages. Packages are bundled
files containing software programs and metadata, which include information
about dependencies and installation instructions. Package managers
streamline the handling of these packages, ensuring that software installations
are efficient and that dependencies are resolved automatically.
Key Components:
• Packages: Bundles containing software and metadata.
• Repositories: Centralized storage locations for packages.
• Package Managers: Tools that automate the management of packages.

2. High-Level vs. Low-Level Package Managers


Package management systems are typically divided into two tiers: high-level
and low-level package managers.
Low-Level Package Managers:
• Functionality: Directly handle the installation, removal, and querying of
individual package files.
• Dependency Management: Do not automatically resolve
dependencies; require manual intervention.
• Examples:
o dpkg: Utilized in Debian-based distributions.
o rpm: Employed in Red Hat-based distributions.
High-Level Package Managers:
• Functionality: Provide a user-friendly interface, managing packages and
their dependencies seamlessly.
• Dependency Management: Automatically resolve and install
dependencies.
• Repository Management: Interact with online repositories to fetch and
update packages.
• Examples:
o apt: Front-end for dpkg in Debian-based systems.
o yum/dnf: Front-ends for rpm in Red Hat-based systems.
In essence, low-level tools manage individual packages without handling
dependencies, while high-level tools offer a comprehensive solution, managing
packages, dependencies, and repositories.

In Ubuntu (Debian-based systems):


• Adding a Repository:
o Use the add-apt-repository command for Personal Package
Archives (PPAs):
sudo add-apt-repository ppa:repository-name/ppa
o For non-PPA repositories, manually edit a file in
/etc/apt/[Link].d/:
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/[Link]]
[Link] focal main" | sudo tee
/etc/apt/[Link].d/[Link]
• Adding a Signing Key (Post apt-key Deprecation):
o Download the GPG key and save it to /usr/share/keyrings/:
wget -qO- [Link] | sudo tee
/usr/share/keyrings/[Link]
o Use the signed-by option in the repository configuration to
reference the key:
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/[Link]]
[Link] focal main" | sudo tee
/etc/apt/[Link].d/[Link]
• Key Points:
o The signed-by directive ensures that only the specified GPG key is
used to validate packages from the repository.
o This approach enhances security and aligns with modern best
practices.

In CentOS (Red Hat-based systems):


• Adding a Repository:
o Create or edit a repository file in /etc/[Link].d/:
[repository-name]
name=Repository Name
baseurl=[Link]
enabled=1
gpgcheck=1
gpgkey=[Link]
How Do Interfaces Facilitate Internet Access?
• Network interfaces act as a bridge between the device and the network.
• An interface like eth0 has:
o An IP Address: Used for communication in a network.
o A MAC Address: Unique hardware identifier for the interface.
• The interface uses protocols like TCP/IP to communicate with other
devices or the internet.
Reserved addresses in cidr notation
Network Address:
• The first address in the range.
• All host bits in the subnet are set to 0.
Broadcast Address:
• The last address in the range.
• All host bits in the subnet are set to 1.
[Link]/24
The address used to send traffic to all devices in a subnet.
Derived from the IP address and subnet mask (e.g., [Link] for
[Link]/24).

Result:
• Network Address: [Link]
• Broadcast Address: [Link]
View Rules:
iptables -L -v -n --line-numbers
Add Rule:
iptables -A INPUT -p tcp --dport 22 -j ACCEPT (Allow SSH).
Delete Rule:
iptables -D INPUT 1 (Deletes rule 1 in INPUT chain).
Save Rules:
iptables-save > /etc/iptables/rules.v4
iptables-restore < /etc/iptables/rules.v4
Flush Rules:
iptables -F (Clears all rules in all chains).

If your system's iptables configuration uses multiple tables (e.g., filter, nat,
mangle, raw, security), running the command iptables -L would only display the
filter table by default. To view all tables and their chains, you would need to
use iptables-save or specify the table explicitly using the -t option.

Key Notes on Table-Specific Chains


• Filter Table:
o Default table for packet filtering.
o Chains: INPUT, FORWARD, OUTPUT.
• NAT Table:
o Used for Network Address Translation (e.g., port forwarding,
masquerading).
o Chains: PREROUTING, POSTROUTING, OUTPUT.
• Mangle Table:
o Used for modifying packets (e.g., TTL, DSCP marking).
o Chains: PREROUTING, INPUT, FORWARD, OUTPUT,
POSTROUTING.
• Raw Table:
o Used for bypassing connection tracking for specific packets.
o Chains: PREROUTING, OUTPUT.
• Security Table (less common):
o Used for Mandatory Access Control (MAC) rules.
o Chains: INPUT, FORWARD, OUTPUT.

Commands to View Specific Tables


1. Filter Table (default): iptables -L -v --line-numbers
2. NAT Table: iptables -t nat -L -v --line-numbers
3. Mangle Table: iptables -t mangle -L -v --line-numbers
4. Raw Table: iptables -t raw -L -v --line-numbers
5. Save All Tables: iptables-save
Difference Between Hardlinks and Symlinks
• Hardlink: Points directly to the inode; remains even if the original file is
deleted.
• Symlink: Points to the file path; breaks if the target is removed.
Backup

• Level 0 Backup: A full backup of all data, including files and directories,
regardless of previous backups.
• Incremental Backup: Saves only the data changed since the last backup
(full or incremental).

1. Initialize Docker Swarm


• Initialize Docker Swarm:
bash
Copy code
docker swarm init
• Verify the Swarm setup:
bash
Copy code
docker info
docker node ls

2. Create an Overlay Network


• Create a Swarm-compatible overlay network:
bash
Copy code
docker network create --driver overlay serpent-network
• Verify networks:
bash
Copy code
docker network ls
3. Deploy the Stack
• Deploy the stack using [Link]:
bash
Copy code
docker stack deploy -c [Link] serpent-swarm
• Verify services:
bash
Copy code
docker service ls
• Inspect a specific service:
bash
Copy code
docker service inspect serpent-swarm_backend
• Check service tasks:
bash
Copy code
docker service ps serpent-swarm_nginx-lb

4. Debug Issues
• Check service logs:
bash
Copy code
docker service logs serpent-swarm_backend

Validate the Compose File: Run this to ensure the YAML file is valid:
bash
Copy code
docker-compose config

docker network create --driver overlay --attachable serpent-swarm_serpent-


network

You might also like