Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Advanced Troubleshooting - Linux

Introduction

Advanced troubleshooting in Linux involves diagnosing and resolving complex issues that go beyond basic troubleshooting techniques. This tutorial will cover various methods and tools used for advanced troubleshooting, providing detailed explanations and examples for each.

1. System Logs

System logs are a crucial resource for troubleshooting. They provide detailed information about system events and can help identify the root cause of issues.

Common log files include:

  • /var/log/syslog - General system log
  • /var/log/auth.log - Authentication log
  • /var/log/kern.log - Kernel log

To view a log file, use the cat or less command:

cat /var/log/syslog
[Output of syslog]

2. Disk Space Issues

Running out of disk space can cause various issues. To check disk usage, use the df command:

df -h
Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 20G 27G 43% / tmpfs 2.0G 0 2.0G 0% /dev/shm

To find large files and directories, use the du command:

du -sh /var/*
2.0G /var/log 1.5G /var/lib 100M /var/cache

3. Network Issues

Network issues can be challenging to diagnose. Start by checking the network configuration and status using the ifconfig or ip command:

ifconfig
eth0 Link encap:Ethernet HWaddr 00:1a:4b:16:01:59 inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

To check connectivity, use the ping command:

ping -c 4 google.com
PING google.com (172.217.14.206) 56(84) bytes of data. 64 bytes from lhr25s12-in-f14.1e100.net (172.217.14.206): icmp_seq=1 ttl=54 time=10.1 ms 64 bytes from lhr25s12-in-f14.1e100.net (172.217.14.206): icmp_seq=2 ttl=54 time=10.2 ms

4. System Performance

Monitoring system performance is essential for identifying bottlenecks. Use the top command to view real-time system performance:

top
top - 15:30:01 up 3:20, 2 users, load average: 0.07, 0.08, 0.09 Tasks: 150 total, 1 running, 149 sleeping, 0 stopped, 0 zombie %Cpu(s): 2.0 us, 1.0 sy, 0.0 ni, 96.0 id, 1.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem: 2048576 total, 1029384 used, 1019192 free, 120000 buffers

For detailed performance analysis, use htop (if installed):

htop
[Output of htop]

5. Process Management

Managing processes is vital for system stability. Use the ps command to list running processes:

ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.1 22528 1564 ? Ss 15:00 0:01 /sbin/init

To terminate a process, use the kill command followed by the process ID (PID):

kill 1234

6. Memory Usage

Monitoring memory usage helps prevent system crashes. Use the free command to view memory usage:

free -m
total used free shared buff/cache available Mem: 2000 1000 500 100 500 900 Swap: 1000 200 800

7. File System Issues

File system issues can lead to data loss. Use the fsck command to check and repair file systems:

sudo fsck /dev/sda1
fsck from util-linux 2.36 e2fsck 1.45.6 (20-Mar-2020) /dev/sda1: clean, 1000/131072 files, 50000/524288 blocks

Conclusion

Advanced troubleshooting in Linux requires a deep understanding of the system and the ability to use various tools effectively. By mastering these techniques, you can diagnose and resolve complex issues to maintain system stability and performance.