Linux is the backbone of modern-day DevOps, serving as the primary OS for servers, containers, and cloud environments. This guide describes the most important Linux administration tasks with which DevOps engineers must be familiar in order to manage infrastructure effectively and ensure smooth operations of CI/CD pipelines.
Linux Administration in the DevOps is mainly related to the management and automation of the Linux system to support applications for deployment, scalability, and reliability. Through Linux, DevOps engineers can configure server, host, or deploy containerized applications with system stability support, making it crucial.
Monitoring ensures the health and performance of Linux servers. Common tools include:
-
top, htop: View real-time resource usage.
-
vmstat, iostat: Monitor CPU and I/O statistics.
-
sar: Collect, report, and save system activity.
-
nmon: Visualize system metrics like CPU, memory, and network usage.
Managing user accounts and permissions is vital to secure multi-user systems.
Commands:
-
useradd, usermod, passwd: Manage users.
-
groupadd, gpasswd: Manage groups.
-
chown, chmod: Set file permissions.
Best Practices:
- Use least-privilege principles.
- Employ sudo for controlled administrative access.
Linux distributions rely on package managers to install, update, and remove software.
-
Debian-based (e.g., Ubuntu):
- Commands: apt, dpkg
-
Red Hat-based (e.g., CentOS, RHEL):
- Commands: yum, dnf, rpm
-
Use automation tools like Ansible or Chef for large-scale package management.
Efficient file management ensures organized and secure systems.
-
Commands:
-
ls, cd, mkdir, rmdir: Directory navigation and creation.
-
cp, mv, rm: File operations.
-
find, locate, grep: Search files.
-
tar, gzip, rsync: Compress and sync files.
-
-
Pro Tip: Use rsync for efficient backup and file transfer.
Disk management ensures proper utilization and storage capacity.
-
Commands:
- df, du: Check disk usage.
- mount, umount: Manage mounted filesystems.
- fdisk, lsblk: Partition management.
-
Implement LVM (Logical Volume Management) for flexible storage.
Linux servers often act as network nodes, requiring proper setup and monitoring.
- Commands:
- ifconfig, ip: View and configure network interfaces.
- netstat, ss: Analyze network connections.
- iptables, firewalld: Manage firewall rules.
- Tools:
- tcpdump, nmap: Network debugging and scanning.
- ping, traceroute: Diagnose network issues.
Manage active processes and services for system stability.
- Commands:
- ps, top, kill: Process management.
- systemctl, service: Manage system services.
- Tip: Automate service monitoring with tools like Monit or Nagios.
Automation reduces manual effort and ensures consistency.
- Write reusable scripts for tasks like backups, log rotations, or updates.
- Use tools like cron or at to schedule scripts.
Ensure system security by:
- Implementing firewalls and SELinux/AppArmor.
- Regularly applying patches and updates.
- Enforcing SSH key-based authentication.
- Monitoring login attempts using fail2ban.
Plan robust backup strategies to prevent data loss.
- Tools:
- rsync: Incremental backups.
- tar, gzip: File-based backups.
- Automate periodic backups and test restore processes.
Logs help diagnose and audit system activities.
- Use tools like Logrotate to manage log file sizes.
- Centralize logs with ELK Stack (Elasticsearch, Logstash, Kibana).
Optimize the kernel for specific workloads:
- Adjust kernel parameters with sysctl.
- Analyze system bottlenecks with perf, dstat, or iotop.
Problem: A service consumes excessive CPU.
Solution:
- Use top to identify the process.
- Check logs or configurations for anomalies.
- Adjust system limits in /etc/security/limits.conf.
Problem: Applications experience slow network responses.
Solution:
- Diagnose with ping and traceroute.
- Use tcpdump or iftop for deeper analysis.
- Optimize configurations in /etc/sysctl.conf.
Problem: A server runs out of disk space.
Solution:
- Identify large files with **du -sh ***.
- Archive or delete unnecessary files.
- Extend storage using LVM or mount new partitions.