ÔõÑùʹÓÃLinux¾ÙÐÐÈÕÖ¾ÆÊÎö£¿
ÔõÑùʹÓÃlinux¾ÙÐÐÈÕÖ¾ÆÊÎö£¿
ÔÚÅÌËã»úϵͳÔËÐÐÀú³ÌÖУ¬±¬·¢´ó×ÚµÄÈÕÖ¾Êý¾Ý¡£Í¨¹ý¶ÔÈÕÖ¾¾ÙÐÐÆÊÎö£¬¿ÉÒÔ¸üºÃµØÏàʶϵͳµÄÔËÐÐ״̬ºÍÎÊÌâËùÔÚ¡£¶øLinux×÷Ϊһ¸öÇ¿Ê¢µÄ²Ù×÷ϵͳ£¬ÌṩÁ˸»ºñµÄ¹¤¾ßºÍÏÂÁ¿ÉÒÔ×ÊÖúÎÒÃǾÙÐÐÈÕÖ¾ÆÊÎö¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃLinux¾ÙÐÐÈÕÖ¾ÆÊÎö£¬²¢ÌṩһЩ³£ÓõĴúÂëʾÀý¡£
Ò»¡¢Éó²éÈÕÖ¾Îļþ
Ê×ÏÈ£¬ÎÒÃÇÒªÏàʶϵͳµÄÈÕÖ¾Îļþ´æ·ÅÔÚÄÇÀï¡£ÔÚLinuxϵͳÖУ¬Ò»Ñùƽ³£½«ÏµÍ³ÈÕÖ¾´æ·ÅÔÚ/var/logĿ¼Ï£¬²î±ðµÄ¿¯Ðаæ¿ÉÄÜ»áÓÐËù²î±ð¡£
ʹÓÃlsÏÂÁîÉó²é/var/logĿ¼ÏµÄÎļþ£º
ls /var/log
µÇ¼ºó¸´ÖÆ
¿ÉÒÔ¿´µ½Ò»Ð©³£¼ûµÄÈÕÖ¾Îļþ£¬ºÃ±Èsyslog¡¢auth.logµÈ¡£ÎÒÃÇ¿ÉÒÔʹÓÃcatÏÂÁî»òlessÏÂÁîÉó²éÈÕÖ¾ÎļþµÄÄÚÈÝ£¬ÀýÈçÉó²ésyslogÎļþ£º
cat /var/log/syslog
µÇ¼ºó¸´ÖÆ
¶þ¡¢ËÑË÷Òªº¦×Ö
µ±ÈÕÖ¾Îļþ½ÏÁ¿´óʱ£¬ÎÒÃÇ¿ÉÒÔʹÓÃgrepÏÂÁîÀ´ËÑË÷Òªº¦×Ö£¬´Ó¶ø¿ìËÙ¶¨Î»ÎÒÃÇÌåÌùµÄÈÕÖ¾ÐÅÏ¢¡£
ÀýÈ磬ÔÚsyslogÎļþÖÐËÑË÷Òªº¦×Ö”error”£º
grep "error" /var/log/syslog
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
ÕâÑù¿ÉÒÔÕÒµ½ËùÓаüÀ¨”error”Òªº¦×ÖµÄÈÕÖ¾ÐС£
Èý¡¢¹ýÂËÈÕÖ¾ÐÅÏ¢
ÓÐʱ¼ä£¬ÎÒÃÇÖ»ÌåÌùij¸öÌض¨µÄÈÕÖ¾ÀàÐÍ»òÕßij¸öʱ¼ä¶ÎÄÚµÄÈÕÖ¾ÐÅÏ¢¡£Õâʱ¼ä£¬¿ÉÒÔʹÓÃһЩÏÂÁîÀ´¹ýÂËÈÕÖ¾ÐÅÏ¢¡£
¹ýÂËÌض¨ÈÕÖ¾¼¶±ðµÄÐÅÏ¢
syslogÎļþÖаüÀ¨Á˲î±ðµÄÈÕÖ¾¼¶±ð£¬Èçdebug¡¢info¡¢warning¡¢errorµÈ¡£ÎÒÃÇ¿ÉÒÔʹÓÃgrepÏÂÁîÀ´¹ýÂ˳öÌض¨µÄÈÕÖ¾¼¶±ð¡£
ÀýÈ磬¹ýÂ˳öËùÓеĹýʧÈÕÖ¾£º
grep "error" /var/log/syslog
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
¹ýÂËÌØ׼ʱ¼ä¶ÎµÄÈÕÖ¾ÐÅÏ¢
ÓÐʱ¼ä£¬ÎÒÃÇÖ»ÌåÌùij¸öʱ¼ä¶ÎÄÚµÄÈÕÖ¾ÐÅÏ¢¡£ÎÒÃÇ¿ÉÒÔʹÓÃgrepÏÂÁîÍŽáÕýÔò±í´ïʽÀ´¹ýÂËÈÕÖ¾Îļþ¡£
ÀýÈ磬¹ýÂ˳öÌØ׼ʱ¼ä¶Î£¨2021Äê1ÔÂ1ÈÕµ½2021Äê1ÔÂ31ÈÕ£©ÄÚµÄÈÕÖ¾ÐÅÏ¢£º
grep "2021-01-[01-31]" /var/log/syslog
µÇ¼ºó¸´ÖÆ
ËÄ¡¢Í³¼ÆÈÕÖ¾ÐÅÏ¢
ÓÐʱ¼ä£¬ÎÒÃÇÐèҪͳ¼Æij¸öʱ¼ä¶ÎÄÚµÄÈÕÖ¾ÐÅÏ¢£¬ºÃ±Èij¸ö¹ýʧÔÚÒ»¶Îʱ¼äÄÚ·ºÆðÁ˼¸¶à´Î¡£
ÎÒÃÇ¿ÉÒÔʹÓÃgrepÍŽáwcÏÂÁîÀ´¾ÙÐÐͳ¼Æ¡£ÀýÈ磬ͳ¼Æij¸ö¹ýʧÔÚsyslogÎļþÖзºÆðµÄ´ÎÊý£º
grep "error" /var/log/syslog | wc -l
µÇ¼ºó¸´ÖÆ
ÕâÑù¿ÉÒÔ»ñµÃ¹ýʧ·ºÆðµÄ´ÎÊý¡£
Îå¡¢ÈÕÖ¾ÆÊÎö¹¤¾ß
³ýÁËʹÓÃLinuxÏÂÁÎÒÃÇ»¹¿ÉÒÔʹÓÃһЩÈÕÖ¾ÆÊÎö¹¤¾ßÀ´¸üÀû±ãµØ¾ÙÐÐÈÕÖ¾ÆÊÎö¡£
awkÏÂÁî
awkÊÇÒ»ÖÖÇ¿Ê¢µÄÎı¾´¦Àí¹¤¾ß£¬¿ÉÒÔÓÃÀ´¶ÔÈÕÖ¾Îļþ¾ÙÐÐÆÊÎöºÍÆÊÎö¡£
ÀýÈ磬ÎÒÃÇҪͳ¼Æÿ¸öСʱÄÚ¹ýʧ·ºÆðµÄ´ÎÊý£¬¿ÉÒÔʹÓÃÈçÏÂÏÂÁ
awk '{print $4}' /var/log/syslog | awk -F: '{print $1}' | sort | uniq -c
µÇ¼ºó¸´ÖÆ
ÕâÑù¿ÉÒÔÊä³öÿ¸öСʱ¹ýʧ·ºÆðµÄ´ÎÊý¡£
sedÏÂÁî
sedÊÇÒ»ÖÖÁ÷±à¼Æ÷£¬¿ÉÒÔÓÃÀ´´¦ÀíºÍת»»Îı¾¡£
ÀýÈ磬ÎÒÃÇÒªÌæ»»syslogÎļþÖеÄij¸ö×Ö·û£¬¿ÉÒÔʹÓÃÈçÏÂÏÂÁ
sed 's/error/ERROR/g' /var/log/syslog
µÇ¼ºó¸´ÖÆ
½«ËùÓеĔerror”Ì滻Ϊ”ERROR”¡£
logrotate¹¤¾ß
logrotateÊÇÒ»¸öÈÕÖ¾ÎļþÖÎÀí¹¤¾ß£¬¿ÉÒÔ×ÊÖúÎÒÃÇ°´ÆÚ¾ÙÐÐÈÕÖ¾ÎļþµÄÂÖתºÍѹËõ¡£
ÀýÈ磬ÎÒÃÇ¿ÉÒÔÔÚlogrotateÉèÖÃÎļþÖÐÖ¸¶¨ÐèÒªÂÖתµÄÈÕÖ¾Îļþ¡¢ÂÖתµÄƵÂʺÍÉúÑĵÄÀúÊ·ÈÕÖ¾ÎļþÊýÄ¿¡£
×ܽá
ʹÓÃLinux¾ÙÐÐÈÕÖ¾ÆÊÎöÊǺÜÊÇÓÐÓõÄÊÖÒÕ£¬ÔÚ¹ÊÕÏÅŲéºÍÐÔÄÜÓÅ»¯ÖÐÊ©Õ¹×ÅÖ÷Òª×÷Óᣱ¾ÎÄÏÈÈÝÁ˳£ÓõÄÈÕÖ¾ÆÊÎöÒªÁìºÍ¹¤¾ß£¬Ï£ÍûÄܹ»×ÊÖú¶ÁÕ߸üºÃµØ¾ÙÐÐÈÕÖ¾ÆÊÎöÊÂÇé¡£ËäÈ»£¬ÕÆÎÕÕâЩÊÖÒÕÐèҪ͎áÏÖʵµÄÊÂÇéÂÄÀúºÍÒ»Ö±µÄʵ¼ù£¬Ò»Ö±×ܽáºÍѧϰ£¬²Å»ªÕæÕý³ÉΪһÃûÓÅÒìµÄϵͳÖÎÀíÔ±»ò¿ª·¢Ö°Ô±¡£
ÒÔÉϾÍÊÇÔõÑùʹÓÃLinux¾ÙÐÐÈÕÖ¾ÆÊÎö£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡