×ðÁú¿­Ê±¹ÙÍøµÇ¼

ÔõÑùʹÓÃLinux¾ÙÐÐÈÕÖ¾ÆÊÎöºÍ¹ÊÕÏÅŲé

ÔõÑùʹÓÃlinux¾ÙÐÐÈÕÖ¾ÆÊÎöºÍ¹ÊÕÏÅŲé

СÐò£º

ÔÚ¿ª·¢ºÍÔËάµÄÀú³ÌÖУ¬Óöµ½¹ÊÕϺÍÎÊÌâÊdz£¼ûµÄ¡£¶øÈÕÖ¾ÆÊÎöºÍ¹ÊÕÏÅŲéÊǽâ¾öÎÊÌâµÄÒ»ÖÖÓÐÓÃÊֶΡ£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃlinux¾ÙÐÐÈÕÖ¾ÆÊÎöºÍ¹ÊÕÏÅŲ飬²¢ÌṩÏà¹ØµÄ´úÂëʾÀý¡£

Ò»¡¢ÈÕÖ¾ÆÊÎö

Éó²éÈÕÖ¾Îļþ

ÔÚLinuxϵͳÖУ¬ÈÕÖ¾Îļþͨ³£´æ·ÅÔÚ/var/logĿ¼Ï¡£³£¼ûµÄÈÕÖ¾Îļþ°üÀ¨/var/log/messages¡¢var/log/syslog¡¢/var/log/auth.logµÈ¡£Í¨¹ýÉó²éÕâЩÈÕÖ¾Îļþ£¬¿ÉÒÔ»ñȡϵͳµÄÔËÐÐ״̬ºÍ¿ÉÄܱ£´æµÄÎÊÌâ¡£

ʹÓÃcatÏÂÁîÉó²éÈÕÖ¾ÎļþµÄÄÚÈÝ¡£ÀýÈ磬Éó²é/var/log/messagesÎļþ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ

cat /var/log/messages

µÇ¼ºó¸´ÖÆ

¹ýÂËÈÕÖ¾ÐÅÏ¢

ÈôÊÇÈÕÖ¾Îļþ¹ý´ó£¬ÎÒÃÇ¿ÉÒÔʹÓÃһЩÏÂÁîÐй¤¾ßÀ´¹ýÂ˲¢²éÕÒÌض¨µÄÈÕÖ¾ÐÅÏ¢¡£

ÀýÈ磬ʹÓÃgrepÏÂÁîͨ¹ýÒªº¦×Ö²éÕÒÌض¨µÄÈÕÖ¾ÐÅÏ¢¡£ÒÔÏÂÏÂÁ²éÕÒ°üÀ¨Òªº¦×Ö”error”µÄÈÕÖ¾ÐÅÏ¢£º

grep "error" /var/log/messages

µÇ¼ºó¸´ÖÆ

ÈÕÖ¾Ðýת

Ϊ×èÖ¹ÈÕÖ¾Îļþ¹ý´ó£¬ÏµÍ³»á×Ô¶¯¾ÙÐÐÈÕÖ¾Ðýת£¨logrotate£©¡£ÈÕÖ¾Ðýת»á½«Ä¿½ñÈÕÖ¾Îļþ±¸·Ý£¬²¢½¨ÉèÒ»¸öеĿÕÎļþ¡£

¿ÉÒÔʹÓÃlsÏÂÁîÉó²éÈÕÖ¾ÎļþÒÔ¼°±¸·ÝÎļþ£º

ls -lh /var/log/messages*

µÇ¼ºó¸´ÖÆ

¶þ¡¢¹ÊÕÏÅŲé

Éó²éϵͳ״̬

ʹÓÃtopÏÂÁî¿ÉÒÔÉó²éÄ¿½ñϵͳµÄÔËÐÐ״̬¡£topÏÂÁî¿ÉÒÔÏÔʾCPUºÍÄÚ´æµÄʹÓÃÇéÐΣ¬ÒÔ¼°ÕýÔÚÔËÐеÄÀú³Ì¡£

top

µÇ¼ºó¸´ÖÆ

Éó²éÀú³ÌÐÅÏ¢

ʹÓÃpsÏÂÁî¿ÉÒÔÉó²éϵͳÖÐÕýÔÚÔËÐеÄÀú³Ì¡£¿ÉÒÔÍŽágrepÏÂÁî²éÕÒÌض¨µÄÀú³Ì¡£

ps -ef | grep "httpd"

µÇ¼ºó¸´ÖÆ

Éó²éÍøÂçÅþÁ¬

ʹÓÃnetstatÏÂÁî¿ÉÒÔÉó²éÄ¿½ñϵͳµÄÍøÂçÅþÁ¬ÇéÐΡ£¿ÉÒÔÉó²éTCP¡¢UDPÅþÁ¬£¬ÒÔ¼°¼àÌýµÄ¶Ë¿ÚºÅ¡£

netstat -an

µÇ¼ºó¸´ÖÆ

Éó²éϵͳ×ÊÔ´

ʹÓÃdfÏÂÁî¿ÉÒÔÉó²é´ÅÅÌ¿Õ¼äµÄʹÓÃÇéÐΡ£

df -h

µÇ¼ºó¸´ÖÆ

ʹÓÃfreeÏÂÁî¿ÉÒÔÉó²éÄÚ´æµÄʹÓÃÇéÐΡ£

free -h

µÇ¼ºó¸´ÖÆ

ʹÓÃiostatÏÂÁî¿ÉÒÔÉó²é´ÅÅ̺ÍCPUµÄʹÓÃÇéÐΡ£

iostat

µÇ¼ºó¸´ÖÆ

Èý¡¢´úÂëʾÀý

ÏÂÃæÊÇÒ»¸ö¼òÆӵľ籾ʾÀý£¬ÓÃÓÚÆÊÎöÈÕÖ¾ÎļþÖÐÌض¨Òªº¦×ֵķºÆð´ÎÊý£º

#!/bin/bash

log_file="/var/log/messages"
keyword="error"

count=$(grep -c "$keyword" "$log_file")

echo "Keyword "$keyword" appears $count times in "$log_file"."

µÇ¼ºó¸´ÖÆ

ÉúÑÄÒÔÉϾ籾Ϊlog_analysis.sh£¬Ê¹ÓÃÒÔÏÂÏÂÁîÔËÐо籾£º

bash log_analysis.sh

µÇ¼ºó¸´ÖÆ

¾ç±¾»áͳ¼ÆÈÕÖ¾Îļþ/var/log/messagesÖÐÒªº¦×Ö”error”µÄ·ºÆð´ÎÊý£¬²¢ÔÚÊä³öÖÐÏÔʾЧ¹û¡£

½áÂÛ£º

ͨ¹ýÈÕÖ¾ÆÊÎöºÍ¹ÊÕÏÅŲ飬ÎÒÃÇ¿ÉÒÔÏàʶϵͳµÄÔËÐÐ״̬ºÍÎÊÌ⡣ͨ¹ýºÏÀíÔËÓÃһЩÏÂÁîÐй¤¾ß£¬ÎÒÃÇ¿ÉÒÔ²éÕÒÌض¨µÄÈÕÖ¾ÐÅÏ¢£¬ÏàʶϵͳºÍÀú³ÌµÄÔËÐÐÇéÐΣ¬ÒÔ¼°¼ì²éϵͳ×ÊÔ´µÄʹÓÃÇéÐΡ£Í¬Ê±£¬±àдһЩ¼òÆӵľ籾ҲÄÜ×ÊÖúÎÒÃǸüÀû±ãµØ¾ÙÐÐÈÕÖ¾ÆÊÎöºÍ¹ÊÕÏÅŲ顣

Ï£Íû±¾ÎĵÄÄÚÈÝÄܹ»Îª¸÷ÈËÌṩһЩÓÐÓõÄÖ¸µ¼£¬×ÊÖú½â¾öÎÊÌâºÍÌá¸ßЧÂÊ¡£Ð»Ð»ÔĶÁ£¡

ÒÔÉϾÍÊÇÔõÑùʹÓÃLinux¾ÙÐÐÈÕÖ¾ÆÊÎöºÍ¹ÊÕÏÅŲéµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ