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

LinuxÇéÐÎϵÄÈÕÖ¾ÆÊÎö¼¼ÇÉÓëÒªÁì

linuxÇéÐÎϵÄÈÕÖ¾ÆÊÎö¼¼ÇÉÓëÒªÁì

СÐò£º

ÔÚLinuxϵͳÖУ¬ÈÕÖ¾ÎļþÊǺÜÊÇÖ÷ÒªµÄ×ÊÔ´£¬¿ÉÒԼͼϵͳÔËÐÐ״̬¡¢¹ýʧÐÅÏ¢¡¢Óû§ÐÐΪµÈÖÖÖÖÊý¾Ý¡£Í¨¹ý¶ÔÈÕÖ¾ÎļþµÄÆÊÎö£¬ÎÒÃÇ¿ÉÒÔ¸üºÃµØÏàʶϵͳµÄÔËÐÐ״̬£¬ÊµÊ±·¢Ã÷ÎÊÌâ²¢×÷³öÏìÓ¦µÄ´¦Àí¡£±¾ÎĽ«ÏÈÈÝһЩÔÚLinuxÇéÐÎϾÙÐÐÈÕÖ¾ÆÊÎöµÄ¼¼ÇɺÍÒªÁ죬²¢¸ø³öÏìÓ¦µÄ´úÂëʾÀý¡£

Ò»¡¢ÈÕÖ¾ÎļþµÄλÖúÍÃûÌÃ

ÔÚLinuxϵͳÖУ¬ÈÕÖ¾Îļþͨ³£±»´æ·ÅÔÚ/var/logĿ¼Ï£¬²î±ðµÄϵͳºÍÓ¦ÓóÌÐò»áÌìÉú²î±ðµÄÈÕÖ¾Îļþ¡£³£¼ûµÄÈÕÖ¾ÎļþÈçÏ£º

ϵͳÈÕÖ¾£º/var/log/messages»ò/var/log/syslog

ϵͳÈÕÖ¾¼Í¼ÁËϵͳµÄÔËÐÐ״̬¡¢ÄÚºËÐÅÏ¢¡¢Ð§ÀÍÆô¶¯ÐÅÏ¢µÈ¡£

Çå¾²ÈÕÖ¾£º/var/log/secure»ò/var/log/auth.log

Çå¾²ÈÕÖ¾Ö÷Òª¼Í¼ÁËÓû§µÇ¼¡¢È¨Ïޱ任¡¢Çå¾²ÊÂÎñµÈÏà¹ØÐÅÏ¢¡£

Ó¦ÓóÌÐòÈÕÖ¾£º/var/log/application.log

²î±ðµÄÓ¦ÓóÌÐò»áÓÐ×Ô¼ºµÄÈÕÖ¾Îļþ£¬ÓÃÓڼͼӦÓóÌÐòÔËÐÐʱµÄ¹ýʧÐÅÏ¢¡¢µ÷ÊÔÐÅÏ¢µÈ¡£

¶þ¡¢Éó²éÈÕÖ¾ÎļþµÄÄÚÈÝ

ÔÚLinuxÇéÐÎÏ£¬ÎÒÃÇͨ³£Ê¹ÓÃÒÔÏÂÏÂÁîÀ´Éó²éÈÕÖ¾ÎļþµÄÄÚÈÝ£º

catÏÂÁÓÃÓÚÔÚÖÕ¶ËÖÐÊä³öÎļþµÄÄÚÈÝ£¬¿ÉÒÔʹÓÃcatÏÂÁîÉó²éСÐÍÈÕÖ¾Îļþ£¬Ê¾ÀýÏÂÁîÈçÏ£º

cat /var/log/messages

µÇ¼ºó¸´ÖÆ

lessÏÂÁÓÃÓÚÖðÒ³ÏÔʾÎļþµÄÄÚÈÝ£¬±ÈcatÏÂÁî¸üÊʺÏÉó²é´óÐÍÈÕÖ¾Îļþ£¬Ê¾ÀýÏÂÁîÈçÏ£º

less /var/log/application.log

µÇ¼ºó¸´ÖÆ

tailÏÂÁÓÃÓÚÉó²éÎļþµÄ×îºó¼¸ÐÐÄÚÈÝ£¬³£ÓÃÓÚʵʱÉó²éÈÕÖ¾ÎļþµÄ¸üÐÂÇéÐΣ¬Ê¾ÀýÏÂÁîÈçÏ£º

tail -f /var/log/syslog

µÇ¼ºó¸´ÖÆ

Èý¡¢Õë¶ÔÈÕÖ¾Îļþ¾ÙÐйýÂ˺ÍËÑË÷

ÓÐʱ¼äÎÒÃÇÖ»¶ÔÈÕÖ¾ÎļþÖеÄijЩÌض¨ÐиÐÐËȤ£¬ÎÒÃÇ¿ÉÒÔͨ¹ýһЩ¹¤¾ßºÍÏÂÁî¾ÙÐйýÂ˺ÍËÑË÷²Ù×÷¡£

grepÏÂÁÓÃÓÚÔÚÎļþÖÐËÑË÷Ö¸¶¨µÄ×Ö·û´®£¬Ê¾ÀýÏÂÁîÈçÏ£º

grep "error" /var/log/application.log

µÇ¼ºó¸´ÖÆ

awkÏÂÁÓÃÓÚ¶ÔÎļþ¾ÙÐÐÖðÐд¦Àí£¬¿ÉÒÔƾ֤Ìض¨µÄ¹æÔòÌáÈ¡ÎļþÖеÄÊý¾Ý£¬Ê¾ÀýÏÂÁîÈçÏ£º

awk '/error/ {print}' /var/log/application.log

µÇ¼ºó¸´ÖÆ

sedÏÂÁÓÃÓÚ¶ÔÎļþÖеÄÎı¾¾ÙÐÐÌæ»»¡¢É¾³ý»ò²åÈë²Ù×÷£¬Ê¾ÀýÏÂÁîÈçÏ£º

sed '/error/d' /var/log/application.log

µÇ¼ºó¸´ÖÆ

ËÄ¡¢Ê¹ÓÃShell¾ç±¾¾ÙÐÐ×Ô¶¯»¯ÆÊÎö

ÔÚÈÕÖ¾ÆÊÎöÀú³ÌÖУ¬ÎÒÃÇͨ³£ÐèÒª¶ÔÈÕÖ¾Îļþ¾ÙÐжà´ÎËÑË÷¡¢¹ýÂË»òÅÌËã²Ù×÷¡£Ê¹ÓÃShell¾ç±¾¿ÉÒÔ×ÊÖúÎÒÃÇ×Ô¶¯»¯ÕâЩ²Ù×÷£¬Ìá¸ßÊÂÇéЧÂÊ¡£ÏÂÃæÊÇÒ»¸öʹÓÃShell½ÅÔ­À´Í³¼Æij¸öÒªº¦×ÖÔÚÈÕÖ¾ÎļþÖзºÆð´ÎÊýµÄʾÀý£º

#!/bin/bash

logfile="/var/log/application.log"
keyword="error"
count=0

while read line
do
    if echo $line | grep -q $keyword
    then
        count=$((count+1))
    fi
done < "$logfile"

echo "The keyword "$keyword" appears $count times in the log file."

µÇ¼ºó¸´ÖÆ

Î塢ʹÓù¤¾ß¾ÙÐи߼¶ÈÕÖ¾ÆÊÎö

ÈôÊÇÐèÒª¾ÙÐиüÖØ´óµÄÈÕÖ¾ÆÊÎöºÍ´¦Àí£¬ÎÒÃÇ¿ÉÒÔʹÓÃһЩרҵµÄ¹¤¾ßÀ´×ÊÖúÎÒÃÇÍê³É£¬ÈçELK£¨Elasticsearch, Logstash, Kibana£©µÈ¡£ÕâЩ¹¤¾ß¿ÉÒÔ½«ÈÕÖ¾Êý¾Ý´æ´¢ÔÚÊý¾Ý¿âÖУ¬²¢ÌṩǿʢµÄËÑË÷¡¢¹ýÂË¡¢¿ÉÊÓ»¯µÈ¹¦Ð§£¬µ«Ïà¶ÔÖØ´óһЩ¡£

½áÓ

ÈÕÖ¾ÆÊÎöÊÇLinuxϵͳÖÎÀíºÍ¹ÊÕÏɨ³ýµÄÖ÷Òª»·½Ú¡£Í¨¹ý±¾ÎÄÏÈÈݵļ¼ÇɺÍÒªÁ죬ÎÒÃÇ¿ÉÒÔ¸üºÃµØÃ÷È·ºÍʹÓÃÈÕÖ¾Îļþ£¬²¢Äܹ»¸ü¿ìËٵض¨Î»Ï¢Õù¾öÎÊÌ⡣ϣÍû±¾ÎĶԶÁÕßÔÚÈÕÖ¾ÆÊÎö·½ÃæÓÐËù×ÊÖú¡£

²Î¿¼ÎÄÏ×£º

The Linux Command Line, William E. Shotts, Jr.

LinuxÏÂÁîÐÐÓëShell¾ç±¾±à³Ì´óÈ«£¬W. Richard StevensµÈÖø

ÒÔÉϾÍÊÇLinuxÇéÐÎϵÄÈÕÖ¾ÆÊÎö¼¼ÇÉÓëÒªÁìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ