{"id":224835,"date":"2020-12-17T12:15:21","date_gmt":"2020-12-17T04:15:21","guid":{"rendered":"http:\/\/4563.org\/?p=224835"},"modified":"2020-12-17T12:15:21","modified_gmt":"2020-12-17T04:15:21","slug":"vir%e5%ae%b6%e6%80%8e%e4%b9%88%e9%99%90%e5%88%b6cpu-%e5%8a%a8%e4%b8%8d%e5%8a%a8%e5%b0%b1%e5%85%b3%e6%9c%ba%e4%ba%86-%e6%9c%89%e4%bb%80%e4%b9%88%e6%96%b9%e6%b3%95%e8%83%bd%e9%99%90%e5%88%b6%e4%b8%8b","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=224835","title":{"rendered":"VIR\u5bb6\u600e\u4e48\u9650\u5236CPU \u52a8\u4e0d\u52a8\u5c31\u5173\u673a\u4e86 \u6709\u4ec0\u4e48\u65b9\u6cd5\u80fd\u9650\u5236\u4e0b\u5417"},"content":{"rendered":"\n<p>  \t\t\t\t\t<strong>ncnc<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3>VIR\u5bb6\u600e\u4e48\u9650\u5236CPU \u52a8\u4e0d\u52a8\u5c31\u5173\u673a\u4e86 \u6709\u4ec0\u4e48\u65b9\u6cd5\u80fd\u9650\u5236\u4e0b\u5417<\/h3>\n<p>  \t\t \u672c\u5e16\u6700\u540e\u7531 ncnc \u4e8e 2020-12-17 10:36 \u7f16\u8f91 <\/p>\n<p> VIR\u5bb6\u600e\u4e48\u9650\u5236CPU \u52a8\u4e0d\u52a8\u5c31\u5173\u673a\u4e86 \u6709\u4ec0\u4e48\u65b9\u6cd5\u80fd\u9650\u5236\u4e0b\u5417<\/p>\n<p>  \u5b89\u88c5\u4e2aBT\u5173\u673a \u5b89\u88c5\u4e0b\u73af\u5883\u53c8\u5173\u673a \u8fc1\u79fb\u4e0b\u6570\u636e\u53c8\u5173\u673a :Q <\/p>\n<p>  \u6709\u6ca1\u6709\u65b9\u6cd5\u80fd\u9650\u5236\u4e0bCPU <\/p>\n<p>  Linux VPS\u901a\u8fc7\u5b89\u88c5CPULimit\u6765\u9650\u5236CPU\u4f7f\u7528\u7387<\/p>\n<p>  cpulimit\u547d\u4ee4\u7684\u5de5\u4f5c\u539f\u7406\u662f\u4e3a\u8fdb\u7a0b\u9884\u8bbe\u4e00\u4e2acpu\u5360\u7528\u7387\u4e0a\u9650\uff0c\u5e76\u5b9e\u65f6\u76d1\u63a7\u8fdb\u7a0b\u662f\u5426\u8d85\u51fa\u6b64\u4e0a\u9650\uff0c\u800c\u505a\u51fa\u52a8\u6001\u8c03\u6574\u3002\u4ece\u800c\u53ef\u4ee5\u63a7\u5236\u8fdb\u7a0b\u7684cpu\u4f7f\u7528\u7387\u7684\u4e0a\u9650\u503c\u3002<\/p>\n<p>  \u5b89\u88c5<\/p>\n<p>  \u4f7f\u7528root\u8fd0\u884c\u547d\u4ee4\uff1a<\/p>\n<p>  #debian\/ubuntu\u7cfb\u7edf<br \/>  apt install -y cpulimit<\/p>\n<p>  #RHEL\/Centos\/Fedora\u7cfb\u7edf<br \/>  yum install epel-release cpulimit<\/p>\n<p>  \u7528\u6cd5<\/p>\n<p>  1\u3001\u5e38\u89c4\u7528\u6cd5<\/p>\n<p>  #\u9650\u5236firefox\u4f7f\u752830% cpu\u5229\u7528\u7387<br \/>  cpulimit -e firefox -l 30<\/p>\n<p>  #\u9650\u5236\u8fdb\u7a0b\u53f71313\u7684\u7a0b\u5e8f\u4f7f\u752830%cpu\u5229\u7528\u7387<br \/>  cpulimit -p 1313 -l 30<\/p>\n<p>  #\u9650\u5236\u7edd\u5bf9\u8def\u5f84\u4e0b\u8be5\u8f6f\u4ef6\u7684cpu\u5229\u7528\u7387<br \/>  cpulimit -e \/usr\/local\/nginx\/sbin\/nginx -l 50<\/p>\n<p>  2\u3001\u9650\u5236\u6240\u6709\u8fdb\u7a0b\u7684CPU\u4f7f\u7528\u7387<br \/>  \u9ed8\u8ba4\u60c5\u51b5\u4e0bcpulimit\u53ea\u80fd\u5bf9\u5df2\u7ecf\u5b58\u5728\u7684\u8fdb\u7a0b\u8fdb\u884c\u9650\u5236\uff0c\u4f46\u662f\u8bbe\u7f6e\u6b64\u811a\u672c\u4e3a\u968f\u673a\u81ea\u542f\u52a8\u5373\u53ef\uff0c\u5b83\u4f1a\u5bf9\u6240\u6709\u8fdb\u7a0b\uff08\u5305\u62ec\u65b0\u5efa\u8fdb\u7a0b\uff09\u8fdb\u884c\u76d1\u63a7\u5e76\u9650\u5236\uff083\u79d2\u68c0\u6d4b\u4e00\u6b21\uff0cCPU\u9650\u5236\u4e3a75\uff05\uff09<\/p>\n<p>  \u8fd9\u5c31\u53ef\u4ee5\u9632\u6b62\u56e0\u4e3aCPU\u4f7f\u7528\u7387\u8fc7\u9ad8\u800c\u88abban\u4e86\uff01<\/p>\n<p>  #!\/bin\/bash <\/p>\n<p>  while true ; do<\/p>\n<p>  id=`ps -ef | grep cpulimit | grep -v &quot;grep&quot; | awk &#8216;{print $10}&#8217; | tail -1`<\/p>\n<p>  nid=`ps aux | awk &#8216;{ if ( $3 &gt; 75 ) print $2 }&#8217; | head -1`<\/p>\n<p>  if [ &quot;${nid}&quot; != &quot;&quot; ] &amp;&amp; [ &quot;${nid}&quot; != &quot;${id}&quot; ] ; then<\/p>\n<p>  &nbsp; &nbsp; cpulimit -p ${nid} -l 75 &amp;<\/p>\n<p>  &nbsp; &nbsp; echo &quot;[`date`] CpuLimiter run for ${nid} `ps -ef | grep ${nid} | awk &#8216;{print $8}&#8217; | head -1`&quot; &gt;&gt; \/root\/cpulimit-log.log<\/p>\n<p>  fi<\/p>\n<p>  sleep 3<\/p>\n<p>  done<\/p>\n<p>  \u4fdd\u5b58\u5230 \/root\/cpulimit.sh\uff0c\u4f1a\u81ea\u52a8\u751f\u6210\u65e5\u5fd7\u6587\u4ef6 \/root\/cpulimit-log.log\u3002<\/p>\n<p>  \u7136\u540e\u4fee\u6539 \/etc\/rc.local \u5728\u5bf9\u5e94\u4f4d\u7f6e\u52a0\u5165 \/root\/cpulimit.sh \u518d\u91cd\u542f\u7cfb\u7edf\uff0c\u5c31\u4f1a\u5168\u7a0b\u9650\u5236\u5404\u4e2a\u8fdb\u7a0b\u7684CPU\u4f7f\u7528\u4e86\uff01<\/p>\n<p>  \t\t\t\t\t<strong>\u8001\u8d3a023<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t \u672c\u5e16\u6700\u540e\u7531 \u8001\u8d3a023 \u4e8e 2020-12-17 10:56 \u7f16\u8f91 <\/p>\n<p> \u6536\u85cf\u4e86\u3002<\/p>\n<p>  \u987a\u4fbf\u95ee\u4e0b\u697c\u4e3b\uff0c\u4f60\u8fd9\u5e16\u5b50\u80cc\u666f\u662f\u600e\u4e48\u641e\u7684\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>lc_soul<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u5df2\u6536\u85cf \u6709\u7a7a\u8bd5\u8bd5\u770b\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>\u82b1\u6837\u64b8\u7ba1\u51a0\u519b<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u597d\u50cf\u662f\u9650\u5236\u78c1\u76d8io\uff0c\u786e\u5b9a\u662f\u9650\u5236cpu\u5417\uff1f\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>\u4f3c\u6bdb\u975e\u6bdb<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\tvir\u6ca1\u90a3\u4e48\u4e25\u5427\u3002\u7f16\u8bd1\u4e2a50\u5206\u949f\u3002100%\u4e5f\u6ca1\u89c1\u5173\u673a\u554a\u3002\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>ncnc<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u4f3c\u6bdb\u975e\u6bdb \u5927\u4f6c\u6709\u8bdd\u8bf4 : 2020-12-17 10:52<br \/>  vir\u6ca1\u90a3\u4e48\u4e25\u5427\u3002\u7f16\u8bd1\u4e2a50\u5206\u949f\u3002100%\u4e5f\u6ca1\u89c1\u5173\u673a\u554a\u3002<\/p>\n<p> \u4e0d\u6e05\u695a\u4f60\u7684 \u6211\u76841H1.5G\u7684\u5c0f\u9e21 <\/p>\n<p>  \u5b89\u88c5\u4e2aBT\u5173\u673a \u5b89\u88c5\u4e0b\u73af\u5883\u53c8\u5173\u673a \u8fc1\u79fb\u4e0b\u6570\u636e\u53c8\u5173\u673a \u89e3\u538b\u4e0b\u53c8\u5173\u673a :L\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>QEMU<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u4e0d\u540c\u7684\u6bcd\u9e21\u60c5\u51b5\u4e0d\u4e00\u6837\u3002\u6211\u6709\u4e00\u53f0vir \u7a0b\u5e8fbug\u628aCPU\u5e72\u5230100%\u4e00\u665a\u4e0a \u5565\u4e8b\u6ca1\u6709\uff0c\u4ee5\u4e3a\u8981\u51c9\u4e86\u3002\u7ed3\u679c\u8fde\u8b66\u544a\u90fd\u6ca1\u6709:lolhttps:\/\/cdn.jsdelivr.net\/gh\/hishis\/forum-master\/public\/images\/patch.gif\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>yanaxiao<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u7528\u4e86\u4e00\u5e74\u4e86\uff0c\u6ca1\u5173\u673a\u8fc7\u3002\t\t\t  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>ncnc \u5927\u4f6c\u6709\u8bdd\u8bf4 : VIR\u5bb6&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/224835"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=224835"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/224835\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=224835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=224835"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=224835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}