{"id":1565,"date":"2020-07-06T11:14:23","date_gmt":"2020-07-06T03:14:23","guid":{"rendered":"https:\/\/www.strongd.net\/?p=1565"},"modified":"2020-07-06T11:14:23","modified_gmt":"2020-07-06T03:14:23","slug":"%e5%bf%ab%e9%80%9f%e5%88%86%e6%9e%90-apache-%e7%9a%84-access-log%ef%bc%8c%e6%8a%93%e5%87%ba%e5%89%8d%e5%8d%81%e5%a4%a7%e7%b6%b2%e7%ab%99%e6%b5%81%e9%87%8f%e5%85%87%e6%89%8b","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=1565","title":{"rendered":"\u5feb\u901f\u5206\u6790 Apache \u7684 access log\uff0c\u6293\u51fa\u524d\u5341\u5927\u7db2\u7ad9\u6d41\u91cf\u5147\u624b"},"content":{"rendered":"<p>\u8aaa\u5230 Log \u5206\u6790\u5927\u5bb6\u90fd\u6703\u5148\u60f3\u5230\u7528 AWStats \u4f86\u5206\u6790\uff0c\u6c92\u932f\u9019\u7d55\u5c0d\u662f\u4e00\u500b\u6700\u597d\u7684\u89e3\u6c7a\u65b9\u5f0f\uff0c\u4f46\u5982\u679c\u4f60\u53ea\u662f\u8981\u7c21\u55ae\u7684\u5206\u6790\u4e00\u4e9b\u8cc7\u8a0a\uff0c\u5c31\u53ef\u4ee5\u5229\u7528\u4e00\u4e9b\u7c21\u55ae\u7684 shell \u7d44\u5408\u4f86\u6488\u51fa\u4f60\u8981\u7684\u8cc7\u6599<\/p>\n<p>&nbsp;<\/p>\n<p>\u9019\u7bc7\u4e3b\u8981\u662f\u91dd\u5c0d Apache \u7684 access log \u4f86\u9032\u884c\u5206\u6790\uff0c\u4e26\u63d0\u4f9b\u4ee5\u4e0b\u7bc4\u4f8b\u7d66\u5927\u5bb6\u53c3\u8003<\/p>\n<p>&nbsp;<\/p>\n<p><span>\u53d6\u5f97\u524d\u5341\u540daccess \u6700\u591a\u7684IP \u4f4d\u5740<\/span><\/p>\n<pre class=\"lang:default decode:true \"><span>cat access_log | awk'{print $ 1}'| sort | uniq -c | sort -nr | head -10<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p>\u53d6\u5f97\u524d\u5341\u540d access \u6700\u591a\u7684\u7db2\u9801<\/p>\n<pre class=\"lang:default decode:true\"><span>cat access_log | awk'{print $ 11}'| sort | uniq -c | sort -nr | head -10<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p>\u53d6\u5f97\u524d\u5341\u540d\u4e0b\u8f09\u6d41\u91cf\u6700\u5927\u7684 zip \u6a94\u6848<\/p>\n<pre class=\"lang:default decode:true \"><span>cat access.log | awk'\uff08$ 7\u301c\/ \\\u3002zip \/\uff09{print $ 10\u201c\u201d $ 1\u201c\u201d $ 4\u201c\u201d $ 7}'| sort -nr | head -10<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p>\u53d6\u5f97\u524d\u5341\u540d Loading \u6700\u5927\u7684\u9801\u9762 (\u5927\u65bc60\u79d2\u7684 php \u9801\u9762)<\/p>\n<pre class=\"lang:default decode:true \"><span>cat access_log | awk'\uff08$ NF&gt; 60 &amp;&amp; $ 7\u301c\/ \\\u3002php \/\uff09{print $ 7}'| sort -n | uniq -c | sort -nr | head -10<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p>\u53d6\u5f97\u524d\u5341\u540d User access \u6700\u4e45\u7684\u9801\u9762<\/p>\n<pre class=\"lang:default decode:true\"><span>cat access_log | awk'\uff08$ 7\u301c\/ \\\u3002php \/\uff09{print $ NF\u201c\u201d $ 1\u201c\u201d $ 4\u201c\u201d $ 7}'| sort -nr | head -10<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p><span>\u53d6\u5f97access log \u5e73\u5747\u6d41\u91cf(GB)<\/span><\/p>\n<pre class=\"lang:default decode:true \"><span>cat access_log | awk'{sum + = $ 10} END {print sum \/ 1024\/1024\/1024}'<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p><span>\u53d6\u5f97\u6240\u6709404 Link<\/span><\/p>\n<pre class=\"lang:default decode:true \"><span>awk'\uff08$ 9\u301c\/ 404 \/\uff09'access_log | awk'{print $ 9\uff0c$ 7}'| \u5206\u985e<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p>\u53d6\u5f97\u6240\u6709 access code \u7684 stats \u6578\u91cf<\/p>\n<pre class=\"lang:default decode:true \"><span>cat access_log | awk -F'''$ 9 ==\u201c 400\u201d || $ 9 ==\u201c 404\u201d || $ 9 ==\u201c 408\u201d || $ 9 ==\u201c 499\u201d || $ 9 ==\u201c 500\u201d || $ 9 ==\u201c 502\u201d || $ 9 ==\u201c 504\u201d {print $ 9}'| | \u6392\u5e8f| uniq -c | \u66f4\u591a<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p>\u4ee5\u4e0a\u53ea\u662f\u7c21\u55ae\u5206\u6790\u51fa\u5e38\u7528\u7684\u9700\u6c42\uff0c\u4e5f\u53ef\u4ee5\u81ea\u884c\u659f\u914c\u8abf\u6574\uff0c\u7136\u5f8c\u518d\u5f9e\u4e2d\u627e\u5230\u81ea\u5df1\u60f3\u8981\u7684\u5206\u6790\u6a21\u5f0f<\/p>\n<p>\u76f8\u4fe1\u5728\u65e5\u5e38\u7684\u7dad\u8b77\u4f7f\u7528\u4e2d\u53ef\u4ee5\u5e6b\u4e0a\u5f88\u5927\u7684\u5fd9\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8aaa\u5230 Log \u5206\u6790\u5927\u5bb6\u90fd\u6703\u5148\u60f3\u5230\u7528 AWStats \u4f86\u5206\u6790\uff0c\u6c92\u932f\u9019\u7d55\u5c0d\u662f\u4e00\u500b\u6700\u597d\u7684\u89e3\u6c7a\u65b9\u5f0f\uff0c\u4f46\u5982\u679c\u4f60\u53ea\u662f\u8981\u7c21\u55ae\u7684\u5206\u6790\u4e00\u4e9b\u8cc7\u8a0a\uff0c\u5c31\u53ef\u4ee5\u5229\u7528\u4e00\u4e9b\u7c21\u55ae\u7684 shell \u7d44\u5408\u4f86\u6488\u51fa\u4f60\u8981\u7684\u8cc7\u6599 &nbsp; \u9019\u7bc7\u4e3b\u8981\u662f\u91dd\u5c0d Apache \u7684 access log \u4f86\u9032\u884c\u5206\u6790\uff0c\u4e26\u63d0\u4f9b\u4ee5\u4e0b\u7bc4\u4f8b\u7d66\u5927\u5bb6\u53c3\u8003 &nbsp; \u53d6\u5f97\u524d\u5341\u540daccess \u6700\u591a\u7684IP \u4f4d\u5740 cat access_log | awk'{print $ 1}&#8217;| sort | uniq -c | sort -nr | head -10 &nbsp; \u53d6\u5f97\u524d\u5341\u540d access \u6700\u591a\u7684\u7db2\u9801 cat access_log | awk'{print $ 11}&#8217;| sort | uniq -c | sort -nr | head -10 &nbsp; &hellip; <a href=\"https:\/\/www.strongd.net\/?p=1565\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">\u5feb\u901f\u5206\u6790 Apache \u7684 access log\uff0c\u6293\u51fa\u524d\u5341\u5927\u7db2\u7ad9\u6d41\u91cf\u5147\u624b<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[244,122],"class_list":["post-1565","post","type-post","status-publish","format-standard","hentry","category-20","tag-accesslog","tag-apache"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/1565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1565"}],"version-history":[{"count":1,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/1565\/revisions"}],"predecessor-version":[{"id":1566,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/1565\/revisions\/1566"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}