{"id":86394,"date":"2024-01-07T01:28:14","date_gmt":"2024-01-06T17:28:14","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=86394"},"modified":"2024-01-07T01:28:14","modified_gmt":"2024-01-06T17:28:14","slug":"deletefile-space","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/deletefile-space.html","title":{"rendered":"\u4e3a\u4ec0\u4e48\u5220\u9664\u4e86\u6587\u4ef6\u7a7a\u95f4\u5374\u4e0d\u91ca\u653e\uff1f"},"content":{"rendered":"
\u4f60\u662f\u5426\u78b0\u89c1\u8fc7 Linux \u73af\u5883\u4e0b\uff0c\u6587\u4ef6\u5df2\u7ecf\u5220\u9664\uff0c\u4f46\u662f\u7a7a\u95f4\u672a\u88ab\u91ca\u653e\u7684\u60c5\u51b5\uff1f\u8fd9\u7bc7\u5c0f\u6587\u5c31\u4f1a\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u8fd9\u79cd\u95ee\u9898\u7684\u4e00\u4e2a\u573a\u666f\uff0c\u4ee5\u53ca\u76f8\u5e94\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n
\u6211\u4eec\u7684\u4e00\u53f0\u5e94\u7528\u670d\u52a1\u5668\uff0c\u64cd\u4f5c\u7cfb\u7edf\u662f Red Hat Linux\uff0c\u76d1\u63a7\u62a5\u8b66\uff0c\/opt\/applog\u6587\u4ef6\u7cfb\u7edf\u4f7f\u7528\u7387\u8d85\u9608\u503c\uff0c\u6574\u4f53\u5bb9\u91cf\u4e3a50G\uff0c\u4f46\u53d1\u73b0\u5b9e\u9645\u6587\u4ef6\u5bb9\u91cf20G\uff0c\u5269\u4e0b\u768430G\u7a7a\u95f4\u662f\u4ec0\u4e48\uff1f<\/p>\n
\u6211\u4eec\u77e5\u9053\uff0cLinux \u73af\u5883\u4e0b\uff0c\u4efb\u4f55\u4e8b\u7269\uff0c\u90fd\u662f\u4ee5\u6587\u4ef6\u7684\u5f62\u5f0f\u5b58\u5728\uff0c\u7cfb\u7edf\u5728\u540e\u53f0\uff0c\u4e3a\u6bcf\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff0c\u5206\u914d\u4e86\u4e00\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u4ed6\u4e3a\u5e94\u7528\u7a0b\u5e8f\u548c\u64cd\u4f5c\u7cfb\u7edf\u4e4b\u95f4\u7684\u4ea4\u4e92\u64cd\u4f5c\u63d0\u4f9b\u4e86\u901a\u7528\u7684\u63a5\u53e3\uff0c\u65e2\u7136\u662f\u6587\u4ef6\uff0c\u5c31\u4f1a\u5360\u7528\u7a7a\u95f4\uff0c\u6b64\u65f6\u53ef\u4ee5\u4f7f\u7528 lsof \u6307\u4ee4\uff0c\u4ed6\u53ef\u4ee5\u5217\u51fa\uff0c\u5f53\u524d\u7cfb\u7edf\u6b63\u5728\u6253\u5f00\u7684\u6587\u4ef6\u3002<\/p>\n
\n>lsof\r\nCOMMAND \u00a0 \u00a0 \u00a0PID \u00a0 \u00a0 \u00a0USER \u00a0 FD \u00a0 \u00a0 \u00a0TYPE \u00a0 \u00a0DEVICE \u00a0SIZE\/OFF \u00a0 \u00a0 \u00a0NODE NAME\r\n...\r\nfilebeat \u00a0111442 \u00a0 app \u00a01r \u00a0 \u00a0 \u00a0REG \u00a0 \u00a0 253,3 209715229 \u00a0 1040407 \/opt\/applog\/E.20171016.info.012.log\r\nfilebeat \u00a0111442 \u00a0 app \u00a02r \u00a0 \u00a0 \u00a0REG \u00a0 \u00a0 253,3 209715254 \u00a0 \u00a0385080 \/opt\/applog\/E.20171015.info.001.log (deleted)\r\n...<\/pre>\n<\/blockquote>\n\u8868\u5934\u5404\u5b57\u6bb5\uff0c\u542b\u4e49\u5982\u4e0b\uff1a<\/p>\n
COMMAND\uff1a\u8fdb\u7a0b\u7684\u540d\u79f0
\nPID\uff1a\u8fdb\u7a0b\u6807\u8bc6\u7b26
\nUSER\uff1a\u8fdb\u7a0b\u6240\u6709\u8005
\nFD\uff1a\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u5e94\u7528\u7a0b\u5e8f\u901a\u8fc7\u6587\u4ef6\u63cf\u8ff0\u7b26\u8bc6\u522b\u8be5\u6587\u4ef6\u3002\u5982cwd\u3001txt\u7b49
\nTYPE\uff1a\u6587\u4ef6\u7c7b\u578b\uff0c\u5982DIR\u3001REG\u7b49
\nDEVICE\uff1a\u6307\u5b9a\u78c1\u76d8\u7684\u540d\u79f0
\nSIZE\uff1a\u6587\u4ef6\u7684\u5927\u5c0f
\nNODE\uff1a\u7d22\u5f15\u8282\u70b9\uff08\u6587\u4ef6\u5728\u78c1\u76d8\u4e0a\u7684\u6807\u8bc6\uff09
\nNAME\uff1a\u6253\u5f00\u6587\u4ef6\u7684\u786e\u5207\u540d\u79f0<\/p><\/blockquote>\n\u53ef\u4ee5\u770b\u51fa\uff0c\u6709\u4e00\u4e9b\u884c\u4e2d\uff0cNAME\u6807\u8bc6\u4e86(deleted)<\/p>\n
\/opt\/applog\/E.20171015.info.001.log (deleted)<\/p><\/blockquote>\n
\u4ed6\u7684\u542b\u4e49\uff0c\u5c31\u662f\u8fd9\u6587\u4ef6\u5df2\u88ab\u5220\u9664\uff0c\u4f46\u6253\u5f00\u6587\u4ef6\u7684\u53e5\u67c4\uff0c\u5e76\u672a\u5173\u95ed\uff0c\u518d\u770b COMMAND \u7684\u540d\u79f0\u662f filebeat\uff0cUSER \u8fdb\u7a0b\u6240\u6709\u8005\u662f app\uff0c\u8fd9\u662f\u6211\u4eec\u7684\u65e5\u5fd7\u91c7\u96c6\u8fdb\u7a0b\uff0capp \u7528\u6237\u5f00\u542f\u4e86 filebeat \u8fdb\u7a0b\u3002<\/p>\n
\u63d2\u64ad\u4e00\u4e0b\u65e5\u5fd7\u91c7\u96c6\u5e73\u53f0<\/p>\n
\u4f20\u7edf\u7684\u5f00\u6e90\u65e5\u5fd7\u5e73\u53f0\uff0c\u5373 ELK\uff0c\u7531 ElasticSearch\u3001Logstash \u548c Kiabana \u4e09\u4e2a\u5f00\u6e90\u5de5\u5177\u7ec4\u6210\uff0c\u5176\u4e2d\uff1a<\/p>\n
\n
- Elasticsearch \u662f\u4e2a\u5f00\u6e90\u5206\u5e03\u5f0f\u641c\u7d22\u5f15\u64ce\uff0c\u5206\u5e03\u5f0f\uff0c\u96f6\u914d\u7f6e\uff0c\u81ea\u52a8\u53d1\u73b0\uff0c\u7d22\u5f15\u81ea\u52a8\u5206\u7247\uff0c\u7d22\u5f15\u526f\u672c\u673a\u5236\uff0crestful \u98ce\u683c\u63a5\u53e3\uff0c\u591a\u6570\u636e\u6e90\uff0c\u81ea\u52a8\u641c\u7d22\u8d1f\u8f7d\u7b49\u3002<\/li>\n
- Logstash \u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u91c7\u96c6\u5de5\u5177\uff0c\u4ed6\u53ef\u4ee5\u5bf9\u65e5\u5fd7\u8fdb\u884c\u6536\u96c6\u3001\u8fc7\u6ee4\uff0c\u5e76\u5c06\u5176\u5b58\u50a8\u4f9b\u4ee5\u540e\u4f7f\u7528\u3002<\/li>\n
- Kibana \u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u56fe\u5f62 Web \u5de5\u5177\uff0c\u53ef\u4ee5\u4e3a Logstash \u548c ElasticSearch \u63d0\u4f9b\u65e5\u5fd7\u5206\u6790\u53cb\u597d\u7684 Web \u754c\u9762\uff0c\u53ef\u4ee5\u6c47\u603b\u3001\u5206\u6790\u548c\u641c\u7d22\u91cd\u8981\u6570\u636e\u65e5\u5fd7\u3002<\/li>\n<\/ul>\n
\u5e38\u89c1\u7684\u90e8\u7f72\u56fe\uff0c\u5982\u4e0b\u6240\u793a<\/p>\n
<\/p>\n
\u5bf9\u4e8e\u4e0a\u9762\u63d0\u5230\u7684 filebeat \u53c8\u662f\u4ec0\u4e48\uff1f\u548c ELK \u6709\u4ec0\u4e48\u8054\u7cfb\uff1f<\/p>\n
\u77e5\u4e4e\u4e0a\u6709\u4e00\u6bb5\u5927\u725b\u9976\u741b\u7433\u7684\u4ecb\u7ecd(\u300aELKstack \u6743\u5a01\u6307\u5357\u300b\u4f5c\u8005)\uff0c\u975e\u5e38\u7cbe\u8f9f\uff0c\u5f15\u81ea\u00a0https:\/\/www.zhihu.com\/question\/54058964\/answer\/137882919<\/p>\n
\u56e0\u4e3a logstash \u662f jvm \u8dd1\u7684\uff0c\u8d44\u6e90\u6d88\u8017\u6bd4\u8f83\u5927\uff0c\u6240\u4ee5\u540e\u6765\u4f5c\u8005\u53c8\u7528 golang \u5199\u4e86\u4e00\u4e2a\u529f\u80fd\u8f83\u5c11\u4f46\u662f\u8d44\u6e90\u6d88\u8017\u4e5f\u5c0f\u7684\u8f7b\u91cf\u7ea7\u7684 logstash-forwarder\u3002\u4e0d\u8fc7\u4f5c\u8005\u53ea\u662f\u4e00\u4e2a\u4eba\uff0c\u52a0\u5165<http:\/\/elastic.co\u516c\u53f8\u4ee5\u540e\uff0c\u56e0\u4e3a es \u516c\u53f8\u672c\u8eab\u8fd8\u6536\u8d2d\u4e86\u53e6\u4e00\u4e2a\u5f00\u6e90\u9879\u76ee packetbeat\uff0c\u800c\u8fd9\u4e2a\u9879\u76ee\u4e13\u95e8\u5c31\u662f\u7528 golang \u7684\uff0c\u6709\u6574\u4e2a\u56e2\u961f\uff0c\u6240\u4ee5 es \u516c\u53f8\u5e72\u8106\u628a logstash-forwarder \u7684\u5f00\u53d1\u5de5\u4f5c\u4e5f\u5408\u5e76\u5230\u540c\u4e00\u4e2a golang \u56e2\u961f\u6765\u641e\uff0c\u4e8e\u662f\u65b0\u7684\u9879\u76ee\u5c31\u53eb filebeat \u4e86\u3002<\/p><\/blockquote>\n
<\/p>\n
\u7b80\u5355\u6765\u8bb2\uff0cfilebeat \u5c31\u662f\u65e5\u5fd7\u91c7\u96c6\u7684\u8fdb\u7a0b agent\uff0c\u8d1f\u8d23\u91c7\u96c6\u5e94\u7528\u65e5\u5fd7\u6587\u4ef6\u3002<\/p>\n
\u5bf9\u4e8e\u6211\u4e0a\u9762\u7684\u8fd9\u4e2a\u95ee\u9898\uff0c\u4e4b\u6240\u4ee5\u6709\u5927\u91cf\u7684(deleted)\uff0c\u672a\u91ca\u653e\u6587\u4ef6\u53e5\u67c4\uff0c\u8fd8\u6709\u4e2a\u80cc\u666f\uff0c\u5c31\u662f\u7531\u4e8e\u78c1\u76d8\u7a7a\u95f4\u975e\u5e38\u6709\u9650\uff0c\u4e34\u65f6\u52a0\u4e86\u4efb\u52a1\uff0c\u6bcf\u5c0f\u65f6\u5220\u966412\u5c0f\u65f6\u524d\u7684\u65e5\u5fd7\uff0c\u6362\u53e5\u8bdd\u8bf4\uff0c\u5b9a\u65f6\u4efb\u52a1\u4f1a\u81ea\u52a8\u5220\u9664\u6b64\u65f6 filebeat \u6b63\u5728\u6253\u5f00\u7740\u7684\u4e00\u4e9b\u6587\u4ef6\uff0c\u4e8e\u662f\u8fd9\u4e9b\u6587\u4ef6\uff0c\u5c31\u53d8\u4e3a\u4e86\u672a\u91ca\u653e\u7684\u6587\u4ef6\uff0c\u56e0\u6b64\u5b9e\u9645\u6587\u4ef6\u5220\u9664\u4e86\uff0c\u4f46\u7a7a\u95f4\u672a\u88ab\u91ca\u653e\u3002<\/p>\n
\u89e3\u51b3\u65b9\u68481\uff1a<\/strong><\/p>\n
\u4e3a\u4e86\u8fc5\u901f\u91ca\u653e\u7a7a\u95f4\u5360\u7528\uff0c\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\uff0c\u5c31\u662f kill -9 filebeat \u8fdb\u7a0b\uff0c\u6b64\u65f6\u7a7a\u95f4\u4f1a\u91ca\u653e\u3002\u4f46\u5e76\u4e0d\u662f\u4ece\u6839\u672c\u89e3\u51b3\uff0c\u5b9a\u65f6\u4efb\u52a1\u8fd8\u4f1a\u5220\u9664\u8fd9\u4e9b\uff0cfilebeat \u6253\u5f00\u7684\u6587\u4ef6\uff0c\u5bfc\u81f4\u7a7a\u95f4\u6ee1\u3002<\/p>\n
\u89e3\u51b3\u65b9\u68482\uff1a<\/strong>
\nfilebeat \u7684\u914d\u7f6e\u6587\u4ef6 filebeat.yml\uff0c\u5176\u5b9e\u6709\u4e24\u4e2a\u53c2\u6570\uff1a<\/p>\n\n
- close_older: 1h
\n\u8bf4\u660e<\/strong>\uff1aClose older closes the file handler for which were not modified for longer then close_older. Time strings like 2h (2 hours), 5m (5 minutes) can be used.<\/li>\n<\/ul>\n\u5373\u5982\u679c\u4e00\u4e2a\u6587\u4ef6\u5728\u67d0\u4e2a\u65f6\u95f4\u6bb5\u5185\u6ca1\u6709\u53d1\u751f\u8fc7\u66f4\u65b0\uff0c\u5219\u5173\u95ed\u76d1\u63a7\u7684\u6587\u4ef6handle\uff0c\u9ed8\u8ba41\u5c0f\u65f6\u3002<\/p>\n
\n
- force_close_files: false
\n\u8bf4\u660e<\/strong>\uff1aThis option closes a file, as soon as the file name changes. This config option is recommended on windows only. Filebeat keeps the files it\u2019s reading open. This can cause issues when the file is removed, as the file will not be fully removed until also Filebeat closes the reading. Filebeat closes the file handler after ignore_older. During this time no new file with the same name can be created. Turning this feature on the other hand can lead to loss of data on rotate files. It can happen that after file rotation the beginning of the new file is skipped, as the reading starts at the end. We recommend to leave this option on false but lower the ignore_older value to release files faster.<\/li>\n<\/ul>\n\u5373\u5f53\u6587\u4ef6\u540d\u79f0\u6709\u53d8\u5316\u65f6\uff0c\u5305\u62ec\u6539\u540d\u548c\u5220\u9664\uff0c\u4f1a\u81ea\u52a8\u5173\u95ed\u4e00\u4e2a\u6587\u4ef6\u3002<\/p>\n
\u8fd9\u4e24\u4e2a\u53c2\u6570\u7ed3\u5408\u8d77\u6765\uff0c\u6839\u636e\u5e94\u7528\u9700\u6c42\uff0c\u4e00\u4e2a\u6587\u4ef630\u5206\u949f\u5185\u4e0d\u66f4\u65b0\uff0c\u5219\u9700\u8981\u5173\u95ed\u53e5\u67c4\uff0c\u6587\u4ef6\u6539\u540d\u6216\u5220\u9664\uff0c\u9700\u8981\u5173\u95ed\u53e5\u67c4<\/p>\n
close_older: 30m
\nforce_close_files: true<\/p><\/blockquote>\n\u53ef\u4ee5\u6ee1\u8db3\uff0cfilebeat \u91c7\u96c6\u65e5\u5fd7\uff0c\u4ee5\u53ca\u5b9a\u65f6\u5220\u9664\u5386\u53f2\u6587\u4ef6\uff0c\u8fd9\u4e24\u4e2a\u4efb\u52a1\u7684\u57fa\u672c\u8981\u6c42\u3002<\/p>\n
\n\u539f\u6587\u6765\u81ea\uff1ahttp:\/\/www.yunweipai.com\/archives\/23125.html<\/a><\/p>\n