DevOps Planning to Production Day 1 of 24 : Getting Started with Red Hat Linux
Kanav Gathe
Posted on November 27, 2024
Introduction to Red Hat Linux
Think of an operating system like a conductor in an orchestra, coordinating all the different instruments (hardware components) to create a harmonious performance. Red Hat Linux is a professional-grade conductor, known for its reliability and enterprise support.
Red Hat Linux is a specialized version of Linux designed for business environments. Imagine you're building a house - while regular Linux distributions might be like basic building tools from a hardware store, Red Hat Linux is like having professional-grade construction equipment with a dedicated support team.
Key features that make Red Hat Linux special:
- Enterprise Support: You have access to professional help 24/7, like having an expert on call.
- Long-term Stability: Updates and security patches continue for up to 10 years, ensuring your system stays secure.
- Certified Software Compatibility: Programs are thoroughly tested to work together, like pieces of a puzzle designed to fit perfectly.
- Security Features: Built-in protection mechanisms, like having a state-of-the-art security system for your house.
File System Management
The Linux file system is organized like a tree, starting from a single point called the "root" directory (/). Let's understand each major directory and its purpose:
/ (Root Directory)
│
├── /home # User personal directories (like individual bedrooms)
├── /etc # System configuration files (like the house's control panel)
├── /var # Variable data like logs (like a diary of system events)
├── /bin # Essential commands (like basic household tools)
├── /usr # User programs (like entertainment systems)
├── /tmp # Temporary files (like a scratch pad)
└── /boot # Files needed to start the system (like startup instructions)
Let's explore how to manage this file system with practical examples:
# Creating directories (like creating rooms in a house)
mkdir -p /home/projects/website
# The -p flag creates parent directories if they don't exist
# Moving files (like moving furniture between rooms)
mv /home/old_documents/* /home/archive/
# Copying files (like making duplicates of important documents)
cp -r /etc/httpd/conf/ /etc/httpd/conf.backup/
# The -r flag copies directories recursively
# Finding files (like searching for something in your house)
find /home -name "*.pdf" -mtime -7
# This finds all PDF files modified in the last 7 days
User and Group Administration
Managing users and groups in Linux is like managing employees in a company. Let's explore this with practical examples:
# Creating a new user (like hiring a new employee)
useradd -m -s /bin/bash john
# -m creates a home directory
# -s sets their default shell
# Setting a password
passwd john
# Creating a group (like creating a department)
groupadd developers
# Adding a user to a group (like assigning someone to a department)
usermod -aG developers john
# -a means append
# -G specifies the group
# Setting up project permissions
mkdir /projects/webapp
chown john:developers /projects/webapp
chmod 775 /projects/webapp
Understanding file permissions:
- Read (r): Like being able to view a document (4 in numeric notation)
- Write (w): Like being able to edit a document (2 in numeric notation)
- Execute (x): Like being able to run a program (1 in numeric notation)
Example permission settings:
chmod 755 script.sh
# 7 (owner): read + write + execute (4+2+1)
# 5 (group): read + execute (4+1)
# 5 (others): read + execute (4+1)
Package Management with YUM
YUM (Yellowdog Updater Modified) is like a smart package delivery service for your system. It handles:
- Installing new software
- Updating existing software
- Removing unwanted software
- Managing dependencies (other software needed for programs to work)
Common YUM commands with real-world examples:
# Updating the entire system
yum update -y
# The -y flag automatically answers "yes" to prompts
# Installing a web server
yum install httpd php mysql-server -y
# This installs multiple packages at once
# Searching for packages
yum search "web server"
# Shows all packages related to web servers
# Removing packages
yum remove unused-package -y
# Cleaning up
yum clean all
# Removes temporary files and cached data
System Services and Systemd
Systemd is like a master control panel for your system services. Here's how to manage services:
# Starting a service (like turning on an appliance)
systemctl start httpd
# Checking service status
systemctl status httpd
# Shows if the service is running and recent log entries
# Enabling service to start at boot
systemctl enable httpd
# Like setting an appliance to turn on automatically
# Restarting a service
systemctl restart httpd
# Viewing service logs
journalctl -u httpd
# Shows detailed logs for the service
Networking Configuration
Understanding networking in Linux is like understanding how mail gets delivered. Let's break it down:
Basic Network Configuration
# Viewing network interfaces
ip addr show
# Shows all network interfaces and their IP addresses
# Configuring a network interface
nmcli con mod eth0 \
ipv4.addresses "192.168.1.100/24" \
ipv4.gateway "192.168.1.1" \
ipv4.dns "8.8.8.8"
# Like setting up a new mailing address and route
# Testing network connectivity
ping -c 4 google.com
# Sends test packets to check connection
Understanding IP and Netmask
An IP address is like a street address, and a netmask defines the neighborhood:
# Example IP configuration
ip addr add 192.168.1.100/24 dev eth0
# /24 means the first 24 bits define the network (like the street)
# The remaining 8 bits are for individual addresses (like house numbers)
Security and Permissions
Security in Linux is like having multiple layers of protection in a building:
Basic Security Configuration
# Setting up a basic firewall
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
# Like setting up security checkpoints
# Checking for open ports
ss -tuln
# Shows which ports are listening for connections
# Setting up SELinux (Security-Enhanced Linux)
setenforce 1
# Enables strict security policies
System Performance Monitoring
Monitoring your system is like keeping track of a car's dashboard indicators:
# Real-time system monitoring
top
# Shows CPU, memory, and process information
# Disk usage monitoring
df -h
# Shows disk space usage in human-readable format
# Memory usage
free -m
# Shows memory usage in megabytes
# Creating a monitoring script
cat << 'EOF' > /usr/local/bin/monitor.sh
#!/bin/bash
while true; do
echo "=== System Status ==="
date
echo "CPU Usage:"
top -bn1 | grep "Cpu(s)"
echo "Memory Usage:"
free -m
echo "Disk Usage:"
df -h /
sleep 60
done
EOF
chmod +x /usr/local/bin/monitor.sh
Storage Management
Managing storage in Linux is like organizing a warehouse:
# Creating a new partition
fdisk /dev/sdb
# Interactive tool for partition management
# Creating a filesystem
mkfs.xfs /dev/sdb1
# Like preparing a storage area for use
# Mounting storage
mount /dev/sdb1 /data
# Making the storage accessible
# Automatic mounting (in /etc/fstab)
echo "/dev/sdb1 /data xfs defaults 0 0" >> /etc/fstab
# Ensures storage is mounted at boot
Backup and Restore
Implementing a reliable backup system is crucial. Here's a comprehensive backup script:
#!/bin/bash
# Configuration
BACKUP_DIR="/backup"
SOURCE_DIRS=("/etc" "/home" "/var/www")
DATE=$(date +%Y%m%d)
RETENTION_DAYS=30
# Create backup directory
mkdir -p "$BACKUP_DIR"
# Backup function
backup_directory() {
local source_dir="$1"
local backup_name="$(basename $source_dir)_$DATE.tar.gz"
echo "Backing up $source_dir..."
tar -czf "$BACKUP_DIR/$backup_name" "$source_dir"
if [ $? -eq 0 ]; then
echo "Backup of $source_dir completed successfully"
else
echo "Backup of $source_dir failed"
fi
}
# Perform backups
for dir in "${SOURCE_DIRS[@]}"; do
backup_directory "$dir"
done
# Clean old backups
find "$BACKUP_DIR" -type f -mtime +$RETENTION_DAYS -delete
echo "Backup process completed"
Posted on November 27, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 27, 2024