0%
دليل شامل لأوامر استكشاف أخطاء الخوادم وإصلاحها (Troubleshooting)

دليل شامل لأوامر استكشاف أخطاء الخوادم وإصلاحها (Troubleshooting)

دليل مفصل للأوامر الأساسية لاستكشاف أخطاء الخوادم وإصلاحها، مع التركيز على تسجيل الأحداث (Logging) وتحليل السجلات.

I

InSkillCoach

· دقيقة

دليل شامل لأوامر استكشاف أخطاء الخوادم وإصلاحها (Troubleshooting)

دليل مفصل للأوامر الأساسية لاستكشاف أخطاء الخوادم وإصلاحها، مع التركيز على تسجيل الأحداث (Logging).

الأوامر الأساسية لتسجيل الأحداث

1. متابعة السجلات في الوقت الفعلي

# Suivi des logs système
tail -f /var/log/syslog

# Suivi des logs d'authentification
tail -f /var/log/auth.log

# Suivi des logs Apache
tail -f /var/log/apache2/access.log
tail -f /var/log/apache2/error.log

# Suivi des logs Nginx
tail -f /var/log/nginx/access.log
tail -f /var/log/nginx/error.log

# Suivi des logs MySQL
tail -f /var/log/mysql/error.log

2. تصفية السجلات

# Filtrage par erreur
grep "ERROR" /var/log/syslog

# Filtrage par date
grep "$(date +%Y-%m-%d)" /var/log/syslog

# Filtrage avec contexte
grep -A 5 -B 5 "ERROR" /var/log/syslog

# Filtrage avec exclusion
grep -v "INFO" /var/log/syslog

# Filtrage avec comptage
grep -c "ERROR" /var/log/syslog

3. تحليل السجلات

# Affichage des dernières lignes
tail -n 100 /var/log/syslog

# Affichage des premières lignes
head -n 100 /var/log/syslog

# Affichage avec numérotation
cat -n /var/log/syslog

# Affichage avec coloration
grep --color=auto "ERROR" /var/log/syslog

# Affichage avec horodatage
awk '{print $1, $2, $3}' /var/log/syslog

أوامر متقدمة لتسجيل الأحداث

1. تحليل السجلات باستخدام Awk

# Comptage des erreurs par heure
awk '{print $3}' /var/log/syslog | grep "ERROR" | sort | uniq -c

# Extraction des IPs des logs Apache
awk '{print $1}' /var/log/apache2/access.log | sort | uniq -c

# Analyse des codes de statut HTTP
awk '{print $9}' /var/log/apache2/access.log | sort | uniq -c

# Temps de réponse moyen
awk '{sum+=$10} END {print sum/NR}' /var/log/apache2/access.log

2. تحليل السجلات باستخدام Sed

# Suppression des lignes vides
sed '/^$/d' /var/log/syslog

# Remplacement de texte
sed 's/ERROR/ERREUR/g' /var/log/syslog

# Extraction de lignes spécifiques
sed -n '100,200p' /var/log/syslog

# Suppression des lignes contenant un mot
sed '/ERROR/d' /var/log/syslog

3. تحليل السجلات باستخدام Perl

# Extraction des erreurs avec contexte
perl -ne 'print if /ERROR/ .. /^$/;' /var/log/syslog

# Analyse des logs avec regex
perl -ne 'print if /(ERROR|WARNING)/' /var/log/syslog

# Formatage des logs
perl -pe 's/(\d{4}-\d{2}-\d{2})/$1/g' /var/log/syslog

أوامر مراقبة النظام

1. مراقبة الموارد

# Surveillance CPU
top
htop
mpstat 1

# Surveillance mémoire
free -m
vmstat 1

# Surveillance disque
df -h
iostat 1

# Surveillance réseau
netstat -tulpn
iftop

2. مراقبة العمليات

# Liste des processus
ps aux

# Arbre des processus
pstree

# Détails des processus
lsof -i
lsof -p <PID>

# Priorité des processus
nice -n -20 <commande>

3. مراقبة الخدمات

# État des services
systemctl status <service>

# Logs des services
journalctl -u <service>

# Suivi des logs en temps réel
journalctl -u <service> -f

# Filtrage des logs par priorité
journalctl -p err

أوامر التشخيص

1. تشخيص الشبكة

# Test de connectivité
ping <host>
traceroute <host>

# Test de ports
nc -zv <host> <port>
telnet <host> <port>

# Analyse réseau
tcpdump -i eth0
wireshark

2. تشخيص النظام

# Informations système
uname -a
lsb_release -a

# Informations matérielles
lshw
dmidecode

# Informations réseau
ifconfig
ip addr

3. تشخيص الأداء

# Profilage système
strace <commande>
ltrace <commande>

# Analyse de performance
perf top
perf record

# Analyse de mémoire
valgrind <programme>

أفضل الممارسات

  1. تنظيم السجلات

    • التدوير المنتظم للسجلات (Log Rotation)
    • ضغط السجلات القديمة
    • أرشفة السجلات المهمة
  2. تحليل السجلات

    • إعداد عوامل التصفية
    • إنشاء التقارير
    • المراقبة الاستباقية
  3. الصيانة

    • التنظيف المنتظم
    • التحقق من الصلاحيات
    • تحديث الإعدادات

سكربتات مفيدة

1. سكربت المراقبة

#!/bin/bash
# Surveillance des logs en temps réel
tail -f /var/log/syslog | while read line; do
    if echo "$line" | grep -q "ERROR"; then
        echo "[$(date)] $line" >> /var/log/errors.log
    fi
done

2. سكربت التحليل

#!/bin/bash
# Analyse des logs Apache
awk '{print $1}' /var/log/apache2/access.log | sort | uniq -c | sort -nr | head -n 10

3. سكربت الصيانة

#!/bin/bash
# Rotation des logs
find /var/log -type f -name "*.log" -mtime +7 -exec gzip {} \;

الخاتمة

يتطلب استكشاف أخطاء الخوادم وإصلاحها إتقانًا جيدًا لأوامر تسجيل الأحداث وتحليل السجلات. يغطي هذا الدليل الأوامر الأساسية والتقنيات المتقدمة لإدارة السجلات بكفاءة.

مصادر إضافية

InSkillCoach

نبذة عن InSkillCoach

خبير في التدريب والتقنيات

مدرّب متخصص في التقنيات المتقدمة والذكاء الاصطناعي، تدعمه شركة GNeurone Inc.

الشهادات:

  • AWS Certified Solutions Architect – Professional
  • شهادات Google Cloud
  • Microsoft Certified: DevOps Engineer Expert
  • Certified Kubernetes Administrator (CKA)
  • CompTIA Security+
559
130

التعليقات

التعليقات مدعومة عبر GitHub Discussions

سجّل الدخول باستخدام GitHub للمشاركة في النقاش

تم نسخ الرابط!