{"id":427,"date":"2014-04-11T16:26:19","date_gmt":"2014-04-11T08:26:19","guid":{"rendered":"http:\/\/ufqi.com\/blog\/?p=427"},"modified":"2014-04-11T16:28:38","modified_gmt":"2014-04-11T08:28:38","slug":"tech-details-201404","status":"publish","type":"post","link":"https:\/\/ufqi.com\/blog\/tech-details-201404\/","title":{"rendered":"\u8ba1\u7b97\u673a\u6280\u672f\u70b9\u6ef4, rotatelogs, awk"},"content":{"rendered":"<p><strong>1. Apache HTTPD 2.4+ \u7684 <a href=\"http:\/\/httpd.apache.org\/docs\/current\/programs\/rotatelogs.html\" target=\"_blank\">rotatelogs <\/a>\u65b0\u529f\u80fd \u5f88\u8d34\u5fc3<\/strong><\/p>\n<p>\u539f\u6765\u7684 rotatelogs \u5c31\u88ab\u632a\u5230\u522b\u5904\u7528\u505a\u65e5\u5fd7\u7684\u5f52\u96c6\u4e0e\u7ba1\u7406\u3002\u73b0\u5728\u9047\u5230\u65b0\u7684\u9700\u6c42\u3002\u6bd4\u5982\u5c06\u67d0\u4e2a\u65e5\u5fd7\u6587\u4ef6\u89c6\u4e3a\u4e00\u4e2a\u6709\u59cb\u65e0\u7ec8\u7684\u7f13\u51b2\u6c60\uff0c\u4e00\u8fb9\u987a\u5e8f\u5199\u5165\uff0c\u4e00\u8fb9\u987a\u5e8f\u8bfb\u51fa\uff0c\u800c\u4e14\u5e0c\u671b\u8fd8\u80fd\u6309\u5929\u5206\u6587\u4ef6\uff0c\u4e0d\u7136\u5c3a\u5bf8\u4f1a\u5927\u5230\u4e0d\u597d\u64cd\u4f5c\u3002<\/p>\n<p>\u6309\u5929\u5f52\u96c6\uff0crotatelogs\u63d0\u4f9b\u4e86\u5b8c\u5907\u7684\u652f\u6301\uff0c\u524d\u9762\u7684\u987a\u5e8f\u5199\u5165\u4e0d\u662f\u95ee\u9898\uff0c\u800c\u540e\u9762\u7684\u987a\u5e8f\u8bfb\u51fa\u5c31\u6709\u96be\u5ea6\u4e86\u3002\u5728?nix\u4e0a\uff0c\u901a\u5e38\u4f1a\u7528\u5230 tail \u8fd9\u4e2a\u5229\u5668\uff0c\u4f46tail\u672c\u8eab\u65e0\u6cd5\u5bf9\u66f4\u6362\u6587\u4ef6\u540d\u7684\u73b0\u8c61\u505a\u5904\u7406\u3002<\/p>\n<p>\u4e5f\u8bb8\u662fApapche HTTPD\u4e5f\u9047\u5230\u8fd9\u6837\u7684\u95ee\u9898\uff0c\u57282.4+\u7684\u7248\u672c\u4e2d\uff0crotatelogs\u4e2d\u589e\u52a0\u4e86 -L \u53c2\u6570\uff1a<\/p>\n<p><code>-L<\/code>\u00a0<var>linkname<\/var>Causes a hard link to be made from the current logfile to the specified link name. This can be used to watch the log continuously across rotations using a command like\u00a0<code>tail -F linkname<\/code>.<\/p>\n<p>\u751a\u597d\u3002\u771f\u53d1\u56f0\u5462\uff0c\u9012\u4e2a\u6795\u5934\u3002<\/p>\n<p>\u5728\u4e00\u8fb9\u8bfb\u51fa\u7684\u4e00\u6bb5\uff0c\u8fd9\u6837\uff1a<\/p>\n<p>shell&gt; tail &#8211;follow=name &#8211;max-unchanged-stats=5 &#8211;retry &#8211;sleep-interval=3 my_file<\/p>\n<p><strong>2. \u6570\u636e\u632a\u79fb\u9700\u7ec6\u8282<\/strong><\/p>\n<p>-ufqi \u5728\u6539\u7248\u5e76\u632a\u5230 VPS \u4e4b\u524d\uff0c\u589e\u52a0\u505a\u4e86\u5168\u91cf\u5907\u4efd\uff0c\u4f46\u6570\u636e\u5e93\u7684\u5907\u4efd\u662fMySQL\u7684\u76ee\u524d\u5168\u62f7\u8d1d\uff0c\u7559\u7684\u662fMySQL\u683c\u5f0f\u7684.MYI, .MYD\u7b49\u6587\u4ef6\u3002\u52a0\u4e0a\u65b0\u7248\u7684\u6570\u636e\u5e93\u7edf\u4e00\u5c06\u6570\u636e\u8868\u53ca\u7a0b\u5e8f\u8fd0\u884c\u65f6\u73af\u5883\u90fd\u6539\u6210 UTF-8\uff0c\u539f\u6765\u7684\u6570\u636e\u5c31\u9762\u4e34\u8f6c\u5e93\u3001\u8f6c\u7801\u7684\u95ee\u9898\u3002<\/p>\n<p>\u7efc\u5408\u4f7f\u7528Shell\u3001AWK\u548cIconv\u7b49\u5de5\u5177\uff0c\u5c06\u6570\u636e\u4ece\u4e00\u4e2a\u4e34\u65f6\u7684\u65e7\u5e93\u4e2d\u8f6c\u51fa\u6765\u6210txt\uff0c\u7136\u540e\u518d\u5c06txt\u8f6c\u7801\uff0c\u8f6c\u7801\u4e4b\u540e\u5c06txt\u62fc\u5199\u6210\u65b0\u7684SQL\uff0c\u7136\u540e\u518d\u5012\u5165\u5230\u65b0\u6570\u636e\u5e93\u4e2d\uff0c\u5e76\u4e0d\u662f\u96be\u4e8b\u3002<\/p>\n<p>\u4f46\u5947\u602a\u7684\u73b0\u8c61\u53d1\u73b0\u4e86\uff0c\u6211\u4e4b\u524d\u4e00\u76f4\u6709\u5370\u8c61\u7684\u4e00\u7bc7\u6587\u7ae0\uff0c\u201d<a href=\"http:\/\/ufqi.com\/cn\/exp\/x3901.html?title=%E6%9C%80%E9%95%BF%E7%9A%84%E4%B8%80%E5%A4%9C\" target=\"_blank\">\u6700\u957f\u7684\u4e00\u591c<\/a>\u201c\uff0c\u8bb0\u5f55\u7559\u5b66\u4e8b\u4ef6\u7684\u6587\u7ae0\u6b7b\u6d3b\u67e5\u4e0d\u5230\u3002\u7ecf\u8fc7\u8fdb\u4e00\u6b65\u5730\u67e5\u770b\uff0c\u53d1\u73b0\u6570\u636e\u5728\u65b0\u65e7\u6570\u636e\u5e93\u4e2d\u4e0d\u4e00\u81f4\uff0c\u518d\u5230\u8f6c\u7801\u53ca\u65b0SQL\u751f\u6210\u7684\u7a0b\u5e8f\u4e2d\u6838\u67e5\uff0c\u53d1\u73b0SQL\u91cc\u7684\u6570\u636e\u91cf\u4e5f\u5bf9\uff0cSQL\u8bed\u53e5\u88ab\u6267\u884c\uff0c\u4f46\u65b0\u751f\u6210\u7684\u8bb0\u5f55\u6761\u6570\u4e0e\u539f\u6765\u4e0d\u7b26\uff0c\u6709\u77ed\u7f3a\u3002<\/p>\n<p>\u8fdb\u4e00\u6b65\u5730\u7ec6\u5fc3\u89c2\u5bdf\u53d1\u73b0\uff0c\u5b58\u50a8\u5355\u5f15\u53f7\u548c\u53cc\u5f15\u53f7\u7684\u8f6c\u4e49\u95ee\u9898\u3002<\/p>\n<p>\u6709\u4e24\u4e2a\u7ec6\u8282\u5728\u7b2c\u4e00\u6b21\u505a\u65f6\u5ffd\u7565\u4e86\uff0c\u9700\u7ea0\u6b63\uff1a<\/p>\n<p>1\uff09awk\u5728\u5207\u5206\u7531MySQL\u5bfc\u51fa\u7684\u6570\u636etxt\u65f6\uff0c\u9700\u589e\u52a0 -F &#8220;\\t&#8221;, \u4f7f\u7528\u5236\u8868\u7b26\u505a\u5b57\u6bb5\u5206\u5272\uff1b<\/p>\n<p>2\uff09\u5982\u679c\u5728\u65b0\u7ec4\u88c5\u7684SQL\u4e2d\uff0c\u4f7f\u7528&#8221;\u4f5c\u4e3a\u5b57\u6bb5\u7684\u8fb9\u754c\uff0c\u5219\u9700\u8981\u4f7f\u7528 gsub(&#8220;\\&#8221;&#8221;, &#8220;\\\\\\&#8221;&#8221;, $4); \u8fd9\u6837\u7684\u5f62\u5f0f\uff0c\u5bf9\u67d0\u4e9b\u5b57\u6bb5\u4e2d\u7684&#8221;\u505a\u8f6c\u4e49\u64cd\u4f5c\u3002<\/p>\n<p>&#8212;-<\/p>\n<p>\u6d77\u91cf\u8ba1\u7b97\u673a\u8d44\u6e90\u4e0b\u8f7d\u5730\u5740\uff1a\u00a0<a href=\"http:\/\/labs.people.com.cn\/url4p\/index.php?sid=92977&amp;act=query&amp;shortkey=L2SW\" target=\"_blank\">-R\/L2SW<\/a>\u00a0 \uff085GB) \u751a\u81f3\u5305\u542b\u4e86\u300a\u8ba1\u7b97\u673a\u7a0b\u5e8f\u8bbe\u8ba1\u827a\u672f\u300b\u76841-4\u5377\uff01<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Apache HTTPD 2.4+ \u7684 rotatelogs \u65b0\u529f\u80fd \u5f88\u8d34 &hellip; <a href=\"https:\/\/ufqi.com\/blog\/tech-details-201404\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,6],"tags":[],"_links":{"self":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/427"}],"collection":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/comments?post=427"}],"version-history":[{"count":3,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/427\/revisions"}],"predecessor-version":[{"id":429,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/427\/revisions\/429"}],"wp:attachment":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/media?parent=427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/categories?post=427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/tags?post=427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}