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

LinuxÏÂÈÕÖ¾ÆÊÎöÓëÒì³£¼ì²âÒªÁìºÍÕ½ÂÔ

linuxÏÂÈÕÖ¾ÆÊÎöÓëÒì³£¼ì²âÒªÁìºÍÕ½ÂÔ

СÐò£º

Ëæ×Å»¥ÁªÍøµÄ¿ìËÙÉú³¤£¬ÖÖÖÖϵͳºÍÓ¦ÓóÌÐòµÄÈÕÖ¾±¬·¢Á¿Ò²Ô½À´Ô½´ó¡£¶Ô´ó×ÚÈÕÖ¾¾ÙÐÐÓÐÓõÄÆÊÎöºÍÒì³£¼ì²â³ÉΪÁË°ü¹ÜϵͳÕý³£ÔËÐк͹ÊÕÏÕï¶ÏµÄÖ÷Òª»·½Ú¡£ÔÚLinux²Ù×÷ϵͳÖУ¬ÓÐÐí¶àÓÅÒìµÄÈÕÖ¾ÆÊÎöºÍÒì³£¼ì²â¹¤¾ß£¬±¾ÎĽ«ÏÈÈÝһЩ³£ÓõÄÒªÁìºÍÕ½ÂÔ£¬²¢ÌṩÏà¹Ø´úÂëʾÀý¡£

Ò»¡¢ÈÕÖ¾ÆÊÎöÒªÁìºÍÕ½ÂÔ

ʹÓÃgrepÏÂÁî

grepÊÇLinuxÖзǾ­³£ÓõÄÏÂÁîÐй¤¾ß£¬ÓÃÓÚËÑË÷Ö¸¶¨µÄ×Ö·û´®¡£ÔÚÈÕÖ¾ÆÊÎöÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃgrepÏÂÁîÀ´²éÕÒÌض¨Òªº¦´Ê£¬ÒÔ±ãɸѡ³öÎÒÃǸÐÐËȤµÄÈÕÖ¾ÐÅÏ¢¡£ÀýÈ磬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´ÕÒ³ö·ºÆð¹ÊÕϵÄÈÕÖ¾£º

grep “error” logfile

ʹÓÃawkÏÂÁî

awkÊÇÒ»ÖÖÇ¿Ê¢µÄÎı¾´¦Àí¹¤¾ß£¬ÔÚÈÕÖ¾ÆÊÎöÖпÉÒÔÓÃÀ´ÌáÈ¡ºÍ¹ýÂËÈÕÖ¾ÐÅÏ¢¡£ÀýÈ磬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´Í³¼ÆÈÕÖ¾Öвî±ðÓû§µÄ»á¼û´ÎÊý£º

awk ‘{print $1}’ logfile | sort | uniq -c

ʹÓÃsedÏÂÁî

sedÊÇÒ»ÖÖÁ÷ʽÎı¾±à¼­Æ÷£¬Ò²¿ÉÒÔÓÃÓÚÈÕÖ¾ÆÊÎö¡£ÀýÈ磬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´É¾³ýÈÕÖ¾ÖеÄʱ¼ä´Á£º

sed ‘s/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}//g’ logfile

ʹÓÃlogrotate¹¤¾ß

logrotateÊÇLinuxÖÐ×Ô´øµÄÈÕÖ¾ÂÖת¹¤¾ß£¬¿ÉÒÔÓÃÓÚÖÎÀíÈÕÖ¾ÎļþµÄ¾ÞϸºÍÊýÄ¿¡£ÎÒÃÇ¿ÉÒÔÉèÖÃlogrotateʹÆä°´ÆÚ¶ÔÈÕÖ¾Îļþ¾ÙÐÐÂÖת£¬´Ó¶ø¼á³ÖÈÕÖ¾ÎļþµÄ¿É¶ÁÐԺͿÉÖÎÀíÐÔ¡£

¶þ¡¢Òì³£¼ì²âÒªÁìºÍÕ½ÂÔ

»ùÓÚ¹æÔòµÄÒì³£¼ì²â

»ùÓÚ¹æÔòµÄÒì³£¼ì²âÊÇÒ»ÖÖ³£¼ûµÄÒªÁ죬ͨ¹ý½ç˵һϵÁйæÔòÀ´¼ì²âÈÕÖ¾ÖеÄÒì³£ÇéÐΡ£ÀýÈ磬ÎÒÃÇ¿ÉÒÔ½ç˵¹æÔò£¬µ±ÈÕÖ¾ÖзºÆðij¸öÒªº¦´Êʱ£¬´¥·¢¾¯±¨¡£¿ÉÒÔʹÓù¤¾ßÈçfail2banÀ´ÊµÏÖ»ùÓÚ¹æÔòµÄÒì³£¼ì²â¡£

»ùÓÚͳ¼ÆµÄÒì³£¼ì²â

»ùÓÚͳ¼ÆµÄÒì³£¼ì²âÊÇʹÓÃͳ¼ÆѧԭÀíÀ´¼ì²âÈÕÖ¾ÖеÄÒì³£ÇéÐΡ£ÀýÈ磬ÎÒÃÇ¿ÉÒÔʹÓÃÅÌËãÈÕÖ¾ÖÐij¸öÊÂÎñµÄƽ¾ùÖµºÍ±ê×¼²î£¬µ±Ä³¸öÊÂÎñµÄÖµÁè¼Ýƽ¾ùÖµ¼ÓÉÏÈý±¶±ê×¼²îʱ£¬¾ÍÅжÏΪÒì³£¡£¿ÉÒÔʹÓù¤¾ßÈçELK£¨Elasticsearch, Logstash, Kibana£©À´¾ÙÐлùÓÚͳ¼ÆµÄÒì³£¼ì²â¡£

»ùÓÚ»úеѧϰµÄÒì³£¼ì²â

»ùÓÚ»úеѧϰµÄÒì³£¼ì²âÊÇʹÓûúеѧϰËã·¨À´ÑµÁ·Ä£×Ó£¬²¢Æ¾Ö¤Ä£×ÓÀ´ÅжÏÈÕÖ¾ÖеÄÒì³£ÇéÐΡ£ÀýÈ磬ÎÒÃÇ¿ÉÒÔʹÓûúеѧϰģ×ÓÀ´Õ¹ÍûÈÕÖ¾ÖпÉÄÜ·ºÆðµÄÒì³£ÊÂÎñ¡£¿ÉÒÔʹÓù¤¾ßÈçTensorFlow¡¢Scikit-learnµÈÀ´¾ÙÐлùÓÚ»úеѧϰµÄÒì³£¼ì²â¡£

´úÂëʾÀý£º

ÒÔÏÂÊÇÒ»¸öʹÓÃgrepÏÂÁîºÍshell¾ç±¾¾ÙÐÐÈÕÖ¾ÆÊÎöµÄ´úÂëʾÀý£º

#!/bin/bash

logfile="access.log"
keyword="error"

grep $keyword $logfile | while read -r line
do
    echo "Found error in line: $line"
done

µÇ¼ºó¸´ÖÆ

ÒÔÉϾ籾»áËÑË÷ÈÕÖ¾ÎļþÖаüÀ¨¹ýʧҪº¦×ÖµÄÐУ¬²¢Êä³öÕÒµ½µÄ¹ýʧÐÅÏ¢¡£

½áÂÛ£º

ÈÕÖ¾ÆÊÎöºÍÒì³£¼ì²âÔÚLinuxϵͳÖкÜÊÇÖ÷Òª£¬Äܹ»×ÊÖúÎÒÃÇʵʱ·¢Ã÷ϵͳ¹ÊÕϺÍÒì³£ÇéÐΡ£±¾ÎÄÏÈÈÝÁËһЩ³£ÓõÄÒªÁìºÍÕ½ÂÔ£¬²¢ÌṩÁËÏà¹ØµÄ´úÂëʾÀý¡£Í¨¹ýºÏÀíʹÓÃÕâЩ¹¤¾ßºÍÒªÁ죬ÎÒÃÇ¿ÉÒÔ¸üºÃµØÆÊÎöºÍ¼ì²âÈÕÖ¾£¬°ü¹ÜϵͳµÄÕý³£ÔËÐС£

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

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ