¼¼ÇÉ£ºÓÐÓýâ¶ÁºÍÖÎÀíLinuxÈÕÖ¾Îļþ
ÎÊÌ⣺ÉîÈë̽ÌÖLinuxÈÕÖ¾Îļþ½â¶ÁÓëÖÎÀí¼¼ÇÉ
ÔÚLinuxϵͳÖУ¬ÈÕÖ¾ÎļþÊǺÜÊÇÖ÷ÒªµÄ×é³É²¿·Ö£¬Ëü¼Í¼ÁËϵͳºÍÓ¦ÓóÌÐòµÄÔËÐÐ״̬¡¢¹ýʧÐÅÏ¢ÒÔ¼°ÆäËûÒªº¦ÐÅÏ¢¡£×¼È·½â¶ÁºÍÖÎÀíÈÕÖ¾Îļþ¿ÉÒÔ×ÊÖúÎÒÃÇʵʱ·¢Ã÷Ï¢Õù¾öÎÊÌ⣬Ìá¸ßϵͳµÄÎȹÌÐÔºÍÇå¾²ÐÔ¡£±¾ÎĽ«ÏÈÈÝLinuxÈÕÖ¾ÎļþµÄ»ù±¾¿´·¨£¬ÒÔ¼°ÔõÑùʹÓó£¼ûµÄÏÂÁîºÍ¹¤¾ßÀ´½â¶ÁºÍÖÎÀíÈÕÖ¾Îļþ¡£
1. ÈÕÖ¾ÎļþµÄÀàÐͺÍλÖÃ
ÔÚLinuxϵͳÖУ¬ÈÕÖ¾Îļþͨ³£·ÖΪϵͳÈÕÖ¾ºÍÓ¦ÓóÌÐòÈÕÖ¾Á½ÖÖÀàÐÍ¡£ÏµÍ³ÈÕÖ¾ÎļþÒ»Ñùƽ³£´æ´¢ÔÚ/var/log/Ŀ¼Ï£¬°üÀ¨/var/log/messages¡¢/var/log/syslog¡¢/var/log/auth.logµÈÎļþ¡£Ó¦ÓóÌÐòÈÕÖ¾ÎļþÔòƾ֤ÏêϸӦÓóÌÐòµÄÐèÒª´æ·ÅÔÚ²î±ðµÄλÖ㬺ñÈApacheµÄÈÕÖ¾Ò»Ñùƽ³£´æ·ÅÔÚ/var/log/apache2/Ŀ¼Ï¡£
2. Éó²éÈÕÖ¾ÎļþÄÚÈÝ
ÔÚLinuxϵͳÖУ¬¿ÉÒÔʹÓÃcat¡¢less¡¢tailµÈÏÂÁîÀ´Éó²éÈÕÖ¾ÎļþµÄÄÚÈÝ¡£ÆäÖУ¬tailÏÂÁî¿ÉÒÔÓÃÀ´Éó²éÈÕÖ¾ÎļþµÄ×îÐÂÄÚÈÝ£¬ºÜÊÇÊʺÏʵʱ¼à¿ØÈÕÖ¾ÎļþµÄת±ä¡£
ÀýÈ磬Éó²é/var/log/messagesÎļþµÄ×îºó10ÐÐÄÚÈÝ£º
tail -n 10 /var/log/messages
µÇ¼ºó¸´ÖÆ
3. ʹÓÃgrepɸѡÈÕÖ¾ÐÅÏ¢
grepÏÂÁî¿ÉÒÔ×ÊÖúÎÒÃÇɸѡÈÕÖ¾ÎļþÖÐÇкÏÌõ¼þµÄÐÅÏ¢£¬ÒÔ±ã¸ü¿ìµØ¶¨Î»ÎÊÌâ¡£ºÃ±È£¬²éÕÒ°üÀ¨Òªº¦´Ê”error”µÄÐУº
cat /var/log/messages | grep "error"
µÇ¼ºó¸´ÖÆ
4. ÈÕÖ¾ÎļþÂÖת
ΪÁË×èÖ¹ÈÕÖ¾Îļþ¹ý´óÕ¼Óùý¶à´ÅÅ̿ռ䣬ͨ³£»á¶ÔÈÕÖ¾Îļþ¾ÙÐÐÂÖת¡£LinuxϵͳÖг£ÓõÄÈÕÖ¾ÂÖת¹¤¾ßÊÇlogrotate£¬Ëü¿ÉÒÔƾ֤ԤÉèµÄ¹æÔò¶ÔÈÕÖ¾Îļþ¾ÙÐа´ÆÚÂÖתºÍѹËõ¡£
5. ʵʱ¼à¿ØÈÕÖ¾Îļþ
ÓÐʱ¼äÎÒÃÇÐèҪʵʱ¼à¿ØÈÕÖ¾ÎļþµÄת±ä£¬¿ÉÒÔʹÓÃtail -fÏÂÁîʵÏÖÕâ¸ö¹¦Ð§¡£ÕâÑù¿ÉÒÔÒ»Ö±µØÏÔʾÈÕÖ¾ÎļþµÄ×îÐÂÄÚÈÝ£¬Àû±ãÎÒÃÇʵʱ·¢Ã÷ÎÊÌâ¡£
tail -f /var/log/messages
µÇ¼ºó¸´ÖÆ
6. ÆÊÎöÈÕÖ¾ÎļþµÄÄÚÈÝ
³ýÁËÖ±½ÓÉó²éÈÕÖ¾ÎļþµÄÄÚÈÝ£¬ÎÒÃÇ»¹¿ÉÒÔ½èÖú¹¤¾ßÈçawk¡¢sedµÈ¶ÔÈÕÖ¾Îļþ¾ÙÐнøÒ»²½ÆÊÎöºÍ´¦Àí¡£ÕâЩ¹¤¾ß¿ÉÒÔ×ÊÖúÎÒÃÇÌáÈ¡Ìض¨×ֶΡ¢ÅÌËãͳ¼ÆÐÅÏ¢µÈ£¬¼ÓËÙÎÊÌⶨλµÄËÙÂÊ¡£
½áÓï
ͨ¹ý±¾ÎĵÄÏÈÈÝ£¬ÐÅÍжÁÕ߶ÔLinuxÈÕÖ¾ÎļþµÄ½â¶ÁºÍÖÎÀíÓÐÁ˸üÉîÈëµÄÏàʶ¡£ÔÚÏÖʵÊÂÇéÖУ¬ÎÞаÔËÓÃÕâЩ¼¼Çɽ«»á×ÊÖúÎÒÃǸü¸ßЧµØÅÅÅÌÎÊÌâ¡¢Ìá¸ßϵͳµÄÎȹÌÐÔºÍÇå¾²ÐÔ¡£Ï£Íû±¾ÎÄÄܶԶÁÕßÓÐËù×ÊÖú£¬Ò²½Ó´ý¸÷ÈË·ÖÏí×Ô¼ºÔÚÈÕÖ¾ÎļþÖÎÀí·½ÃæµÄÂÄÀúºÍ¼¼ÇÉ¡£
ÒÔÉϾÍÊǼ¼ÇÉ£ºÓÐÓýâ¶ÁºÍÖÎÀíLinuxÈÕÖ¾ÎļþµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡