ÔõÑù¾ÙÐÐLinuxϵͳµÄÈÕÖ¾ÆÊÎöºÍ¹ÊÕÏÕï¶Ï
ÔõÑù¾ÙÐÐLinuxϵͳµÄÈÕÖ¾ÆÊÎöºÍ¹ÊÕÏÕï¶Ï£¬ÐèÒªÏêϸ´úÂëʾÀý
ÔÚLinuxϵͳÖУ¬ÈÕÖ¾ÊǺÜÊÇÖ÷ÒªµÄ£¬Ëü¼Í¼ÁËϵͳµÄÔËÐÐ״̬ºÍÖÖÖÖÊÂÎñµÄ±¬·¢¡£Í¨Ì«¹ýÎöºÍÕï¶ÏϵͳÈÕÖ¾£¬¿ÉÒÔ×ÊÖúÎÒÃÇÕÒµ½ÏµÍ³¹ÊÕϵÄÔµ¹ÊÔÓÉ£¬²¢ÊµÊ±½â¾öÎÊÌâ¡£±¾ÎĽ«ÏÈÈÝһЩ³£ÓõÄLinuxÈÕÖ¾ÆÊÎöºÍ¹ÊÕÏÕï¶ÏµÄÒªÁ죬²¢¸ø³öÏìÓ¦µÄ´úÂëʾÀý¡£
ÈÕÖ¾ÎļþµÄλÖúÍÃûÌÃ
ÔÚLinuxϵͳÖУ¬ÈÕÖ¾ÎļþÒ»Ñùƽ³£´æ·ÅÔÚ/var/logĿ¼Ï£¬³£¼ûµÄÈÕÖ¾Îļþ°üÀ¨£º
/var/log/messages£º¼Í¼ϵͳµÄÒ»Ñùƽ³£ÐÔÐÂÎÅ¡£
/var/log/auth.log£º¼Í¼ϵͳµÄÈÏÖ¤ÈÕÖ¾¡£
/var/log/syslog£º¼Í¼ϵͳµÄ´ó×ÚÐÅÏ¢¡£
/var/log/secure£º¼Í¼ϵͳµÄÇå¾²Ïà¹ØÐÅÏ¢¡£
/var/log/boot.log£º¼Í¼ϵͳµÄÆô¶¯ÈÕÖ¾¡£
ÕâЩÈÕÖ¾ÎļþµÄÃûÌÃÒ»Ñùƽ³£ÊÇÎı¾ÃûÌ㬿ÉÒÔʹÓÃÎı¾±à¼Æ÷Ö±½ÓÉó²éºÍÆÊÎö¡£
ʹÓÃgrepÏÂÁî¹ýÂËÈÕÖ¾
grepÏÂÁîÊÇÒ»¸öºÜÊÇÇ¿Ê¢µÄÎı¾ËÑË÷¹¤¾ß£¬¿ÉÒÔƾָ֤¶¨µÄģʽËÑË÷Îı¾ÎļþÖеÄÄÚÈÝ¡£ÎÒÃÇ¿ÉÒÔʹÓÃgrepÏÂÁî¹ýÂËÈÕÖ¾Îļþ£¬ÒÔ±ãÕÒ³öÌض¨µÄÐÅÏ¢¡£
ÀýÈ磬Ҫ²éÕÒ°üÀ¨Òªº¦×Ö”error”µÄÈÕÖ¾¼Í¼£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ
grep "error" /var/log/messages
µÇ¼ºó¸´ÖÆ
Õ⽫Êä³öËùÓаüÀ¨Òªº¦×Ö”error”µÄÈÕÖ¾¼Í¼¡£
ʹÓÃsedÏÂÁî±à¼ÈÕÖ¾
sedÏÂÁîÊÇÒ»¸öÇ¿Ê¢µÄÎı¾±à¼¹¤¾ß£¬¿ÉÒÔ¶ÔÎı¾Îļþ¾ÙÐÐÖݪֲÙ×÷¡£ÎÒÃÇ¿ÉÒÔʹÓÃsedÏÂÁî±à¼ÈÕÖ¾Îļþ£¬ÒԱ㽫ÆäÃûÌû¯»òÌáÈ¡³öÌض¨µÄÐÅÏ¢¡£
ÀýÈ磬ҪÌáÈ¡³ö°üÀ¨Òªº¦×Ö”error”µÄÈÕÖ¾¼Í¼£¬²¢½«ÆäÉúÑĵ½Ò»¸öÐÂÎļþÖУ¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ
sed -n '/error/ p' /var/log/messages > error.log
µÇ¼ºó¸´ÖÆ
Õ⽫½«º¬ÓÐÒªº¦×Ö”error”µÄÈÕÖ¾¼Í¼ÉúÑĵ½error.logÎļþÖС£
ʹÓÃawkÏÂÁîÆÊÎöÈÕÖ¾
awkÏÂÁîÊÇÒ»¸ö¹¦Ð§Ç¿Ê¢µÄÎı¾´¦Àí¹¤¾ß£¬¿ÉÒÔƾָ֤¶¨µÄÌõ¼þºÍ¹æÔò¶ÔÎı¾¾ÙÐÐÆÊÎöºÍ´¦Àí¡£ÎÒÃÇ¿ÉÒÔʹÓÃawkÏÂÁî¶ÔÈÕÖ¾Îļþ¾ÙÐÐÆÊÎö£¬ÒÔ±ã´ÓÖÐÌáÈ¡³öÓÐÓõÄÐÅÏ¢¡£
ÀýÈ磬Ҫ²éÕÒÈÕÖ¾ÎļþÖзºÆðƵÂÊ×î¸ßµÄÒªº¦×Ö£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ
awk '{for(i=1; i<=NF; i++) count[$i]++} END{for(word in count) print count[word], word}' /var/log/messages | sort -rn | head -n 10
µÇ¼ºó¸´ÖÆ
Õ⽫Êä³ö·ºÆðƵÂÊ×î¸ßµÄÇ°10¸öÒªº¦×Ö¼°Æä·ºÆð´ÎÊý¡£
ʹÓÃlogwatch¹¤¾ß×Ô¶¯ÌìÉúÈÕÖ¾±¨¸æ
logwatchÊÇÒ»¸öÓÃÓÚÌìÉúϵͳÈÕÖ¾±¨¸æµÄ¹¤¾ß£¬Ëü¿ÉÒÔ×Ô¶¯ÆÊÎöϵͳÈÕÖ¾£¬²¢ÌìÉúÏìÓ¦µÄ±¨¸æ¡£
ҪװÖÃlogwatch¹¤¾ß£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁ
sudo apt-get install logwatch
µÇ¼ºó¸´ÖÆ
×°ÖÃÍê³Éºó£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÌìÉúϵͳÈÕÖ¾±¨¸æ£º
sudo logwatch
µÇ¼ºó¸´ÖÆ
±¨¸æ½«»áÏÔʾÔÚÖÕ¶ËÉÏ¡£
ÒÔÉÏÊÇһЩ³£ÓõÄLinuxÈÕÖ¾ÆÊÎöºÍ¹ÊÕÏÕï¶ÏµÄÒªÁìºÍ´úÂëʾÀý¡£Í¨Ì«¹ýÎöºÍÕï¶ÏϵͳÈÕÖ¾£¬ÎÒÃÇ¿ÉÒÔʵʱ·¢Ã÷ϵͳ¹ÊÕÏ£¬²¢½ÓÄÉÏìÓ¦µÄ²½·¥½â¾öÎÊÌ⡣ϣÍû±¾ÎÄÄܶԶÁÕßÔÚLinuxϵͳÈÕÖ¾ÆÊÎöºÍ¹ÊÕÏÕï¶Ï·½ÃæÌṩһЩ×ÊÖú¡£
ÒÔÉϾÍÊÇÔõÑù¾ÙÐÐLinuxϵͳµÄÈÕÖ¾ÆÊÎöºÍ¹ÊÕÏÕï¶ÏµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡