×ðÁú¿­Ê±

LinuxÇéÐÎϵÄWebÈÕÖ¾ÆÊÎöÒªÁìºÍ¼¼ÇÉ

linuxÇéÐÎϵÄwebÈÕÖ¾ÆÊÎöÒªÁìºÍ¼¼ÇÉ

Ëæ×ÅWebÓ¦ÓóÌÐòµÄÆÕ¼°ºÍ»¥ÁªÍøµÄÉú³¤ £¬WebÈÕÖ¾ÆÊÎö±äµÃÔ½À´Ô½Ö÷Òª¡£Í¨Ì«¹ýÎöWebÈÕÖ¾ £¬ÎÒÃÇ¿ÉÒÔÏàʶÓû§µÄ»á¼ûÐÐΪ¡¢ÓÅ»¯ÍøÕ¾ÐÔÄÜ¡¢·¢Ã÷DZÔÚÎÊÌâµÈ¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃLinuxÇéÐÎÏµĹ¤¾ßºÍ¼¼ÇɾÙÐÐWebÈÕÖ¾ÆÊÎö £¬²¢ÌṩһЩ´úÂëʾÀýÀ´×ÊÖú¶ÁÕ߸üºÃµØÃ÷È·¡£

Ê×ÏÈ £¬ÎÒÃÇÐèÒªÍøÂçWebЧÀÍÆ÷µÄ»á¼ûÈÕÖ¾¡£³£¼ûµÄWebЧÀÍÆ÷ÈçApache¡¢Nginx¶¼»áÌìÉú»á¼ûÈÕÖ¾Îļþ¡£ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁîÕÒµ½ÈÕÖ¾ÎļþµÄ·¾¶£º

# Apache»á¼ûÈÕ־·¾¶
/var/log/apache2/access.log

# Nginx»á¼ûÈÕ־·¾¶
/var/log/nginx/access.log

µÇ¼ºó¸´ÖÆ

ÏÂÃæ £¬ÎÒÃÇÏÈÈݼ¸ÖÖ³£¼ûµÄWebÈÕÖ¾ÆÊÎöÒªÁìºÍ¼¼ÇÉ¡£

ͳ¼Æ»á¼ûÁ¿ºÍ»á¼ûIPÊý

ÎÒÃÇ¿ÉÒÔʹÓÃwcÏÂÁîͳ¼ÆÈÕÖ¾ÎļþµÄÐÐÊý £¬¼´»á¼ûÁ¿£º

$ wc -l /var/log/apache2/access.log
1000 /var/log/apache2/access.log

µÇ¼ºó¸´ÖÆ

Ҫͳ¼Æ»á¼ûµÄΨһIPÊý £¬ÎÒÃÇ¿ÉÒÔʹÓÃawkÏÂÁ

$ awk '{print $1}' /var/log/apache2/access.log | sort | uniq | wc -l
100 /var/log/apache2/access.log

µÇ¼ºó¸´ÖÆ

ÆÊÎö»á¼ûȪԴ

ÎÒÃÇ¿ÉÒÔʹÓÃawkÏÂÁîÌáÈ¡»á¼ûÈÕÖ¾ÖеÄURL×ֶΠ£¬²¢Ê¹ÓÃsortÏÂÁîͳ¼ÆÅÅÃû£º

$ awk '{print $7}' /var/log/apache2/access.log | sort | uniq -c | sort -rn | head -n 10
500 /home
400 /products
300 /about
...

µÇ¼ºó¸´ÖÆ

ÕâÑùÎÒÃǾͿÉÒÔÖªµÀÄÄЩҳÃæÊÇÓû§×î³£»á¼ûµÄ¡£

ÆÊÎö»á¼ûʱ¼äºÍÏìӦʱ¼ä

̫ͨ¹ýÎö»á¼ûʱ¼äºÍÏìӦʱ¼ä £¬ÎÒÃÇ¿ÉÒÔÏàʶÓû§»á¼ûÍøÕ¾µÄá¯Áëʱ¶ÎºÍÍøÕ¾ÐÔÄÜ¡£ÎÒÃÇ¿ÉÒÔʹÓÃawkÏÂÁîÌáÈ¡»á¼ûʱ¼ä×ֶΠ£¬²¢Ê¹ÓÃsortÏÂÁî¼Í¼ʱ¼ä˳Ðò£º

$ awk '{print $4}' /var/log/apache2/access.log | cut -c 14-18 | sort | uniq -c
100 00:00
200 01:00
...

µÇ¼ºó¸´ÖÆ

ʹÓÃawkÏÂÁîÌáÈ¡ÏìӦʱ¼ä×ֶΠ£¬²¢Æ¾Ö¤ÐèÒª¾ÙÐÐÅÅÐòºÍͳ¼Æ¡£

ÆÊÎö»á¼û¹ýʧ

ÎÒÃÇ¿ÉÒÔʹÓÃgrepÏÂÁî²éÕÒ°üÀ¨¹ýʧ״̬ÂëµÄÐÐ £¬²¢Í³¼ÆÆä·ºÆð´ÎÊý£º

$ grep -E " 4[0-9]{2} " /var/log/apache2/access.log | wc -l
50

µÇ¼ºó¸´ÖÆ

ÕâÑùÎÒÃǾͿÉÒÔÏàʶÍøÕ¾µÄ¹ýʧҳÃæºÍ¹ýʧƵÂÊ¡£

ÒÔÉÏÖ»ÊÇWebÈÕÖ¾ÆÊÎöµÄһЩ»ù±¾ÒªÁìºÍ¼¼ÇÉ £¬ÏÖÕæÏàÐÎÏ¿ÉÄÜÐèҪƾ֤ÏêϸÐèÇó¾ÙÐиüÖØ´óµÄÆÊÎö¡£±ðµÄ £¬ÉÐÓÐһЩǿʢµÄÈÕÖ¾ÆÊÎö¹¤¾ßÈçELK¡¢AWStats¡¢GoAccessµÈ¿É¹©Ñ¡Ôñ¡£

×ܽáÆðÀ´ £¬LinuxÇéÐÎϵÄWebÈÕÖ¾ÆÊÎöÌṩÁ˸»ºñµÄ¹¤¾ßºÍ¼¼ÇÉ £¬¿ÉÒÔ×ÊÖúÎÒÃÇÏàʶÓû§ÐÐΪ¡¢ÓÅ»¯ÍøÕ¾ÐÔÄܵÈ¡£Ï£ÍûÕâƪÎÄÕÂÄܶԶÁÕßÔÚWebÈÕÖ¾ÆÊÎö·½ÃæÓÐËùÆô·¢¡£

²Î¿¼×ÊÁÏ£º

[https://www.digitalocean.com/community/tutorials](https://www.digitalocean.com/community/tutorials)

ÒÔÉϾÍÊÇLinuxÇéÐÎϵÄWebÈÕÖ¾ÆÊÎöÒªÁìºÍ¼¼ÇɵÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

13452372176

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

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

QR code
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿