{"id":205473,"date":"2025-06-02T18:42:26","date_gmt":"2025-06-02T10:42:26","guid":{"rendered":"https:\/\/server.hk\/cnblog\/?p=205473"},"modified":"2025-06-02T23:13:19","modified_gmt":"2025-06-02T15:13:19","slug":"%e6%b7%b1%e5%ba%a6%e8%a7%a3%e6%9e%90%ef%bc%9a25%e4%b8%aa%e6%8f%90%e5%8d%87linux%e7%b3%bb%e7%bb%9f%e6%80%a7%e8%83%bd%e7%9a%84%e5%ae%9e%e7%94%a8%e8%b0%83%e4%bc%98%e6%8a%80%e5%b7%a7","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/205473\/","title":{"rendered":"\u6df1\u5ea6\u89e3\u6790\uff1a25\u4e2a\u63d0\u5347Linux\u7cfb\u7edf\u6027\u80fd\u7684\u5b9e\u7528\u8c03\u4f18\u6280\u5de7"},"content":{"rendered":"<h2>\u524d\u8a00<\/h2>\n<p>\u5728\u5f53\u4eca\u6570\u5b57\u5316\u65f6\u4ee3\uff0c\u670d\u52a1\u5668\u6027\u80fd\u5bf9\u4e1a\u52a1\u7cfb\u7edf\u7684\u7a33\u5b9a\u6027\u4e0e\u54cd\u5e94\u901f\u5ea6\u81f3\u5173\u91cd\u8981\u3002\u7279\u522b\u662f\u5728\u90e8\u7f72\u9ad8\u6027\u80fd\u5e94\u7528\u65f6\uff0c\u4f18\u5316Linux\u7cfb\u7edf\u7684\u8fd0\u884c\u73af\u5883\u663e\u5f97\u5c24\u4e3a\u5173\u952e\u3002\u672c\u6587\u5c06\u7cfb\u7edf\u68b3\u740625\u4e2a\u9ad8\u6548\u7684Linux\u6027\u80fd\u8c03\u4f18\u6280\u5de7\uff0c\u6db5\u76d6\u5185\u6838\u53c2\u6570\u4f18\u5316\u3001I\/O\u8c03\u6574\u3001\u5185\u5b58\u914d\u7f6e\u7b49\u65b9\u9762\uff0c\u5e2e\u52a9\u6280\u672f\u4eba\u5458\u5728\u7ba1\u7406 <strong>\u9999\u6e2f\u4e91\u670d\u52a1\u5668<\/strong>\u3001\u00a0<strong>\u9999\u6e2f\u72ec\u7acb\u670d\u52a1\u5668<\/strong> \u65f6\u83b7\u5f97\u66f4\u5f3a\u7684\u6027\u80fd\u652f\u6491\u3002<\/p>\n<h2>\u4e00\u3001\u5185\u5b58\u4e0eSwap\u7a7a\u95f4\u4f18\u5316<\/h2>\n<ol>\n<li><strong>\u8c03\u4f4eswappiness\u53c2\u6570<\/strong><br \/>\n\u964d\u4f4eLinux\u7cfb\u7edf\u5bf9\u4ea4\u6362\u5206\u533a\u7684\u4f9d\u8d56\uff0c\u63d0\u5347\u7269\u7406\u5185\u5b58\u4f7f\u7528\u4f18\u5148\u7ea7\u3002<\/p>\n<pre><code class=\"language-bash\">sysctl vm.swappiness=10\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u8c03\u6574dirty\u7f13\u5b58\u7b56\u7565<\/strong><br \/>\n\u8bbe\u7f6e<code>dirty_ratio<\/code>\u4e0e<code>dirty_background_ratio<\/code>\u53ef\u4ee5\u51cf\u5c11I\/O\u5199\u5165\u538b\u529b\u3002<\/p>\n<pre><code class=\"language-bash\">sysctl vm.dirty_ratio=15\r\nsysctl vm.dirty_background_ratio=5\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u542f\u7528\u5927\u9875\u5185\u5b58HugePages<\/strong><br \/>\n\u5bf9\u6570\u636e\u5e93\u7b49\u5927\u5185\u5b58\u5e94\u7528\u5f00\u542f\u5927\u9875\u673a\u5236\uff0c\u6709\u6548\u51cf\u5c11\u5185\u5b58\u788e\u7247\u3002<\/p>\n<pre><code class=\"language-bash\">echo \"vm.nr_hugepages=256\" &gt;&gt; \/etc\/sysctl.conf\r\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<h2>\u4e8c\u3001\u7cfb\u7edf\u8d44\u6e90\u4e0e\u8c03\u5ea6\u9650\u5236\u4f18\u5316<\/h2>\n<ol start=\"4\">\n<li><strong>\u63d0\u9ad8ulimit\u6587\u4ef6\u53e5\u67c4\u6570<\/strong><br \/>\n\u4fee\u6539 <code>\/etc\/security\/limits.conf<\/code> \u589e\u52a0\u8d44\u6e90\u9650\u5236\uff0c\u907f\u514d\u9ad8\u5e76\u53d1\u65f6\u8d44\u6e90\u8017\u5c3d\u3002<\/p>\n<pre><code class=\"language-conf\">* soft nofile 65535  \r\n* hard nofile 65535\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u4f18\u5316\u8fdb\u7a0b\u8c03\u5ea6\u7b56\u7565<\/strong><br \/>\n\u901a\u8fc7 <code>chrt<\/code> \u4e3a\u6838\u5fc3\u4efb\u52a1\u8bbe\u5b9a\u66f4\u9ad8\u4f18\u5148\u7ea7\uff0c\u63d0\u9ad8\u5173\u952e\u4e1a\u52a1\u54cd\u5e94\u3002<\/p>\n<pre><code class=\"language-bash\">chrt -f 99 &lt;\u8fdb\u7a0bID&gt;\r\n<\/code><\/pre>\n<\/li>\n<li><strong>NUMA\u4eb2\u548c\u6027\u7ba1\u7406<\/strong><br \/>\n\u591a\u6838CPU\u67b6\u6784\u4e2d\uff0c\u5408\u7406\u5206\u914d\u5185\u5b58\u4e0eCPU\u8d44\u6e90\uff0c\u4f18\u5316\u672c\u5730\u8bbf\u95ee\u901f\u5ea6\u3002<\/p>\n<pre><code class=\"language-bash\">numactl --interleave=all &lt;\u5e94\u7528\u547d\u4ee4&gt;\r\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<h2>\u4e09\u3001I\/O\u4e0e\u6587\u4ef6\u7cfb\u7edf\u8c03\u4f18<\/h2>\n<ol start=\"7\">\n<li><strong>\u8c03\u6574I\/O\u8c03\u5ea6\u7b56\u7565<\/strong><br \/>\n\u6839\u636e\u786c\u76d8\u7c7b\u578b\u9009\u62e9\u8c03\u5ea6\u5668\uff0c\u5982SSD\u5efa\u8bae\u4f7f\u7528noop\u3002<\/p>\n<pre><code class=\"language-bash\">echo noop &gt; \/sys\/block\/sda\/queue\/scheduler\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u6302\u8f7d\u6587\u4ef6\u7cfb\u7edf\u65f6\u4f7f\u7528noatime\u9009\u9879<\/strong><br \/>\n\u907f\u514d\u6bcf\u6b21\u8bfb\u53d6\u66f4\u65b0\u8bbf\u95ee\u65f6\u95f4\uff0c\u51cf\u5c11\u78c1\u76d8I\/O\u3002<\/p>\n<pre><code class=\"language-bash\">\/dev\/sda1 \/ ext4 defaults,noatime 0 0\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u91c7\u7528SSD\u66ff\u6362\u4f20\u7edfHDD<\/strong><br \/>\n\u5728\u9ad8I\/O\u5e94\u7528\u4e2d\u5f15\u5165SSD\uff0c\u53ef\u4ee5\u663e\u8457\u63d0\u5347\u78c1\u76d8\u541e\u5410\u6027\u80fd\u3002<\/li>\n<\/ol>\n<h2>\u56db\u3001\u7f51\u7edc\u6027\u80fd\u4f18\u5316<\/h2>\n<ol start=\"10\">\n<li><strong>\u6269\u5927TCP\u8fde\u63a5\u961f\u5217\u957f\u5ea6<\/strong><br \/>\n\u589e\u52a0<code>somanxconn<\/code>\u503c\uff0c\u6709\u52a9\u4e8e\u5e94\u5bf9\u9ad8\u5e76\u53d1\u7f51\u7edc\u8bf7\u6c42\u3002<\/p>\n<pre><code class=\"language-bash\">sysctl -w net.core.somaxconn=1024\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u5f00\u542fTCP\u8fde\u63a5\u91cd\u7528\u4e0e\u5feb\u901f\u56de\u6536<\/strong><br \/>\n\u964d\u4f4eTIME_WAIT\u5806\u79ef\uff0c\u9002\u7528\u4e8e\u77ed\u8fde\u63a5\u73af\u5883\u3002<\/p>\n<pre><code class=\"language-bash\">sysctl -w net.ipv4.tcp_tw_reuse=1  \r\nsysctl -w net.ipv4.tcp_tw_recycle=1\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u4f18\u5316TCP\u7a97\u53e3\u5927\u5c0f\u4e0e\u7f13\u51b2\u533a<\/strong><br \/>\n\u63d0\u5347\u9ad8\u5ef6\u8fdf\u7f51\u7edc\u4f20\u8f93\u6548\u7387\u3002<\/p>\n<pre><code class=\"language-bash\">sysctl -w net.core.rmem_max=16777216  \r\nsysctl -w net.core.wmem_max=16777216\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u8c03\u6574TCP\u8fde\u63a5\u8d85\u65f6\u53c2\u6570<\/strong><br \/>\n\u964d\u4f4etcp_fin_timeout\u65f6\u95f4\uff0c\u52a0\u5feb\u8fde\u63a5\u91ca\u653e\u3002<\/p>\n<pre><code class=\"language-bash\">sysctl -w net.ipv4.tcp_fin_timeout=15\r\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<h2>\u4e94\u3001\u76d1\u63a7\u4e0e\u670d\u52a1\u7ba1\u7406\u5de5\u5177\u63a8\u8350<\/h2>\n<ol start=\"14\">\n<li><strong>\u4f7f\u7528top\u3001htop\u5b9e\u65f6\u76d1\u63a7\u7cfb\u7edf\u8d44\u6e90<\/strong><br \/>\n\u5feb\u901f\u53d1\u73b0CPU\u3001\u5185\u5b58\u74f6\u9888\uff0c\u662f\u7cfb\u7edf\u8c03\u4f18\u7684\u7b2c\u4e00\u6b65\u3002<\/li>\n<li><strong>vmstat\u4e0eiostat\u89c2\u5bdf\u5185\u5b58\u4e0e\u78c1\u76d8\u8d1f\u8f7d<\/strong><br \/>\n\u957f\u671f\u8fd0\u884c\u8fd9\u4e9b\u547d\u4ee4\u53ef\u4ee5\u5e2e\u52a9\u79ef\u7d2f\u7cfb\u7edf\u72b6\u6001\u6570\u636e\u3002<\/p>\n<pre><code class=\"language-bash\">vmstat 1  \r\niostat -x 1\r\n<\/code><\/pre>\n<\/li>\n<li><strong>perf\u5206\u6790\u6027\u80fd\u74f6\u9888<\/strong><br \/>\n\u6df1\u5165\u5206\u6790\u7a0b\u5e8f\u5c42\u9762\u7684\u6027\u80fd\u95ee\u9898\uff0c\u5b9a\u4f4d\u9ad8CPU\u4f7f\u7528\u70b9\u3002<\/p>\n<pre><code class=\"language-bash\">perf top\r\n<\/code><\/pre>\n<\/li>\n<li><strong>systemd-analyze\u67e5\u770b\u542f\u52a8\u74f6\u9888<\/strong><br \/>\n\u7981\u7528\u975e\u5fc5\u8981\u7684\u5f00\u673a\u670d\u52a1\uff0c\u63d0\u9ad8\u542f\u52a8\u6548\u7387\u3002<\/p>\n<pre><code class=\"language-bash\">systemd-analyze blame\r\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<h2>\u516d\u3001\u670d\u52a1\u4e0e\u5185\u6838\u6a21\u5757\u7ba1\u7406<\/h2>\n<ol start=\"18\">\n<li><strong>\u5173\u95ed\u4e0d\u5fc5\u8981\u670d\u52a1<\/strong><br \/>\n\u4f7f\u7528systemctl\u6216chkconfig\u7981\u7528\u65e0\u5173\u670d\u52a1\uff0c\u91ca\u653e\u7cfb\u7edf\u8d44\u6e90\u3002<\/li>\n<li><strong>\u79fb\u9664\u65e0\u7528\u5185\u6838\u6a21\u5757<\/strong><br \/>\n\u7cbe\u7b80\u6a21\u5757\u52a0\u8f7d\uff0c\u907f\u514d\u5b89\u5168\u4e0e\u6027\u80fd\u98ce\u9669\u3002<\/p>\n<pre><code class=\"language-bash\">lsmod  \r\nmodprobe -r &lt;\u6a21\u5757\u540d&gt;\r\n<\/code><\/pre>\n<\/li>\n<li><strong>nscd\u52a0\u901fDNS\u89e3\u6790<\/strong><br \/>\n\u5b89\u88c5nscd\u63d0\u5347\u57df\u540d\u67e5\u8be2\u54cd\u5e94\u901f\u5ea6\u3002<\/p>\n<pre><code class=\"language-bash\">yum install nscd  \r\nsystemctl start nscd\r\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<h2>\u4e03\u3001\u81ea\u52a8\u5316\u4f18\u5316\u4e0e\u6027\u80fd\u65b9\u6848<\/h2>\n<ol start=\"21\">\n<li><strong>\u4f7f\u7528tuned\u81ea\u9002\u5e94\u4f18\u5316\u914d\u7f6e<\/strong><br \/>\ntuned\u53ef\u6839\u636e\u670d\u52a1\u5668\u7528\u9014\u81ea\u52a8\u5e94\u7528\u5408\u9002\u7684\u6027\u80fd\u7b56\u7565\u3002<\/p>\n<pre><code class=\"language-bash\">yum install tuned  \r\ntuned-adm profile throughput-performance\r\n<\/code><\/pre>\n<\/li>\n<li><strong>\u5f00\u542f\u5f02\u6b65I\/O\uff08AIO\uff09<\/strong><br \/>\n\u5bf9\u4e8e\u6570\u636e\u5e93\u7c7b\u5e94\u7528\uff0c\u901a\u8fc7AIO\u63d0\u5347I\/O\u5e76\u53d1\u80fd\u529b\u3002<\/li>\n<li><strong>\u542f\u7528\u900f\u660e\u5927\u9875\u673a\u5236\uff08THP\uff09<\/strong><br \/>\n\u7279\u522b\u9002\u5408\u5927\u5185\u5b58\u9700\u6c42\u7684\u865a\u62df\u5316\u4e0e\u6570\u636e\u5bc6\u96c6\u578b\u573a\u666f\u3002<\/li>\n<li><strong>\u8c03\u6574\u7f51\u7edc\u6808\u9ed8\u8ba4\u7f13\u51b2\u914d\u7f6e<\/strong><br \/>\n\u63d0\u5347socket\u6570\u636e\u4f20\u8f93\u6548\u7387\uff0c\u4f18\u5316\u7cfb\u7edf\u7ea7\u901a\u8baf\u6027\u80fd\u3002<\/li>\n<li><strong>\u7ed3\u5408\u4e13\u4e1a\u670d\u52a1\u5668\u914d\u7f6e\u90e8\u7f72\u8c03\u4f18\u65b9\u6848<\/strong><br \/>\n\u4f7f\u7528\u9ad8\u914d\u7f6e\u7684\u9999\u6e2f\u670d\u52a1\u5668\u4ea7\u54c1\uff0c\u53ef\u4ee5\u4ece\u786c\u4ef6\u5c42\u9762\u63d0\u5347\u7cfb\u7edf\u6574\u4f53\u6027\u80fd\u7a33\u5b9a\u6027\u3002<\/li>\n<\/ol>\n<hr \/>\n<h2>\u7ed3\u8bed<\/h2>\n<p>\u901a\u8fc7\u4ee5\u4e0a25\u4e2a\u5c42\u6b21\u5206\u660e\u7684\u8c03\u4f18\u5efa\u8bae\uff0c\u8fd0\u7ef4\u4eba\u5458\u548c\u5f00\u53d1\u56e2\u961f\u53ef\u4ee5\u6839\u636e\u4e1a\u52a1\u573a\u666f\u7075\u6d3b\u9009\u62e9\u4f18\u5316\u63aa\u65bd\uff0c\u786e\u4fddLinux\u7cfb\u7edf\u5728\u9ad8\u8d1f\u8f7d\u4e0b\u4ecd\u80fd\u7a33\u5b9a\u9ad8\u6548\u8fd0\u884c\u3002\u7279\u522b\u662f\u5728\u9009\u62e9<a href=\"https:\/\/server.hk\/\"><strong>\u9999\u6e2fvps<\/strong><\/a>\u6216<strong>\u9999\u6e2f\u72ec\u7acb\u670d\u52a1\u5668<\/strong>\u65f6\uff0c\u642d\u914d\u8fd9\u4e9b\u6280\u5de7\uff0c\u5c06\u6781\u5927\u63d0\u5347\u5e94\u7528\u7684\u5904\u7406\u80fd\u529b\u4e0e\u7528\u6237\u4f53\u9a8c\u3002\u90e8\u7f72\u524d\u6cbf\u4e1a\u52a1\u5e94\u7528\uff0c\u9009\u62e9\u9ad8\u6027\u80fd\u3001\u7a33\u5b9a\u7684<strong>\u9999\u6e2f\u4e91\u670d\u52a1\u5668<\/strong>\u662f\u5173\u952e\u4e00\u6b65\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u5728\u5f53\u4eca\u6570\u5b57\u5316\u65f6\u4ee3\uff0c\u670d\u52a1\u5668\u6027&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-205473","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=205473"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205473\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=205473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=205473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=205473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}