{"id":176111,"date":"2020-04-19T09:39:13","date_gmt":"2020-04-19T01:39:13","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=176111"},"modified":"2020-04-07T09:41:32","modified_gmt":"2020-04-07T01:41:32","slug":"linux-parameter-optimization","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-parameter-optimization.html","title":{"rendered":"Linux\u7cfb\u7edf\u9ad8\u5e76\u53d1\u4e0b\u7684\u53c2\u6570\u4f18\u5316"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u4f17\u6240\u5468\u77e5\u5728\u9ed8\u8ba4\u53c2\u6570\u60c5\u51b5\u4e0bLinux\u5bf9\u9ad8\u5e76\u53d1\u652f\u6301\u5e76\u4e0d\u597d\uff0c\u4e3b\u8981\u53d7\u9650\u4e8e\u5355\u8fdb\u7a0b\u6700\u5927\u6253\u5f00\u6587\u4ef6\u6570\u9650\u5236\u3001\u5185\u6838TCP\u53c2\u6570\u65b9\u9762\u548cIO\u4e8b\u4ef6\u5206\u914d\u673a\u5236\u7b49\u3002\u4e0b\u9762\u5c31\u4ece\u51e0\u65b9\u9762\u6765\u8c03\u6574\u4f7fLinux\u7cfb\u7edf\u80fd\u591f\u652f\u6301\u9ad8\u5e76\u53d1\u73af\u5883\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

Iptables\u76f8\u5173<\/strong><\/div>\n

\u5982\u975e\u5fc5\u987b\uff0c\u5173\u6389\u6216\u5378\u8f7diptables\u9632\u706b\u5899\uff0c\u5e76\u963b\u6b62kernel\u52a0\u8f7diptables\u6a21\u5757\u3002\u8fd9\u4e9b\u6a21\u5757\u4f1a\u5f71\u54cd\u5e76\u53d1\u6027\u80fd\u3002<\/p>\n

\u5355\u8fdb\u7a0b\u6700\u5927\u6253\u5f00\u6587\u4ef6\u6570\u9650\u5236<\/strong><\/div>\n

\u4e00\u822c\u7684\u53d1\u884c\u7248\uff0c\u9650\u5236\u5355\u8fdb\u7a0b\u6700\u5927\u53ef\u4ee5\u6253\u5f001024\u4e2a\u6587\u4ef6\uff0c\u8fd9\u662f\u8fdc\u8fdc\u4e0d\u80fd\u6ee1\u8db3\u9ad8\u5e76\u53d1\u9700\u6c42\u7684\uff0c\u8c03\u6574\u8fc7\u7a0b\u5982\u4e0b\uff1a<\/p>\n

\u5728#\u53f7\u63d0\u793a\u7b26\u4e0b\u6572\u5165\uff1a<\/p>\n

# ulimit -n 65535<\/pre>\n

\u5c06root\u542f\u52a8\u7684\u5355\u4e00\u8fdb\u7a0b\u7684\u6700\u5927\u53ef\u4ee5\u6253\u5f00\u7684\u6587\u4ef6\u6570\u8bbe\u7f6e\u4e3a65535\u4e2a\u3002\u5982\u679c\u7cfb\u7edf\u56de\u663e\u7c7b\u4f3c\u4e8e\u201cOperationnotpermitted\u201d\u4e4b\u7c7b\u7684\u8bdd\uff0c\u8bf4\u660e\u4e0a\u8ff0\u9650\u5236\u4fee\u6539\u5931\u8d25\uff0c\u5b9e\u9645\u4e0a\u662f\u56e0\u4e3a\u5728\u4e2d\u6307\u5b9a\u7684\u6570\u503c\u8d85\u8fc7\u4e86Linux\u7cfb\u7edf\u5bf9\u8be5\u7528\u6237\u6253\u5f00\u6587\u4ef6\u6570\u7684\u8f6f\u9650\u5236\u6216\u786c\u9650\u5236\u3002\u56e0\u6b64\uff0c\u5c31\u9700\u8981\u4fee\u6539Linux\u7cfb\u7edf\u5bf9\u7528\u6237\u7684\u5173\u4e8e\u6253\u5f00\u6587\u4ef6\u6570\u7684\u8f6f\u9650\u5236\u548c\u786c\u9650\u5236\u3002<\/p>\n

\u7b2c\u4e00\u6b65\uff0c\u4fee\u6539limits.conf\u6587\u4ef6\uff0c\u5e76\u6dfb\u52a0\uff1a<\/p>\n

# vim \/etc\/security\/limits.conf \r\n \r\n* soft nofile 65536 \r\n \r\n* hard nofile 65536 \r\n<\/pre>\n

\u5176\u4e2d'*'\u53f7\u8868\u793a\u4fee\u6539\u6240\u6709\u7528\u6237\u7684\u9650\u5236;soft\u6216hard\u6307\u5b9a\u8981\u4fee\u6539\u8f6f\u9650\u5236\u8fd8\u662f\u786c\u9650\u5236;65536\u5219\u6307\u5b9a\u4e86\u60f3\u8981\u4fee\u6539\u7684\u65b0\u7684\u9650\u5236\u503c\uff0c\u5373\u6700\u5927\u6253\u5f00\u6587\u4ef6\u6570(\u8bf7\u6ce8\u610f\u8f6f\u9650\u5236\u503c\u8981\u5c0f\u4e8e\u6216\u7b49\u4e8e\u786c\u9650\u5236)\u3002\u4fee\u6539\u5b8c\u540e\u4fdd\u5b58\u6587\u4ef6\u3002<\/p>\n

\u7b2c\u4e8c\u6b65\uff0c\u4fee\u6539\/etc\/pam.d\/login\u6587\u4ef6\uff0c\u5728\u6587\u4ef6\u4e2d\u6dfb\u52a0\u5982\u4e0b\u884c\uff1a<\/p>\n

# vim \/etc\/pam.d\/login \r\n<\/pre>\n

sessionrequired \/lib\/security\/pam_limits.so
\n\u8fd9\u662f\u544a\u8bc9Linux\u5728\u7528\u6237\u5b8c\u6210\u7cfb\u7edf\u767b\u5f55\u540e\uff0c\u5e94\u8be5\u8c03\u7528pam_limits.so\u6a21\u5757\u6765\u8bbe\u7f6e\u7cfb\u7edf\u5bf9\u8be5\u7528\u6237\u53ef\u4f7f\u7528\u7684\u5404\u79cd\u8d44\u6e90\u6570\u91cf\u7684\u6700\u5927\u9650\u5236(\u5305\u62ec\u7528\u6237\u53ef\u6253\u5f00\u7684\u6700\u5927\u6587\u4ef6\u6570\u9650\u5236)\uff0c\u800cpam_limits.so\u6a21\u5757\u5c31\u4f1a\u4ece\/etc\/security\/limits.conf\u6587\u4ef6\u4e2d\u8bfb\u53d6\u914d\u7f6e\u6765\u8bbe\u7f6e\u8fd9\u4e9b\u9650\u5236\u503c\u3002\u4fee\u6539\u5b8c\u540e\u4fdd\u5b58\u6b64\u6587\u4ef6\u3002<\/p>\n

\u7b2c\u4e09\u6b65\uff0c\u67e5\u770bLinux\u7cfb\u7edf\u7ea7\u7684\u6700\u5927\u6253\u5f00\u6587\u4ef6\u6570\u9650\u5236\uff0c\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n

# cat\/proc\/sys\/fs\/file-max \r\n \r\n32568\r\n<\/pre>\n

\u8fd9\u8868\u660e\u8fd9\u53f0Linux\u7cfb\u7edf\u6700\u591a\u5141\u8bb8\u540c\u65f6\u6253\u5f00(\u5373\u5305\u542b\u6240\u6709\u7528\u6237\u6253\u5f00\u6587\u4ef6\u6570\u603b\u548c)32568\u4e2a\u6587\u4ef6\uff0c\u662fLinux\u7cfb\u7edf\u7ea7\u786c\u9650\u5236\uff0c\u6240\u6709\u7528\u6237\u7ea7\u7684\u6253\u5f00\u6587\u4ef6\u6570\u9650\u5236\u90fd\u4e0d\u5e94\u8d85\u8fc7\u8fd9\u4e2a\u6570\u503c\u3002\u901a\u5e38\u8fd9\u4e2a\u7cfb\u7edf\u7ea7\u786c\u9650\u5236\u662fLinux\u7cfb\u7edf\u5728\u542f\u52a8\u65f6\u6839\u636e\u7cfb\u7edf\u786c\u4ef6\u8d44\u6e90\u72b6\u51b5\u8ba1\u7b97\u51fa\u6765\u7684\u4f18\u79c0\u7684\u6700\u5927\u540c\u65f6\u6253\u5f00\u6587\u4ef6\u6570\u9650\u5236\uff0c\u5982\u679c\u6ca1\u6709\u7279\u6b8a\u9700\u8981\uff0c\u4e0d\u5e94\u8be5\u4fee\u6539\u6b64\u9650\u5236\uff0c\u9664\u975e\u60f3\u4e3a\u7528\u6237\u7ea7\u6253\u5f00\u6587\u4ef6\u6570\u9650\u5236\u8bbe\u7f6e\u8d85\u8fc7\u6b64\u9650\u5236\u7684\u503c\u3002\u4fee\u6539\u6b64\u786c\u9650\u5236\u7684\u65b9\u6cd5\u662f\u4fee\u6539\/etc\/sysctl.conf\u6587\u4ef6\u5185fs.file-max= 131072<\/p>\n

\u8fd9\u662f\u8ba9Linux\u5728\u542f\u52a8\u5b8c\u6210\u540e\u5f3a\u884c\u5c06\u7cfb\u7edf\u7ea7\u6253\u5f00\u6587\u4ef6\u6570\u786c\u9650\u5236\u8bbe\u7f6e\u4e3a131072\u3002\u4fee\u6539\u5b8c\u540e\u4fdd\u5b58\u6b64\u6587\u4ef6\u3002<\/p>\n

\u5b8c\u6210\u4e0a\u8ff0\u6b65\u9aa4\u540e\u91cd\u542f\u7cfb\u7edf\uff0c\u4e00\u822c\u60c5\u51b5\u4e0b\u5c31\u53ef\u4ee5\u5c06Linux\u7cfb\u7edf\u5bf9\u6307\u5b9a\u7528\u6237\u7684\u5355\u4e00\u8fdb\u7a0b\u5141\u8bb8\u540c\u65f6\u6253\u5f00\u7684\u6700\u5927\u6587\u4ef6\u6570\u9650\u5236\u8bbe\u4e3a\u6307\u5b9a\u7684\u6570\u503c\u3002\u5982\u679c\u91cd\u542f\u540e\u7528ulimit-n\u547d\u4ee4\u67e5\u770b\u7528\u6237\u53ef\u6253\u5f00\u6587\u4ef6\u6570\u9650\u5236\u4ecd\u7136\u4f4e\u4e8e\u4e0a\u8ff0\u6b65\u9aa4\u4e2d\u8bbe\u7f6e\u7684\u6700\u5927\u503c\uff0c\u8fd9\u53ef\u80fd\u662f\u56e0\u4e3a\u5728\u7528\u6237\u767b\u5f55\u811a\u672c\/etc\/profile\u4e2d\u4f7f\u7528ulimit-n\u547d\u4ee4\u5df2\u7ecf\u5c06\u7528\u6237\u53ef\u540c\u65f6\u6253\u5f00\u7684\u6587\u4ef6\u6570\u505a\u4e86\u9650\u5236\u3002\u7531\u4e8e\u901a\u8fc7ulimit-n\u4fee\u6539\u7cfb\u7edf\u5bf9\u7528\u6237\u53ef\u540c\u65f6\u6253\u5f00\u6587\u4ef6\u7684\u6700\u5927\u6570\u9650\u5236\u65f6\uff0c\u65b0\u4fee\u6539\u7684\u503c\u53ea\u80fd\u5c0f\u4e8e\u6216\u7b49\u4e8e\u4e0a\u6b21ulimit-n\u8bbe\u7f6e\u7684\u503c\uff0c\u56e0\u6b64\u60f3\u7528\u6b64\u547d\u4ee4\u589e\u5927\u8fd9\u4e2a\u9650\u5236\u503c\u662f\u4e0d\u53ef\u80fd\u7684\u3002\u6240\u4ee5\uff0c\u5982\u679c\u6709\u4e0a\u8ff0\u95ee\u9898\u5b58\u5728\uff0c\u5c31\u53ea\u80fd\u53bb\u6253\u5f00\/etc\/profile\u811a\u672c\u6587\u4ef6\uff0c\u5728\u6587\u4ef6\u4e2d\u67e5\u627e\u662f\u5426\u4f7f\u7528\u4e86ulimit-n\u9650\u5236\u4e86\u7528\u6237\u53ef\u540c\u65f6\u6253\u5f00\u7684\u6700\u5927\u6587\u4ef6\u6570\u91cf\uff0c\u5982\u679c\u627e\u5230\uff0c\u5219\u5220\u9664\u8fd9\u884c\u547d\u4ee4\uff0c\u6216\u8005\u5c06\u5176\u8bbe\u7f6e\u7684\u503c\u6539\u4e3a\u5408\u9002\u7684\u503c\uff0c\u7136\u540e\u4fdd\u5b58\u6587\u4ef6\uff0c\u7528\u6237\u9000\u51fa\u5e76\u91cd\u65b0\u767b\u5f55\u7cfb\u7edf\u5373\u53ef\u3002<\/p>\n

\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u5c31\u4e3a\u652f\u6301\u9ad8\u5e76\u53d1TCP\u8fde\u63a5\u5904\u7406\u7684\u901a\u8baf\u5904\u7406\u7a0b\u5e8f\u89e3\u9664\u5173\u4e8e\u6253\u5f00\u6587\u4ef6\u6570\u91cf\u65b9\u9762\u7684\u7cfb\u7edf\u9650\u5236\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5982\u975e\u5fc5\u987b\uff0c\u5173\u6389\u6216\u5378\u8f7diptables\u9632\u706b\u5899\uff0c\u5e76\u963b\u6b62kernel\u52a0\u8f7diptables\u6a21\u5757\u3002\u8fd9\u4e9b\u6a21\u5757\u4f1a\u5f71\u54cd\u5e76\u53d1\u6027\u80fd […]<\/p>\n","protected":false},"author":1329,"featured_media":176147,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-176111","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\/176111","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\/1329"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=176111"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/176111\/revisions"}],"predecessor-version":[{"id":176148,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/176111\/revisions\/176148"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/176147"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=176111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=176111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=176111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}