ÔõÑùͨ¹ýLinuxÏÂÁîÐй¤¾ß¾ÙÐÐϵͳÈÕÖ¾ÆÊÎöºÍ¼à¿Ø£¿
ÔõÑùͨ¹ýlinuxÏÂÁîÐй¤¾ß¾ÙÐÐϵͳÈÕÖ¾ÆÊÎöºÍ¼à¿Ø£¿
ÔÚLinuxϵͳÖУ¬ÏµÍ³ÈÕÖ¾ÊǼͼ²Ù×÷ϵͳºÍÓ¦ÓóÌÐòÔËÐÐʱ±¬·¢µÄÊÂÎñ¡¢¹ýʧºÍÖÒÑÔµÄÖ÷Òª¹¤¾ß¡£¶ÔϵͳÈÕÖ¾¾ÙÐÐÆÊÎöºÍ¼à¿Ø¿ÉÒÔ×ÊÖúÖÎÀíԱʵʱ·¢Ã÷Ï¢Õù¾öÎÊÌ⣬°ü¹ÜϵͳµÄÎȹÌÔËÐС£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃLinuxÏÂÁîÐй¤¾ß¾ÙÐÐϵͳÈÕÖ¾µÄÆÊÎöºÍ¼à¿Ø¡£
Éó²éϵͳÈÕÖ¾Îļþ
ÔÚLinuxϵͳÖУ¬ÏµÍ³ÈÕÖ¾ÎļþÖ÷Òª´æ´¢ÔÚ/var/logĿ¼Ï¡£³£¼ûµÄϵͳÈÕÖ¾Îļþ°üÀ¨£º
/var/log/messages£ºÏµÍ³½¹µã¡¢¸÷ЧÀÍÒÔ¼°¸÷Ó¦ÓóÌÐò±¬·¢µÄÈÕÖ¾ÊÂÎñ¡£
/var/log/syslog£º°üÀ¨ÁËÓÉϵͳ¼°¸÷ЧÀÍËù±¬·¢µÄ´ó´ó¶¼ÈÕÖ¾ÊÂÎñ¡£
/var/log/auth.log£º¼Í¼ÁËϵͳÈÏÖ¤Àú³ÌÖб¬·¢µÄÈÕÖ¾ÊÂÎñ¡£
/var/log/kern.log£º¼Í¼ÁËÄÚºËÊÂÎñµÄÈÕÖ¾Îļþ¡£
/var/log/dmesg£ºÊÇÄں˻·»º³åÇøµÄÒ»¸ö¾µÏñ£¬ÆäÖÐÉúÑÄÁËÆô¶¯Àú³ÌÖеÄÄÚºËÊä³ö¡£
¿ÉÒÔʹÓÃÏÂÁîÐй¤¾ßÈçcat¡¢less¡¢tailµÈÉó²éÕâЩÈÕÖ¾ÎļþµÄÄÚÈÝ¡£ÀýÈ磬ʹÓÃtail -f /var/log/messagesÏÂÁî¿ÉÒÔ¶¯Ì¬µØÉó²éϵͳ½¹µãºÍ¸÷ЧÀ͵ÄÈÕÖ¾ÊÂÎñ¡£
ʹÓÃgrep¾ÙÐÐÈÕÖ¾¹ýÂË
µ±ÈÕÖ¾Îļþ½ÏÁ¿´ó»ò°üÀ¨´ó×ÚÐÅϢʱ£¬¿ÉÒÔʹÓÃgrepÏÂÁî¾ÙÐйýÂË¡£È磬ͨ¹ýgrep “error” /var/log/messagesÏÂÁî¿ÉÒÔÖ»ÏÔʾ°üÀ¨”error”Òªº¦×ÖµÄÈÕÖ¾ÊÂÎñ¡£¶øgrep -i “error” /var/log/messagesÏÂÁîÔò»áºöÂÔÒªº¦×ֵľÞϸд¡£
ʹÓÃawk¾ÙÐÐÈÕÖ¾ÆÊÎö
awkÊÇÒ»ÖÖÇ¿Ê¢µÄÎı¾´¦Àí¹¤¾ß£¬¿ÉÒÔͨ¹ýËü¾ÙÐÐÈÕÖ¾ÆÊÎö¡£ÀýÈ磬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîͳ¼Æÿ¸öЧÀÍÔÚÈÕÖ¾ÎļþÖзºÆðµÄ´ÎÊý£º
awk '{print $5}' /var/log/messages | sort | uniq -c
µÇ¼ºó¸´ÖÆ
¸ÃÏÂÁî»á´Ó/var/log/messagesÖÐÌáȡÿһÐеĵÚÎå¸öµ¥´Ê£¬²¢Í¨¹ýsortºÍuniqÏÂÁî¾ÙÐÐͳ¼ÆºÍÈ¥ÖØ¡£
ʹÓÃjournalctl¾ÙÐÐÈÕÖ¾¼à¿Ø
journalctlÊÇÒ»¸öÓÃÓÚ²Ù×÷ϵͳÈÕÖ¾µÄ¹¤¾ß£¬¿ÉÒÔÈÃÄã¿ìËÙ¼ìË÷ºÍ¼à¿ØϵͳÈÕÖ¾¡£ËüÊÇsystemdÈÕÖ¾µÄÏÂÁîÐнçÃæ¡£ÒÔÏÂÊÇһЩjournalctlÏÂÁîµÄʾÀý£º
journalctl –since “2021-01-01″£ºÏÔʾ´ÓÖ¸¶¨ÈÕÆÚÒÔÀ´µÄËùÓÐÈÕÖ¾ÊÂÎñ¡£
journalctl -u sshd.service£ºÏÔʾsshdЧÀ͵ÄÈÕÖ¾ÊÂÎñ¡£
journalctl -f£º¶¯Ì¬ÏÔʾ×îеÄÈÕÖ¾ÊÂÎñ¡£
ʹÓÃlogwatch¾ÙÐÐϵͳÈÕÖ¾±¨¸æ
logwatchÊÇÒ»¸öÈÕÖ¾ÆÊÎöÓ뱨¸æϵͳ£¬¿ÉÒÔͨ¹ýÓʼþµÈ·½·¨ÏòÖÎÀíÔ±·¢ËÍϵͳÈÕÖ¾µÄ±¨¸æ¡£¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁî×°ÖÃlogwatch:
sudo apt-get install logwatch
µÇ¼ºó¸´ÖÆ
×°ÖÃÍê³Éºó£¬¿ÉÒÔͨ¹ý±à¼/etc/cron.daily/00logwatchÎļþÀ´ÉèÖÃÌìÉúÈÕÖ¾±¨¸æµÄƵÂʺͷ½·¨¡£Ä¬ÈÏÇéÐÎÏ£¬logwatch»á½«ÈÕÖ¾±¨¸æ·¢Ë͵½rootÓû§µÄÓʼþ¡£
ͨ¹ýÉÏÊöÒªÁ죬ÎÒÃÇ¿ÉÒÔͨ¹ýLinuxÏÂÁîÐй¤¾ß¾ÙÐÐϵͳÈÕÖ¾µÄÆÊÎöºÍ¼à¿Ø£¬ÊµÊ±·¢Ã÷Ï¢Õù¾öÎÊÌ⣬°ü¹ÜϵͳµÄÎȹÌÔËÐС£Ï£Íû±¾ÎÄÄܶÔÄãÓÐËù×ÊÖú¡£
ÒÔÉϾÍÊÇÔõÑùͨ¹ýLinuxÏÂÁîÐй¤¾ß¾ÙÐÐϵͳÈÕÖ¾ÆÊÎöºÍ¼à¿Ø£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡