{"id":273,"date":"2025-07-08T11:26:24","date_gmt":"2025-07-08T03:26:24","guid":{"rendered":"https:\/\/blog.hcha.site\/?p=273"},"modified":"2026-03-07T14:11:01","modified_gmt":"2026-03-07T06:11:01","slug":"linux-%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%bd%91%e7%bb%9c%e4%b8%80%e9%94%ae%e8%b0%83%e4%bc%98","status":"publish","type":"post","link":"https:\/\/blog.hcha.site\/?p=273","title":{"rendered":"Linux \u670d\u52a1\u5668\u7f51\u7edc\u4e00\u952e\u8c03\u4f18"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">TL;DR<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>echo -e \"net.core.default_qdisc=fq\\nnet.ipv4.tcp_congestion_control=bbr\" | sudo tee -a \/etc\/sysctl.conf &amp;&amp; echo -e \"* soft nofile 65535\\n* hard nofile 65535\\nroot soft nofile 65535\\nroot hard nofile 65535\" | sudo tee -a \/etc\/security\/limits.conf &amp;&amp; <span style=\"background-color: initial; font-family: inherit; font-size: inherit; text-align: initial; color: initial;\">sysctl -p<\/span><\/code><\/pre>\n\n\n\n<p><strong>\u8bf7\u6ce8\u610f\uff1a<\/strong>\u90e8\u5206\u914d\u7f6e\u9700\u8981\u91cd\u65b0\u542f\u52a8\u670d\u52a1\u6216\u91cd\u65b0\u767b\u5f55\u624d\u80fd\u5e94\u7528\uff0c\u82e5\u8981\u786e\u4fdd\u5b8c\u5168\u5e94\u7528\uff0c<strong>\u91cd\u542f<\/strong>\u662f\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u3002<\/p>\n\n\n\n<p>\u8fd9\u4e00\u8c03\u4f18\u9002\u7528\u4e8e\u9762\u5411\u516c\u5f00\u7f51\u7edc\u73af\u5883\u7684Web\u670d\u52a1\u5668\u3001\u53cd\u5411\u4ee3\u7406\u3001CDN\u8282\u70b9\u7b49\u9700\u8981\u5904\u7406\u5927\u91cf\u5e76\u53d1\u8fde\u63a5\u7684\u5e94\u7528\uff0c\u5bf9\u4e8e\u7eaf\u5185\u7f51\u3001\u4f4e\u5ef6\u8fdf\u3001\u65e0\u4e22\u5305\u73af\u5883\uff0c\u8fd9\u4e9b\u5185\u6838\u914d\u7f6e\u7684\u4f18\u52bf\u5e76\u4e0d\u660e\u663e\u3002<\/p>\n\n\n\n<p>\u672c\u6587\u4e2d\u7684\u547d\u4ee4\u548c\u914d\u7f6e\u6587\u4ef6\u8def\u5f84\u5728\u4e3b\u6d41\u7684Linux\u53d1\u884c\u7248\uff08\u5982 Ubuntu, Debian \u7b49\uff09\u4e0a\u901a\u7528\u3002\u5728\u5176\u4ed6\u7cfb\u7edf\u4e0a\uff0c\u8def\u5f84\u53ef\u80fd\u7565\u6709\u5dee\u5f02\uff0c\u4f46\u4f18\u5316\u539f\u7406\u662f\u76f8\u540c\u7684\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u547d\u4ee4\u89e3\u6790<\/h2>\n\n\n\n<p>\u8fd9\u662f\u4e00\u4e2a\u7531\u4e09\u4e2a<code>&amp;&amp;<\/code>\u7ec4\u6210\u7684\u547d\u4ee4\uff0c\u53ea\u6709\u4e0a\u4e00\u4e2a\u547d\u4ee4\u6b63\u786e\u6267\u884c\uff0c\u4e0b\u4e00\u4e2a\u547d\u4ee4\u624d\u4f1a\u6267\u884c\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u914d\u7f6e\u7f51\u7edc\u5185\u6838\u53c2\u6570<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>echo -e \"net.core.default_qdisc=fq\\nnet.ipv4.tcp_congestion_control=bbr\" | sudo tee -a \/etc\/sysctl.conf<\/code><\/pre>\n\n\n\n<p>\u4f7f\u7528root\u6743\u9650\u5411<code>\/etc\/sysctl.conf<\/code>\u5199\u5165\u4ee5\u4e0b\u914d\u7f6e\u5185\u5bb9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>net.core.default_qdisc=fq<\/code>\uff0c\u6307\u793a\u5185\u6838\u542f\u7528fq (Fair Queue)\u7f51\u7edc\u961f\u5217\u7b97\u6cd5\uff0c\u5b83\u80fd\u66f4\u516c\u5e73\u5730\u5904\u7406\u6570\u636e\u5305\uff0c\u964d\u4f4e\u6392\u961f\u5ef6\u8fdf\u3002<\/li>\n\n\n\n<li><code>net.ipv4.tcp_congestion_control=bbr<\/code>\uff0c\u6307\u793a\u5185\u6838\u542f\u7528bbr (Bottleneck Bandwidth and Round-trip propagation time)TCP\u62e5\u585e\u63a7\u5236\u7b97\u6cd5\uff0c<code>BBR<\/code>\u662fGoogle\u5f00\u53d1\u7684\u4e00\u79cd\u7b97\u6cd5\uff0c\u5b83\u4e0d\u4f9d\u8d56\u4e22\u5305\u6765\u5224\u65ad\u7f51\u7edc\u62e5\u585e\uff0c\u800c\u662f\u901a\u8fc7\u6d4b\u91cf\u7f51\u7edc\u7684\u5e26\u5bbd\u548c\u5f80\u8fd4\u5ef6\u8fdf\u6765\u8c03\u8282\u53d1\u9001\u901f\u7387\u3002<\/li>\n<\/ul>\n\n\n\n<p>BBR\u7b97\u6cd5\u9700\u8981Linux\u5185\u6838\u7248\u672c\u81f3\u5c11\u4e3a4.9\u6216\u66f4\u9ad8\uff0c\u53ef\u4ee5\u901a\u8fc7\u6267\u884c<code>uname -r<\/code>\u68c0\u67e5\u5185\u6838\u7248\u672c\u3002<\/p>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>\u63d0\u9ad8\u6587\u4ef6\u53e5\u67c4\u6570\u9650\u5236<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>echo -e \"* soft nofile 65535\\n* hard nofile 65535\\nroot soft nofile 65535\\nroot hard nofile 65535\" | sudo tee -a \/etc\/security\/limits.conf<\/code><\/pre>\n\n\n\n<p>\u4f7f\u7528root\u6743\u9650\u5411<code>\/etc\/security\/limits.conf<\/code>\u5199\u5165\u4ee5\u4e0b\u914d\u7f6e\u5185\u5bb9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>* soft nofile 65535<\/code>\uff0c\u4e3a\u6240\u6709\u7528\u6237(*) \u914d\u7f6e65535\u7684\u6700\u5927\u6587\u4ef6\u53e5\u67c4\u6570\u8f6f\u9650\u5236\uff0c\u5373\u6bcf\u4e2a\u8fdb\u7a0b\u80fd\u6253\u5f00\u7684\u6700\u5927\u6587\u4ef6\u53e5\u67c4\u6570\u4e3a65535\u3002<\/li>\n\n\n\n<li><code>* hard nofile 65535<\/code>\uff0c\u4e3a\u6240\u6709\u7528\u6237(*) \u914d\u7f6e65535\u7684\u6700\u5927\u6587\u4ef6\u53e5\u67c4\u6570\u786c\u9650\u5236\uff0c\u5bf9\u4e8e\u975eroot\u7528\u6237\uff0c\u53ef\u4ee5\u5728\u786c\u9650\u5236\u8303\u56f4\u5185\u8c03\u8282\u81ea\u5df1\u7684\u8f6f\u9650\u5236\u3002<\/li>\n\n\n\n<li><code>root soft nofile 65535<\/code> \u4e0e <code>root hard nofile 65535<\/code>\uff0c\u51fa\u4e8e\u5b89\u5168\u8003\u8651\uff0c\u7531\u901a\u914d\u7b26<code>*<\/code>\u6216\u7528\u6237\u7ec4<code>@groups<\/code>\u6307\u5b9a\u7684\u8f6f\u786c\u9650\u5236\u4e0d\u4f1a\u5f71\u54cdroot\u7528\u6237\uff0c\u82e5\u8981\u4e3aroot\u7528\u6237\u4e5f\u542f\u7528\u8fd9\u4e00\u9650\u5236\uff0c\u5fc5\u987b\u663e\u5f0f\u5730\u4e3aroot\u7528\u6237\u542f\u7528\u540c\u6837\u7684\u9650\u5236\u503c\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u5728 Linux \u7cfb\u7edf\u4e2d\uff0c\u6bcf\u4e00\u4e2a\u7f51\u7edc\u8fde\u63a5\u5957\u63a5\u5b57\u90fd\u4f1a\u5360\u7528\u4e00\u4e2a\u6587\u4ef6\u53e5\u67c4\u3002\u56e0\u6b64\uff0c\u63d0\u9ad8\u6700\u5927\u6587\u4ef6\u53e5\u67c4\u6570\u7684\u9650\u5236\uff0c\u7b49\u540c\u4e8e\u63d0\u9ad8\u4e86\u670d\u52a1\u5668\u5904\u7406\u5e76\u53d1\u8fde\u63a5\u7684\u80fd\u529b\u3002<\/p>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li>\u7acb\u523b\u5e94\u7528\u7f51\u7edc\u5185\u6838\u53c2\u6570\u6539\u52a8<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code><span style=\"background-color: initial; font-family: inherit; font-size: inherit; text-align: initial; color: initial;\">sysctl -p<\/span><\/code><\/pre>\n\n\n\n<p>\u6307\u793a\u7f51\u7edc\u5185\u6838\u7acb\u523b\u5e94\u7528\u53c2\u6570\u6539\u52a8<\/p>\n\n\n\n<p>\u5bf9\u4e8e\u6587\u4ef6\u53e5\u67c4\u6570\u7684\u8c03\u8282\uff0c\u9700\u8981\u7528\u6237\u91cd\u65b0\u767b\u5f55\u624d\u80fd\u5e94\u7528\uff0c\u5bf9\u4e8e\u4efb\u4f55\u5df2\u7ecf\u542f\u52a8\u7684\u670d\u52a1\u6216\u8005\u7a0b\u5e8f\uff0c\u91cd\u542f\u5b83\u4eec\u5c31\u80fd\u4fee\u6539\uff0c\u4f46\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u4f9d\u7136\u662f\u8fdb\u884c\u4e00\u6b21\u5b8c\u5168\u91cd\u542f\uff1a<code>sudo reboot<\/code>\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6548\u679c\u68c0\u67e5<\/h2>\n\n\n\n<p>\u53ef\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u68c0\u67e5\u662f\u5426\u6b63\u786e\u5e94\u7528\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo sysctl net.ipv4.tcp_congestion_control\nnet.ipv4.tcp_congestion_control = bbr\n$ sudo sysctl net.core.default_qdisc\nnet.core.default_qdisc = fq\n$ ulimit -n\n65535<\/code><\/pre>\n\n\n\n<p>\u82e5\u8f93\u51fa\u662f\u8fd9\u4e00\u503c\uff0c\u8bf4\u660e\u5e94\u7528\u6210\u529f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5173\u4e8e systemd \u670d\u52a1\u7684\u7279\u522b\u8bf4\u660e<\/h2>\n\n\n\n<p>\u5bf9\u4e8e\u7531 <code>systemd<\/code> \u7ba1\u7406\u7684\u7cfb\u7edf\u670d\u52a1\uff08\u5982 Nginx\uff09\uff0c\u76f4\u63a5\u4fee\u6539 <code>\/etc\/security\/limits.conf<\/code> \u53ef\u80fd\u65e0\u6cd5\u751f\u6548\u3002<code>systemd<\/code> \u901a\u8fc7\u81ea\u5df1\u7684\u914d\u7f6e\u6587\u4ef6\u6765\u7ba1\u7406\u670d\u52a1\u7684\u8d44\u6e90\u9650\u5236\u3002<\/p>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539 <code>\/etc\/systemd\/system.conf<\/code> \u548c <code>\/etc\/systemd\/user.conf<\/code> \u6587\u4ef6\u6765\u5168\u5c40\u63d0\u9ad8 <code>systemd<\/code> \u670d\u52a1\u7684\u9650\u5236\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;Manager]\nDefaultLimitNOFILE=65535<\/code><\/pre>\n\n\n\n<p>\u4fee\u6539\u540e\uff0c\u9700\u8981\u6267\u884c <code>sudo systemctl daemon-reexec<\/code> \u5e76\u91cd\u542f\u76f8\u5173\u670d\u52a1\u624d\u80fd\u751f\u6548\u3002<\/p>\n\n\n\n<p>\u66f4\u63a8\u8350\u7684\u505a\u6cd5\u662f\u4e3a\u7279\u5b9a\u7684\u670d\u52a1\u521b\u5efa\u8986\u76d6\u914d\u7f6e\uff0c\u4f8b\u5982\u4e3a Nginx \u670d\u52a1\u63d0\u9ad8\u9650\u5236\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u521b\u5efa\u76ee\u5f55\uff1a<code>sudo mkdir -p \/etc\/systemd\/system\/nginx.service.d\/<\/code><\/li>\n\n\n\n<li>\u521b\u5efa\u914d\u7f6e\u6587\u4ef6\uff1a<code>sudo nano \/etc\/systemd\/system\/nginx.service.d\/override.conf<\/code><\/li>\n\n\n\n<li>\u5199\u5165\u4ee5\u4e0b\u5185\u5bb9<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;Service]\nLimitNOFILE=65535<\/code><\/pre>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li>\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\u5e76\u91cd\u542f\u670d\u52a1\uff1a<code>sudo systemctl daemon-reload &amp;&amp; sudo systemctl restart nginx<\/code><\/li>\n<\/ol>\n\n\n\n<p>\u8fd9\u6837\u53ef\u4ee5\u66f4\u7cbe\u786e\u5730\u63a7\u5236\u6bcf\u4e2a\u670d\u52a1\u7684\u8d44\u6e90\uff0c\u4e5f\u662f\u73b0\u4ee3 Linux \u7cfb\u7edf\u7ba1\u7406\u4e2d\u66f4\u89c4\u8303\u7684\u505a\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>TL;DR \u8bf7\u6ce8\u610f\uff1a\u90e8\u5206\u914d\u7f6e\u9700\u8981\u91cd\u65b0\u542f\u52a8\u670d\u52a1\u6216\u91cd\u65b0\u767b\u5f55\u624d\u80fd\u5e94\u7528\uff0c\u82e5\u8981\u786e\u4fdd\u5b8c\u5168\u5e94\u7528\uff0c\u91cd\u542f\u662f\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u3002 \u8fd9\u4e00\u8c03 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,9],"tags":[10,22,26],"class_list":["post-273","post","type-post","status-publish","format-standard","hentry","category-ubuntu","category-9","tag-ubuntu","tag-22","tag-26"],"_links":{"self":[{"href":"https:\/\/blog.hcha.site\/index.php?rest_route=\/wp\/v2\/posts\/273","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.hcha.site\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hcha.site\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hcha.site\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hcha.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=273"}],"version-history":[{"count":1,"href":"https:\/\/blog.hcha.site\/index.php?rest_route=\/wp\/v2\/posts\/273\/revisions"}],"predecessor-version":[{"id":430,"href":"https:\/\/blog.hcha.site\/index.php?rest_route=\/wp\/v2\/posts\/273\/revisions\/430"}],"wp:attachment":[{"href":"https:\/\/blog.hcha.site\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=273"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hcha.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=273"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hcha.site\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}