{"id":131202,"date":"2019-01-11T08:00:44","date_gmt":"2019-01-11T00:00:44","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=131202"},"modified":"2019-01-03T08:52:06","modified_gmt":"2019-01-03T00:52:06","slug":"ulimit-system-performance","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/ulimit-system-performance.html","title":{"rendered":"Linux\u901a\u8fc7ulimit\u6539\u5584\u7cfb\u7edf\u6027\u80fd"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u7cfb\u7edf\u6027\u80fd\u4e00\u76f4\u662f\u4e00\u4e2a\u53d7\u5173\u6ce8\u7684\u8bdd\u9898\uff0c\u5982\u4f55\u901a\u8fc7\u6700\u7b80\u5355\u7684\u8bbe\u7f6e\u6765\u5b9e\u73b0\u6700\u6709\u6548\u7684\u6027\u80fd\u8c03\u4f18\uff0c\u5982\u4f55\u5728\u6709\u9650\u8d44\u6e90\u7684\u6761\u4ef6\u4e0b\u4fdd\u8bc1\u7a0b\u5e8f\u7684\u8fd0\u4f5c\uff0culimit \u662f\u6211\u4eec\u5728\u5904\u7406\u8fd9\u4e9b\u95ee\u9898\u65f6\uff0c\u7ecf\u5e38\u4f7f\u7528\u7684\u4e00\u79cd\u7b80\u5355\u624b\u6bb5\u3002ulimit \u662f\u4e00\u79cd linux \u7cfb\u7edf\u7684\u5185\u952e\u529f\u80fd\uff0c\u5b83\u5177\u6709\u4e00\u5957\u53c2\u6570\u96c6\uff0c\u7528\u4e8e\u4e3a\u7531\u5b83\u751f\u6210\u7684 shell \u8fdb\u7a0b\u53ca\u5176\u5b50\u8fdb\u7a0b\u7684\u8d44\u6e90\u4f7f\u7528\u8bbe\u7f6e\u9650\u5236\u3002\u672c\u6587\u5c06\u5728\u540e\u9762\u7684\u7ae0\u8282\u4e2d\u8be6\u7ec6\u8bf4\u660e ulimit \u7684\u529f\u80fd\uff0c\u4f7f\u7528\u4ee5\u53ca\u5b83\u7684\u5f71\u54cd\uff0c\u5e76\u4ee5\u5177\u4f53\u7684\u4f8b\u5b50\u6765\u8be6\u7ec6\u5730\u9610\u8ff0\u5b83\u5728\u9650\u5236\u8d44\u6e90\u4f7f\u7528\u65b9\u9762\u7684\u5f71\u54cd\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
ulimit\u7684\u529f\u80fd\u548c\u7528\u6cd5<\/strong><\/div>\n
ulimit\u529f\u80fd\u7b80\u8ff0<\/strong><\/span><\/div>\n

\u5047\u8bbe\u6709\u8fd9\u6837\u4e00\u79cd\u60c5\u51b5\uff0c\u5f53\u4e00\u53f0 Linux \u4e3b\u673a\u4e0a\u540c\u65f6\u767b\u9646\u4e86 10 \u4e2a\u4eba\uff0c\u5728\u7cfb\u7edf\u8d44\u6e90\u65e0\u9650\u5236\u7684\u60c5\u51b5\u4e0b\uff0c\u8fd9 10 \u4e2a\u7528\u6237\u540c\u65f6\u6253\u5f00\u4e86 500 \u4e2a\u6587\u6863\uff0c\u800c\u5047\u8bbe\u6bcf\u4e2a\u6587\u6863\u7684\u5927\u5c0f\u6709 10M\uff0c\u8fd9\u65f6\u7cfb\u7edf\u7684\u5185\u5b58\u8d44\u6e90\u5c31\u4f1a\u53d7\u5230\u5de8\u5927\u7684\u6311\u6218\u3002\u800c\u5b9e\u9645\u5e94\u7528\u7684\u73af\u5883\u8981\u6bd4\u8fd9\u79cd\u5047\u8bbe\u590d\u6742\u7684\u591a\uff0c\u4f8b\u5982\u5728\u4e00\u4e2a\u5d4c\u5165\u5f0f\u5f00\u53d1\u73af\u5883\u4e2d\uff0c\u5404\u65b9\u9762\u7684\u8d44\u6e90\u90fd\u662f\u975e\u5e38\u7d27\u7f3a\u7684\uff0c\u5bf9\u4e8e\u5f00\u542f\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u6570\u91cf\uff0c\u5206\u914d\u5806\u6808\u7684\u5927\u5c0f\uff0cCPU \u65f6\u95f4\uff0c\u865a\u62df\u5185\u5b58\u5927\u5c0f\uff0c\u7b49\u7b49\uff0c\u90fd\u6709\u975e\u5e38\u4e25\u683c\u7684\u8981\u6c42\u3002\u8d44\u6e90\u7684\u5408\u7406\u9650\u5236\u548c\u5206\u914d\u3002<\/p>\n

\u4e0d\u4ec5\u4ec5\u662f\u4fdd\u8bc1\u7cfb\u7edf\u53ef\u7528\u6027\u7684\u5fc5\u8981\u6761\u4ef6\uff0c\u4e5f\u4e0e\u7cfb\u7edf\u4e0a\u8f6f\u4ef6\u8fd0\u884c\u7684\u6027\u80fd\u6709\u7740\u5bc6\u4e0d\u53ef\u5206\u7684\u8054\u7cfb\u3002\u8fd9\u65f6\uff0culimit\u53ef\u4ee5\u8d77\u5230\u5f88\u5927\u7684\u4f5c\u7528\uff0c\u5b83\u662f\u4e00\u79cd\u7b80\u5355\u5e76\u4e14\u6709\u6548\u7684\u5b9e\u73b0\u8d44\u6e90\u9650\u5236\u7684\u65b9\u5f0f\u3002ulimit\u7528\u4e8e\u9650\u5236shell\u542f\u52a8\u8fdb\u7a0b\u6240\u5360\u7528\u7684\u8d44\u6e90\uff0c\u652f\u6301\u4ee5\u4e0b\u5404\u79cd\u7c7b\u578b\u7684\u9650\u5236\uff1a\u6240\u521b\u5efa\u7684\u5185\u6838\u6587\u4ef6\u7684\u5927\u5c0f\u3001\u8fdb\u7a0b\u6570\u636e\u5757\u7684\u5927\u5c0f\u3001Shell\u8fdb\u7a0b\u521b\u5efa\u6587\u4ef6\u7684\u5927\u5c0f\u3001\u5185\u5b58\u9501\u4f4f\u7684\u5927\u5c0f\u3001\u5e38\u9a7b\u5185\u5b58\u96c6\u7684\u5927\u5c0f\u3001\u6253\u5f00\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u6570\u91cf\u3001\u5206\u914d\u5806\u6808\u7684\u6700\u5927\u5927\u5c0f\u3001CPU \u65f6\u95f4\u3001\u5355\u4e2a\u7528\u6237\u7684\u6700\u5927\u7ebf\u7a0b\u6570\u3001Shell \u8fdb\u7a0b\u6240\u80fd\u4f7f\u7528\u7684\u6700\u5927\u865a\u62df\u5185\u5b58\u3002\u540c\u65f6\uff0c\u5b83\u652f\u6301\u786c\u8d44\u6e90\u548c\u8f6f\u8d44\u6e90\u7684\u9650\u5236\u3002<\/p>\n

\u4f5c\u4e3a\u4e34\u65f6\u9650\u5236\uff0culimit \u53ef\u4ee5\u4f5c\u7528\u4e8e\u901a\u8fc7\u4f7f\u7528\u5176\u547d\u4ee4\u767b\u5f55\u7684 shell \u4f1a\u8bdd\uff0c\u5728\u4f1a\u8bdd\u7ec8\u6b62\u65f6\u4fbf\u7ed3\u675f\u9650\u5236\uff0c\u5e76\u4e0d\u5f71\u54cd\u4e8e\u5176\u4ed6 shell \u4f1a\u8bdd\u3002\u800c\u5bf9\u4e8e\u957f\u671f\u7684\u56fa\u5b9a\u9650\u5236\uff0culimit \u547d\u4ee4\u8bed\u53e5\u53c8\u53ef\u4ee5\u88ab\u6dfb\u52a0\u5230\u7531\u767b\u5f55 shell \u8bfb\u53d6\u7684\u6587\u4ef6\u4e2d\uff0c\u4f5c\u7528\u4e8e\u7279\u5b9a\u7684 shell \u7528\u6237\u3002<\/p>\n

\u5982\u4f55\u4f7f\u7528ulimit<\/strong><\/span><\/div>\n

ulimit\u901a\u8fc7\u4e00\u4e9b\u53c2\u6570\u9009\u9879\u6765\u7ba1\u7406\u4e0d\u540c\u79cd\u7c7b\u7684\u7cfb\u7edf\u8d44\u6e90\u3002\u5728\u672c\u8282\uff0c\u6211\u4eec\u5c06\u8bb2\u89e3\u8fd9\u4e9b\u53c2\u6570\u7684\u4f7f\u7528\u3002<\/p>\n

ulimit\u547d\u4ee4\u7684\u683c\u5f0f\u4e3a\uff1a<\/p>\n

\r\n$ ulimit [options] [limit]\r\n[options]\r\n\r\n-H: \u8bbe\u7f6e\u786c\u8d44\u6e90\u9650\u5236\uff0c\u4e00\u65e6\u8bbe\u7f6e\u4e0d\u80fd\u589e\u52a0\u3002\u5982\uff0culimit -Hs 64\uff1b\u9650\u5236\u786c\u8d44\u6e90\uff0c\u7ebf\u7a0b\u6808\u5927\u5c0f\u4e3a64K\u3002\r\n\r\n-S: \u8bbe\u7f6e\u8f6f\u8d44\u6e90\u9650\u5236\uff0c\u8bbe\u7f6e\u540e\u53ef\u4ee5\u589e\u52a0\uff0c\u4f46\u662f\u4e0d\u80fd\u8d85\u8fc7\u786c\u8d44\u6e90\u8bbe\u7f6e\u3002\u5982\uff0culimit -Sn 32\uff1b\u9650\u5236\u8f6f\u8d44\u6e90\uff0c32\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u3002\r\n\r\n-a: \u663e\u793a\u5f53\u524d\u6240\u6709\u7684limit\u4fe1\u606f\u3002\u5982\uff0culimit -a\uff1b\u663e\u793a\u5f53\u524d\u6240\u6709\u7684limit\u4fe1\u606f\u3002\r\n\r\n-c: \u6700\u5927\u7684core\u6587\u4ef6\u7684\u5927\u5c0f\uff0c \u4ee5blocks\u4e3a\u5355\u4f4d\u3002\u5982\uff0culimit -c unlimited\uff1b\u5bf9\u751f\u6210\u7684core\u6587\u4ef6\u7684\u5927\u5c0f\u4e0d\u8fdb\u884c\u9650\u5236\u3002\r\n\r\n-d: \u8fdb\u7a0b\u6700\u5927\u7684\u6570\u636e\u6bb5\u7684\u5927\u5c0f\uff0c\u4ee5Kbytes\u4e3a\u5355\u4f4d\u3002\u5982\uff0culimit -d unlimited\uff1b\u5bf9\u8fdb\u7a0b\u7684\u6570\u636e\u6bb5\u5927\u5c0f\u4e0d\u8fdb\u884c\u9650\u5236\u3002\r\n\r\n-f: \u8fdb\u7a0b\u53ef\u4ee5\u521b\u5efa\u6587\u4ef6\u7684\u6700\u5927\u503c\uff0c\u4ee5 blocks \u4e3a\u5355\u4f4d\u3002\u5982\uff0culimit -f 2048\uff1b\u9650\u5236\u8fdb\u7a0b\u53ef\u4ee5\u521b\u5efa\u7684\u6700\u5927\u6587\u4ef6\u5927\u5c0f\u4e3a2048 blocks\u3002\r\n\r\n-l: \u6700\u5927\u53ef\u52a0\u9501\u5185\u5b58\u5927\u5c0f\uff0c\u4ee5Kbytes\u4e3a\u5355\u4f4d\u3002\u5982\uff0culimit -l 32\uff1b\u9650\u5236\u6700\u5927\u53ef\u52a0\u9501\u5185\u5b58\u5927\u5c0f\u4e3a32Kbytes\u3002\r\n\r\n-m: \u6700\u5927\u5185\u5b58\u5927\u5c0f\uff0c\u4ee5Kbytes\u4e3a\u5355\u4f4d\u3002\u5982\uff0culimit -m unlimited\uff1b\u5bf9\u6700\u5927\u5185\u5b58\u4e0d\u8fdb\u884c\u9650\u5236\u3002\r\n\r\n-n: \u53ef\u4ee5\u6253\u5f00\u6700\u5927\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u6570\u91cf\u3002\u5982\uff0culimit -n 128\uff1b\u9650\u5236\u6700\u5927\u53ef\u4ee5\u4f7f\u7528128\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u3002\r\n\r\n-p: \u7ba1\u9053\u7f13\u51b2\u533a\u7684\u5927\u5c0f\uff0c\u4ee5Kbytes\u4e3a\u5355\u4f4d\u3002\u5982\uff0culimit -p 512\uff1b\u9650\u5236\u7ba1\u9053\u7f13\u51b2\u533a\u7684\u5927\u5c0f\u4e3a512Kbytes\u3002\r\n\r\n-s: \u7ebf\u7a0b\u6808\u5927\u5c0f\uff0c\u4ee5Kbytes\u4e3a\u5355\u4f4d\u3002\u5982\uff0c\u5982\uff0culimit -s 512\uff1b\u9650\u5236\u7ebf\u7a0b\u6808\u7684\u5927\u5c0f\u4e3a512Kbytes\u3002\r\n\r\n-t: \u6700\u5927\u7684CPU\u5360\u7528\u65f6\u95f4\uff0c\u4ee5\u79d2\u4e3a\u5355\u4f4d\u3002 \u5982\uff0culimit -t unlimited\uff1b\u5bf9\u6700\u5927\u7684CPU\u5360\u7528\u65f6\u95f4\u4e0d\u8fdb\u884c\u9650\u5236\u3002\r\n\r\n-u: \u7528\u6237\u6700\u5927\u53ef\u7528\u7684\u8fdb\u7a0b\u6570\u3002\u5982\uff0culimit -u 64\uff1b\u9650\u5236\u7528\u6237\u6700\u591a\u53ef\u4ee5\u4f7f\u752864\u4e2a\u8fdb\u7a0b\u3002\r\n\r\n-v: \u8fdb\u7a0b\u6700\u5927\u53ef\u7528\u7684\u865a\u62df\u5185\u5b58\uff0c\u5982\uff0c\u4ee5Kbytes\u4e3a\u5355\u4f4d\u3002\u5982\uff0culimit -v 200000\uff1b\u9650\u5236\u6700\u5927\u53ef\u7528\u7684\u865a\u62df\u5185\u5b58\u4e3a200000Kbytes\u3002\r\n<\/pre>\n
ulimit\u4f7f\u7528\u5b9e\u4f8b<\/strong><\/div>\n
\u7528\u6237\u8fdb\u7a0b\u7684\u6709\u6548\u8303\u56f4<\/strong><\/span><\/div>\n

ulimit \u4f5c\u4e3a\u5bf9\u8d44\u6e90\u4f7f\u7528\u9650\u5236\u7684\u4e00\u79cd\u5de5\u4f5c\uff0c\u662f\u6709\u5176\u4f5c\u7528\u8303\u56f4\u7684\u3002\u90a3\u4e48\uff0c\u5b83\u9650\u5236\u7684\u5bf9\u8c61\u662f\u5355\u4e2a\u7528\u6237\uff0c\u5355\u4e2a\u8fdb\u7a0b\uff0c\u8fd8\u662f\u6574\u4e2a\u7cfb\u7edf\u5462\uff1f\u4e8b\u5b9e\u4e0a\uff0culimit \u9650\u5236\u7684\u662f\u5f53\u524d shell \u8fdb\u7a0b\u4ee5\u53ca\u5176\u6d3e\u751f\u7684\u5b50\u8fdb\u7a0b\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5982\u679c\u7528\u6237\u540c\u65f6\u8fd0\u884c\u4e86\u4e24\u4e2a shell \u7ec8\u7aef\u8fdb\u7a0b\uff0c\u53ea\u5728\u5176\u4e2d\u4e00\u4e2a\u73af\u5883\u4e2d\u6267\u884c\u4e86 ulimit -s 100\uff0c\u5219\u8be5 shell \u8fdb\u7a0b\u91cc\u521b\u5efa\u6587\u4ef6\u7684\u5927\u5c0f\u6536\u5230\u76f8\u5e94\u7684\u9650\u5236\uff0c\u800c\u540c\u65f6\u53e6\u4e00\u4e2a shell \u7ec8\u7aef\u5305\u62ec\u5176\u4e0a\u8fd0\u884c\u7684\u5b50\u7a0b\u5e8f\u90fd\u4e0d\u4f1a\u53d7\u5176\u5f71\u54cd\u3002<\/p>\n

Shell 1<\/p>\n

\r\n$ ll -h newfile \r\n-rw-r--r--. 1 root root 223K 4\u6708  23 09:16 newfile\r\n$ ulimit -f 100\r\n$ cat newfile > shell1\r\nFile size limit exceeded (core dumped)\r\n$ ll -h shell1\r\n-rw-r--r--. 1 root root 100K 4\u6708 23 09:20 shell1\r\n<\/pre>\n

Shell 2<\/p>\n

\r\n$ cat newfile > shell2\r\n$ ll -d shell2 \r\n-rw-r--r--. 1 root root 227690 4\u6708  23 09:23 shell2\r\n$ ll -h shell2 \r\n-rw-r--r--. 1 root root 223K 4\u6708  23 09:23 shell2\r\n<\/pre>\n

\u90a3\u4e48\uff0c\u662f\u5426\u6709\u9488\u5bf9\u67d0\u4e2a\u5177\u4f53\u7528\u6237\u7684\u8d44\u6e90\u52a0\u4ee5\u9650\u5236\u7684\u65b9\u6cd5\u5462\uff1f\u7b54\u6848\u662f\u6709\u7684\uff0c\u4e34\u65f6\u751f\u6548\uff08\u4e0d\u9650\u5236\u6253\u5f00\u6587\u4ef6\u5927\u5c0f\u9650\u5236\uff09\uff1a<\/p>\n

\r\n$ ulimit -f unlimited\r\n<\/pre>\n

\u6216\u901a\u8fc7\u4fee\u6539\u7cfb\u7edf\u7684\/etc\/security\/limits.conf\u914d\u7f6e\u6587\u4ef6\u3002\u8be5\u6587\u4ef6\u4e0d\u4ec5\u80fd\u9650\u5236\u6307\u5b9a\u7528\u6237\u7684\u8d44\u6e90\u4f7f\u7528\uff0c\u8fd8\u80fd\u9650\u5236\u6307\u5b9a\u7ec4\u7684\u8d44\u6e90\u4f7f\u7528\u3002\u8be5\u6587\u4ef6\u7684\u6bcf\u4e00\u884c\u90fd\u662f\u5bf9\u9650\u5b9a\u7684\u4e00\u4e2a\u63cf\u8ff0\uff0c\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n

\r\n   \r\n<\/value><\/item><\/type><\/domain><\/pre>\n

domain \u8868\u793a\u7528\u6237\u6216\u8005\u7ec4\u7684\u540d\u5b57\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528 * \u4f5c\u4e3a\u901a\u914d\u7b26\u3002Type \u53ef\u4ee5\u6709\u4e24\u4e2a\u503c\uff0csoft \u548c hard\u3002Item \u5219\u8868\u793a\u9700\u8981\u9650\u5b9a\u7684\u8d44\u6e90\uff0c\u53ef\u4ee5\u6709\u5f88\u591a\u5019\u9009\u503c\uff0c\u5982 stack\uff0ccpu\uff0cnofile \u7b49\u7b49\uff0c\u5206\u522b\u8868\u793a\u6700\u5927\u7684\u5806\u6808\u5927\u5c0f\uff0c\u5360\u7528\u7684 cpu \u65f6\u95f4\uff0c\u4ee5\u53ca\u6253\u5f00\u7684\u6587\u4ef6\u6570\u3002\u901a\u8fc7\u6dfb\u52a0\u5bf9\u5e94\u7684\u4e00\u884c\u63cf\u8ff0\uff0c\u5219\u53ef\u4ee5\u4ea7\u751f\u76f8\u5e94\u7684\u9650\u5236\u3002\u4f8b\u5982\uff1a<\/p>\n

\r\n * hard noflle 100\r\n<\/pre>\n

\u8be5\u884c\u914d\u7f6e\u8bed\u53e5\u9650\u5b9a\u4e86\u4efb\u610f\u7528\u6237\u6240\u80fd\u521b\u5efa\u7684\u6700\u5927\u6587\u4ef6\u6570\u662f 100\u3002\u73b0\u5728\u5df2\u7ecf\u53ef\u4ee5\u5bf9\u8fdb\u7a0b\u548c\u7528\u6237\u5206\u522b\u505a\u8d44\u6e90\u9650\u5236\u4e86\uff0c\u770b\u4f3c\u5df2\u7ecf\u8db3\u591f\u4e86\uff0c\u5176\u5b9e\u4e0d\u7136\u3002\u5f88\u591a\u5e94\u7528\u9700\u8981\u5bf9\u6574\u4e2a\u7cfb\u7edf\u7684\u8d44\u6e90\u4f7f\u7528\u505a\u4e00\u4e2a\u603b\u7684\u9650\u5236\uff0c\u8fd9\u65f6\u5019\u6211\u4eec\u9700\u8981\u4fee\u6539\/proc\u4e0b\u7684\u914d\u7f6e\u6587\u4ef6\u3002\/proc\u76ee\u5f55\u4e0b\u5305\u542b\u4e86\u5f88\u591a\u7cfb\u7edf\u5f53\u524d\u72b6\u6001\u7684\u53c2\u6570\uff0c\u4f8b\u5982\/proc\/sys\/kernel\/pid_max\uff0c\/proc\/sys\/net\/ipv4\/ip_local_port_range\u7b49\u7b49\uff0c\u4ece\u6587\u4ef6\u7684\u540d\u5b57\u5927\u81f4\u53ef\u4ee5\u731c\u51fa\u6240\u9650\u5236\u7684\u8d44\u6e90\u79cd\u7c7b\u3002\u7531\u4e8e\u8be5\u76ee\u5f55\u4e0b\u6d89\u53ca\u7684\u6587\u4ef6\u4f17\u591a\uff0c\u5728\u6b64\u4e0d\u4e00\u4e00\u4ecb\u7ecd\u3002\u6709\u5174\u8da3\u7684\u8bfb\u8005\u53ef\u6253\u5f00\u5176\u4e2d\u7684\u76f8\u5173\u6587\u4ef6\u67e5\u9605\u8bf4\u660e\u3002<\/p>\n

\u4f7f\u7528ulimit\u9650\u5236shell\u7684\u5185\u5b58\u4f7f\u7528<\/strong><\/span><\/div>\n

\u5728\u8fd9\u4e00\u5c0f\u8282\u91cc\u5411\u8bfb\u8005\u5c55\u793a\u5982\u4f55\u4f7f\u7528-d\uff0c-m \u548c-v \u9009\u9879\u6765\u5bf9shell\u6240\u4f7f\u7528\u7684\u5185\u5b58\u8fdb\u884c\u9650\u5236\u3002\u9996\u5148\u6211\u4eec\u6765\u770b\u4e00\u4e0b\u4e0d\u8bbe\u7f6eulimit\u9650\u5236\u65f6\u8c03\u7528ls\u547d\u4ee4\u7684\u60c5\u51b5\uff1a<\/p>\n

\r\n$ ll shell1 -l\r\n-rw-r--r--. 1 root root 227690 4\u6708  23 09:16 shell1\r\n<\/pre>\n

\u5927\u5bb6\u53ef\u4ee5\u770b\u5230\u6b64\u65f6\u7684 ls \u547d\u4ee4\u8fd0\u884c\u6b63\u5e38\u3002\u4e0b\u9762\u8bbe\u7f6e ulimit\uff1a<\/p>\n

\r\n$ ulimit -d 1000 -m 1000 -v 1000\r\n\u8fd9\u91cc\u518d\u6e29\u4e60\u4e00\u4e0b\u524d\u9762\u7ae0\u8282\u91cc\u4ecb\u7ecd\u8fc7\u7684\u8fd9\u4e09\u4e2a\u9009\u9879\u7684\u542b\u4e49\uff1a\r\n\r\n-d\uff1a\u8bbe\u7f6e\u6570\u636e\u6bb5\u7684\u6700\u5927\u503c\u3002\u5355\u4f4d\uff1aKB\u3002\r\n\r\n-m\uff1a\u8bbe\u7f6e\u53ef\u4ee5\u4f7f\u7528\u7684\u5e38\u9a7b\u5185\u5b58\u7684\u6700\u5927\u503c\u3002\u5355\u4f4d\uff1aKB\u3002\r\n\r\n-v\uff1a\u8bbe\u7f6e\u865a\u62df\u5185\u5b58\u7684\u6700\u5927\u503c\u3002\u5355\u4f4d\uff1aKB\u3002\r\n<\/pre>\n

\u901a\u8fc7\u4e0a\u9762\u7684 ulimit \u8bbe\u7f6e\u6211\u4eec\u5df2\u7ecf\u628a\u5f53\u524d shell \u6240\u80fd\u4f7f\u7528\u7684\u6700\u5927\u5185\u5b58\u9650\u5236\u5728 1000KB \u4ee5\u4e0b\u3002\u63a5\u4e0b\u6765\u6211\u4eec\u770b\u770b\u8fd9\u65f6\u8fd0\u884c ls \u547d\u4ee4\u4f1a\u5f97\u5230\u4ec0\u4e48\u6837\u7684\u7ed3\u679c\uff1a<\/p>\n

\r\n$ ll shell1 -l\r\nSegmentation fault (core dumped)\r\n<\/pre>\n
\u4f7f\u7528ulimit\u9650\u5236\u7a0b\u5e8f\u6240\u80fd\u521b\u5efa\u7684socket\u6570\u91cf<\/strong><\/span><\/div>\n

\u8003\u8651\u4e00\u4e2a\u73b0\u5b9e\u4e2d\u7684\u5b9e\u9645\u9700\u6c42\u3002\u5bf9\u4e8e\u4e00\u4e2a C\/S \u6a21\u578b\u4e2d\u7684 server \u7a0b\u5e8f\u6765\u8bf4\uff0c\u5b83\u4f1a\u4e3a\u591a\u4e2a client \u7a0b\u5e8f\u8bf7\u6c42\u521b\u5efa\u591a\u4e2a socket \u7aef\u53e3\u7ed9\u4e0e\u54cd\u5e94\u3002\u5982\u679c\u6070\u597d\u6709\u5927\u91cf\u7684 client \u540c\u65f6\u5411 server \u53d1\u51fa\u8bf7\u6c42\uff0c\u90a3\u4e48\u6b64\u65f6 server \u5c31\u4f1a\u9700\u8981\u521b\u5efa\u5927\u91cf\u7684 socket\u8fde\u63a5\u3002\u4f46\u662f\u5728 Linux \u4e0b\u4e00\u5207\u8d44\u6e90\u7686\u6587\u4ef6\uff0c\u666e\u901a\u6587\u4ef6\u662f\u6587\u4ef6\uff0c\u78c1\u76d8\u6253\u5370\u673a\u662f\u6587\u4ef6\uff0csocket \u5f53\u7136\u4e5f\u662f\u6587\u4ef6\u3002\u5728 Linux \u4e0b\u521b\u5efa\u4e00\u4e2a\u65b0\u7684socket \u8fde\u63a5\uff0c\u5b9e\u9645\u4e0a\u5c31\u662f\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u3002\u800cLinux\u5bf9\u5355\u8fdb\u7a0b\u80fd\u6253\u5f00\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u662f\u6709\u9650\u5236\u7684\uff0c\u9ed8\u8ba4\u5355\u8fdb\u7a0b\u80fd\u6253\u5f00\u7684\u6700\u5927\u6587\u4ef6\u6570\u91cf\u4e3a1024,\u3002ulimit \u5e76\u6ca1\u6709\u54ea\u4e2a\u9009\u9879\u76f4\u63a5\u8bf4\u662f\u7528\u6765\u9650\u5236socket\u7684\u6570\u91cf\u7684\u3002\u4f46\u662f\uff0c\u6211\u4eec\u6709-n\u8fd9\u4e2a\u9009\u9879\uff0c\u5b83\u662f\u7528\u4e8e\u9650\u5236\u4e00\u4e2a\u8fdb\u7a0b\u6240\u80fd\u6253\u5f00\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u6700\u5927\u503c\u3002\u5982\u4e0b\u6240\u793a\uff08\u67e5\u770b\u67d0\u4e2a\u8fdb\u7a0b\u5f53\u524d\u6253\u5f00\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u4fe1\u606f\uff09\uff1a<\/p>\n

\r\n$ ll \/proc\/36766\/fd\r\n\u603b\u7528\u91cf 0\r\nlr-x------. 1 root root 64 4\u6708  23 09:31 0 -> \/dev\/null\r\nl-wx------. 1 root root 64 4\u6708  23 09:31 1 -> \/mydata\/localhost.localdomain.err\r\nlrwx------. 1 root root 64 4\u6708  23 09:31 10 -> \/mydata\/ib_logfile1\r\nlrwx------. 1 root root 64 4\u6708  23 09:31 11 -> socket:[115703]\r\nlrwx------. 1 root root 64 4\u6708  23 09:31 12 -> \/tmp\/ibLxLFBt (deleted)\r\nl-wx------. 1 root root 64 4\u6708  23 09:31 13 -> \/mydata\/mysql-bin.000001\r\nlrwx------. 1 root root 64 4\u6708  23 09:31 14 -> socket:[115704]\r\nlrwx------. 1 root root 64 4\u6708  23 09:31 15 -> \/mydata\/mysql\/host.MYI\r\n.......................\r\n<\/pre>\n

\u56e0\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528ulimit -n\u6765\u9650\u5236\u4f46\u8fdb\u7a0b\u6240\u80fd\u6253\u5f00\u7684\u6700\u5927\u6587\u4ef6\u63cf\u8ff0\u7b26\u6570\u91cf\uff0c\u9ed8\u8ba4\u5355\u8fdb\u7a0b\u6253\u5f00\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e3a1024\uff0c\u5c31\u662f\u4ee3\u8868\u5355\u4e2a\u8fdb\u7a0b\u53ea\u80fd\u540c\u65f6\u6700\u591a\u53ea\u80fd\u7ef4\u63011024\u751a\u81f3\u66f4\u5c11\uff08\u56e0\u4e3a\u6709\u5176\u5b83\u6587\u4ef6\u7684\u53e5\u67c4\u88ab\u6253\u5f00\uff09\u3002\u5982\u679c\u5f00\u542f4\u4e2a\u8fdb\u7a0b\u7ef4\u6301\u7528\u6237\u94fe\u63a5\uff0c\u90a3\u4e48\u6574\u4e2a\u5e94\u7528\u80fd\u591f\u540c\u65f6\u7ef4\u6301\u7684\u8fde\u63a5\u6570\u4e0d\u4f1a\u8d85\u8fc74*1024\u4e2a\uff0c\u4e5f\u5c31\u662f\u8bf4\u6700\u591a\u53ea\u80fd\u652f\u63014\u00d71024\u4e2a\u7528\u6237\u5728\u7ebf\u3002\u53ef\u4ee5\u589e\u5927\u8fd9\u4e2a\u8bbe\u7f6e\u4ee5\u4fbf\u670d\u52a1\u80fd\u591f\u7ef4\u6301\u66f4\u591a\u7684TCP\u8fde\u63a5\uff0c\u4ece\u800c\u8fbe\u5230\u9650\u5236socket\u521b\u5efa\u7684\u6570\u91cf\u3002<\/p>\n

\u5982\u679c\u5355\u4e2a\u8fdb\u7a0b\u6253\u5f00\u7684\u6587\u4ef6\u53e5\u67c4\u6570\u91cf\u8d85\u8fc7\u4e86\u7cfb\u7edf\u5b9a\u4e49\u7684\u503c\uff0c\u5c31\u4f1a\u63d0\u5230\u201ctoo many files open\u201d\u7684\u9519\u8bef\u63d0\u793a\u3002\u5982\u4f55\u77e5\u9053\u5f53\u524d\u8fdb\u7a0b\u6253\u5f00\u4e86\u591a\u5c11\u4e2a\u6587\u4ef6\u53e5\u67c4\u5462\uff1f\u901a\u8fc7lsof\u547d\u4ee4\u53ef\u4ee5\u5e2e\u4f60\u67e5\u770b\uff1a<\/p>\n

\r\n$ lsof -n |awk '{print $2}'|sort|uniq -c |sort -nr| head -n 2\r\n    126 7015\r\n     93 1831\r\n<\/pre>\n

\u4e0a\u9762\u8bf4\u660e\u4e86\uff0c7015\u8fdb\u7a0b\u6253\u5f00\u4e86126\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7ps\u547d\u4ee4\u770b\u770b7015\u8fd9\u4e2a\u8fdb\u7a0b\u662f\u4ec0\u4e48\u670d\u52a1\uff08\u8fd9\u91cc\u90fd\u662f\u4ee5\u6211\u7684\u4e3e\u4f8b\u8bf4\u660e\u7684\uff0c\u4f60\u5728\u5b9e\u9a8c\u65f6\u8981\u6839\u636e\u81ea\u5df1\u7684\u8fdb\u7a0b\u8fdb\u884c\u67e5\u770b\uff0c\u76f8\u4fe1\u4f60\u6709\u8fd9\u4e2a\u610f\u8bc6\uff09\u3002<\/p>\n

\u4fee\u6539\u5355\u8fdb\u7a0b\u6240\u80fd\u6253\u5f00\u7684\u6700\u5927\u6587\u4ef6\u6570<\/p>\n

1\uff09ulimit -n 102400<\/p>\n

\u8fd9\u53ea\u662f\u5728\u5f53\u524d\u7ec8\u7aef\u6709\u6548\uff0c\u9000\u51fa\u4e4b\u540e\uff0copen files\u53c8\u53d8\u4e3a\u9ed8\u8ba4\u503c\u3002<\/p>\n

2\uff09\u5c06ulimit -n 102400\u5199\u5230\/etc\/profile\u4e2d\uff0c\u8fd9\u6837\u6bcf\u6b21\u767b\u5f55\u7ec8\u7aef\u65f6\uff0c\u90fd\u4f1a\u81ea\u52a8\u6267\u884c\/etc\/profile\u3002<\/p>\n

3\uff09\u4ee4\u4fee\u6539open files\u7684\u6570\u503c\u6c38\u4e45\u751f\u6548\uff0c\u5219\u5fc5\u987b\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\uff1a\/etc\/security\/limits.conf\u5728\u8fd9\u4e2a\u6587\u4ef6\u540e\u52a0\u4e0a\uff1a<\/p>\n

\r\n* soft nofile 1024000\r\n* hard nofile 1024000\r\nroot soft nofile 1024000\r\nroot hard nofile 1024000\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

\u5047\u8bbe\u6709\u8fd9\u6837\u4e00\u79cd\u60c5\u51b5\uff0c\u5f53\u4e00\u53f0 Linux \u4e3b\u673a\u4e0a\u540c\u65f6\u767b\u9646\u4e86 10 \u4e2a\u4eba\uff0c\u5728\u7cfb\u7edf\u8d44\u6e90\u65e0\u9650\u5236\u7684\u60c5\u51b5\u4e0b\uff0c\u8fd9 10 \u4e2a\u7528 […]<\/p>\n","protected":false},"author":1479,"featured_media":104099,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-131202","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/131202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=131202"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/131202\/revisions"}],"predecessor-version":[{"id":133060,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/131202\/revisions\/133060"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/104099"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=131202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=131202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=131202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}