{"id":442451,"date":"2026-02-25T16:38:04","date_gmt":"2026-02-25T08:38:04","guid":{"rendered":"https:\/\/idc.net\/help\/?p=442451"},"modified":"2026-02-12T16:39:13","modified_gmt":"2026-02-12T08:39:13","slug":"ubuntu-server-%e7%a3%81%e7%9b%98%e7%a9%ba%e9%97%b4%e4%b8%8d%e8%b6%b3%e7%9a%84%e5%8e%9f%e5%9b%a0%e4%b8%8e%e8%a7%a3%e5%86%b3%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/442451\/","title":{"rendered":"Ubuntu Server \u78c1\u76d8\u7a7a\u95f4\u4e0d\u8db3\u7684\u539f\u56e0\u4e0e\u89e3\u51b3\u65b9\u6cd5"},"content":{"rendered":"<p dir=\"auto\">Ubuntu Server\uff08\u5c24\u5176\u662f24.04 LTS\u53ca\u540e\u7eed\u7248\u672c\uff09\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u7ecf\u5e38\u9047\u5230\u6839\u5206\u533a\uff08\/\uff09\u6216 \/var \u5206\u533a\u78c1\u76d8\u7a7a\u95f4\u8017\u5c3d\u7684\u95ee\u9898\uff0c\u5bfc\u81f4\u51fa\u73b0\u201cNo space left on device\u201d\u9519\u8bef\u3001\u65e0\u6cd5\u5199\u5165\u65b0\u6587\u4ef6\u3001\u670d\u52a1\u5d29\u6e83\u751a\u81f3\u7cfb\u7edf\u65e0\u6cd5\u767b\u5f55\u3002\u8fd9\u79cd\u60c5\u51b5\u901a\u5e38\u4e0d\u662f\u786c\u4ef6\u6545\u969c\uff0c\u800c\u662f<strong>\u53ef\u9884\u6d4b\u3001\u53ef\u9884\u9632\u7684\u7d2f\u79ef\u6027\u5360\u7528<\/strong>\u3002<\/p>\n<h2 dir=\"auto\">\u4e00\u3001\u5e38\u89c1\u539f\u56e0\u5206\u7c7b\uff08\u4ece\u9ad8\u9891\u5230\u4f4e\u9891\uff09<\/h2>\n<ol dir=\"auto\">\n<li><strong>\u65e5\u5fd7\u6587\u4ef6\u65e0\u9650\u589e\u957f<\/strong>\uff08\u6700\u5e38\u89c1\uff0c\u536050%\u4ee5\u4e0a\u6848\u4f8b\uff09\n<ul dir=\"auto\">\n<li>\/var\/log\/journal\/\uff08systemd-journald\u6301\u4e45\u5316\u65e5\u5fd7\uff09<\/li>\n<li>\/var\/log\/syslog\u3001auth.log\u3001kern.log \u7b49\u4f20\u7edf\u6587\u672c\u65e5\u5fd7<\/li>\n<li>\u9ad8\u8d1f\u8f7d\u670d\u52a1\uff08\u5982nginx\u3001postgresql\u3001docker\uff09\u4ea7\u751f\u5927\u91cfdebug\/info\u7ea7\u65e5\u5fd7<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u5305\u7ba1\u7406\u7f13\u5b58\u4e0e\u65e7\u7248\u672c\u6b8b\u7559<\/strong>\n<ul dir=\"auto\">\n<li>\/var\/cache\/apt\/archives\/ \u4e2d\u7684 .deb \u5305\uff08apt \u672a clean\uff09<\/li>\n<li>snap \u7f13\u5b58 \/var\/lib\/snapd\/cache\/<\/li>\n<li>\u65e7\u5185\u6838\u955c\u50cf\uff08\/boot\/ \u7a7a\u95f4\u7d27\u5f20\u65f6\u5e38\u89c1\uff09<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u5bb9\u5668\u4e0e\u865a\u62df\u5316\u76f8\u5173<\/strong>\n<ul dir=\"auto\">\n<li>Docker\/Podman \u955c\u50cf\u3001\u5bb9\u5668\u5c42\u3001volume\u3001overlayfs\uff08\/var\/lib\/docker\/\uff09<\/li>\n<li>MicroK8s \/ k3s \u7b49\u8f7b\u91cfk8s \u7684 etcd\u3001\u955c\u50cf\u7f13\u5b58<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u4e34\u65f6\u6587\u4ef6\u4e0e\u7f13\u5b58\u7206\u70b8<\/strong>\n<ul dir=\"auto\">\n<li>\/tmp\/\u3001\/var\/tmp\/ \u4e2d\u672a\u6e05\u7406\u7684\u4e34\u65f6\u6587\u4ef6<\/li>\n<li>\u7528\u6237\u7f13\u5b58\uff08\u5982 ~\/.cache\/\u3001\u6d4f\u89c8\u5668\u7f13\u5b58\u82e5\u6709\u670d\u52a1\u8fd0\u884c\uff09<\/li>\n<li>\u5e94\u7528\u7a0b\u5e8f\u751f\u6210\u7684\u4e34\u65f6\u5927\u6587\u4ef6\uff08\u5982\u5907\u4efd\u3001\u5bfc\u51fa\uff09<\/li>\n<\/ul>\n<\/li>\n<li><strong>Inode \u8017\u5c3d<\/strong>\uff08\u7a7a\u95f4\u6709\u4f59\u4f46\u65e0\u6cd5\u521b\u5efa\u6587\u4ef6\uff09\n<ul dir=\"auto\">\n<li>\u6781\u5c0f\u6587\u4ef6\u6570\u91cf\u8fc7\u591a\uff08\u5e38\u89c1\u4e8e\u90ae\u4ef6\u961f\u5217\u3001\u65e5\u5fd7\u788e\u7247\u3001git\u4ed3\u5e93\u6ee5\u7528\uff09<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u5df2\u5220\u9664\u6587\u4ef6\u53e5\u67c4\u672a\u91ca\u653e<\/strong>\uff08df \u663e\u793a\u6ee1\uff0cdu \u663e\u793a\u7a7a\u95f2\uff09\n<ul dir=\"auto\">\n<li>\u5927\u6587\u4ef6\u88ab\u5220\u9664\u4f46\u8fdb\u7a0b\u4ecd\u6301\u6709\u6253\u5f00\u53e5\u67c4\uff08\u5e38\u89c1\u4e8e\u65e5\u5fd7\u8f6e\u8f6c\u5931\u8d25\u7684\u670d\u52a1\uff09<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u5206\u533a\/\u6587\u4ef6\u7cfb\u7edf\u9884\u7559\u7a7a\u95f4 + \u6839\u5206\u533a\u8fc7\u5c0f<\/strong>\n<ul dir=\"auto\">\n<li>ext4 \u9ed8\u8ba4\u9884\u75595%\u7ed9root\uff08\u975eroot\u7528\u6237\u65e0\u6cd5\u4f7f\u7528\uff09<\/li>\n<li>\u4e91\u670d\u52a1\u5668\u521d\u59cb\u5206\u533a\u8fc7\u5c0f\uff0810\u201325GB\uff09\uff0csnap\/docker\u5b89\u88c5\u540e\u5feb\u901f\u8017\u5c3d<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u5176\u4ed6\u5c11\u89c1\u4f46\u81f4\u547d<\/strong>\n<ul dir=\"auto\">\n<li>core dump \u6587\u4ef6\uff08ulimit \u672a\u9650\u5236\uff09<\/li>\n<li>\u76d1\u63a7\u5de5\u5177\uff08\u5982Prometheus\uff09\u6570\u636e\u76ee\u5f55\u81a8\u80c0<\/li>\n<li>ZFS\/ btrfs \u5feb\u7167\u672a\u6e05\u7406<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h2 dir=\"auto\">\u4e8c\u3001\u8bca\u65ad\u6d41\u7a0b\uff08\u63a8\u8350\u987a\u5e8f\uff09<\/h2>\n<ol dir=\"auto\">\n<li><strong>\u6574\u4f53\u6982\u89c8<\/strong>df -hT \u2192 \u67e5\u770b\u54ea\u4e2a\u6302\u8f7d\u70b9\u6ee1\uff08\u91cd\u70b9\u770b \/ \u548c \/var\uff09 df -i \u2192 \u68c0\u67e5 inode \u662f\u5426\u8017\u5c3d<\/li>\n<li><strong>\u5feb\u901f\u5b9a\u4f4d\u5927\u6237<\/strong>sudo du -sh \/* 2&gt;\/dev\/null | sort -hr | head -15 \u901a\u5e38\u524d\u51e0\u540d\u662f \/var\u3001\/home\u3001\/usr<\/li>\n<li><strong>\u6df1\u5165 \/var<\/strong>\uff08\u51e0\u4e4e\u603b\u662f\u7f6a\u9b41\uff09 sudo du -sh \/var\/* | sort -hr \u91cd\u70b9\u68c0\u67e5\uff1a\n<ul dir=\"auto\">\n<li>\/var\/log<\/li>\n<li>\/var\/lib\/docker<\/li>\n<li>\/var\/cache<\/li>\n<li>\/var\/lib\/snapd<\/li>\n<\/ul>\n<\/li>\n<li><strong>journald \u5360\u7528<\/strong>journalctl --disk-usage<\/li>\n<li><strong>\u88ab\u5220\u9664\u4f46\u672a\u91ca\u653e\u6587\u4ef6<\/strong>sudo lsof \/ | grep deleted \u6216 sudo ls -l \/proc\/*\/fd\/* | grep deleted<\/li>\n<\/ol>\n<h2 dir=\"auto\">\u4e09\u3001\u9488\u5bf9\u6027\u89e3\u51b3\u65b9\u6cd5<\/h2>\n<h3 dir=\"auto\">1. \u6e05\u7406 journal \u65e5\u5fd7\uff08\u6700\u5e38\u89c1\u89e3\u6cd5\uff09<\/h3>\n<p dir=\"auto\">\u4e34\u65f6\u6e05\u7406\uff1a<\/p>\n<ul dir=\"auto\">\n<li>\u4fdd\u7559\u6700\u8fd12\u5468\uff1asudo journalctl --vacuum-time=2weeks<\/li>\n<li>\u9650\u5236\u603b\u5927\u5c0f500MB\uff1asudo journalctl --vacuum-size=500M<\/li>\n<\/ul>\n<p dir=\"auto\">\u6c38\u4e45\u9650\u5236\uff08\u63a8\u8350\u751f\u4ea7\u73af\u5883\uff09\uff1a \u7f16\u8f91 \/etc\/systemd\/journald.conf\uff08\u6216\u521b\u5efa \/etc\/systemd\/journald.conf.d\/override.conf\uff09\uff1a<\/p>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>text<\/div>\n<div>\n<pre tabindex=\"0\"><code>[Journal]\r\nSystemMaxUse=500M\r\nSystemKeepFree=2G\r\nMaxRetentionSec=4weeks<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p dir=\"auto\">\u7136\u540e sudo systemctl restart systemd-journald<\/p>\n<h3 dir=\"auto\">2. \u5305\u7ba1\u7406\u7f13\u5b58\u6e05\u7406<\/h3>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>Bash<\/div>\n<div>\n<pre tabindex=\"0\"><code>sudo apt clean                  # \u6e05\u7a7a\u5df2\u4e0b\u8f7d\u7684deb\u5305\r\nsudo apt autoclean\r\nsudo apt autoremove<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p dir=\"auto\">snap \u6e05\u7406\uff1a<\/p>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>Bash<\/div>\n<div>\n<pre tabindex=\"0\"><code>sudo snap set system refresh.retain=2\r\nsudo snap list --all | awk '\/disabled\/{print $1, $3}' | while read snapname revision; do sudo snap remove \"$snapname\" --revision=\"$revision\"; done<\/code><\/pre>\n<\/div>\n<div><\/div>\n<\/div>\n<\/div>\n<\/div>\n<h3 dir=\"auto\">3. Docker\/Podman \u6e05\u7406<\/h3>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>Bash<\/div>\n<div>\n<pre tabindex=\"0\"><code>docker system prune -a --volumes    # \u6781\u81f4\u6e05\u7406\uff08\u614e\u7528\uff09\r\n# \u6216\u5206\u6b65\uff1a\r\ndocker image prune -a\r\ndocker container prune\r\ndocker volume prune<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<h3 dir=\"auto\">4. \u91ca\u653e\u88ab\u5220\u9664\u6587\u4ef6\u7a7a\u95f4<\/h3>\n<p dir=\"auto\">\u627e\u5230\u5360\u7528\u8fdb\u7a0b \u2192 \u91cd\u542f\/\u6740\u6389\u8fdb\u7a0b\uff08\u670d\u52a1\u4f1a\u81ea\u52a8\u91cd\u542f\uff09 \u6700\u5b89\u5168\u65b9\u5f0f\uff1asudo systemctl restart \u5bf9\u5e94\u670d\u52a1<\/p>\n<h3 dir=\"auto\">5. Inode \u8017\u5c3d\u89e3\u51b3<\/h3>\n<p dir=\"auto\">\u67e5\u627e\u5c0f\u6587\u4ef6\u5927\u6237\uff1a<\/p>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>Bash<\/div>\n<div>\n<pre tabindex=\"0\"><code>sudo find \/ -xdev -type f | xargs -I {} ls -l {} | sort -n -k 5 | tail -n 100<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p dir=\"auto\">\u5e38\u89c1\u6e05\u7406\uff1a\u90ae\u4ef6\u961f\u5217\u3001\u7f13\u5b58\u6587\u4ef6\u3001\u4e34\u65f6\u5c0f\u65e5\u5fd7\u3002<\/p>\n<h3 dir=\"auto\">6. ext4 \u9884\u7559\u7a7a\u95f4\u8c03\u6574\uff08\u53ef\u9009\uff09<\/h3>\n<p dir=\"auto\">sudo tune2fs -m 1 \/dev\/sdX1\uff08\u964d\u52301%\uff09<\/p>\n<h3 dir=\"auto\">7. \u957f\u671f\u9884\u9632\u673a\u5236<\/h3>\n<ul dir=\"auto\">\n<li>\u8bbe\u7f6e logrotate \u4e25\u683c\u8f6e\u8f6c \/var\/log\/*.log<\/li>\n<li>\u76d1\u63a7\u544a\u8b66\uff1aNetdata\/Prometheus + node_exporter \u78c1\u76d8\u4f7f\u7528\u7387 &gt;85% \u544a\u8b66<\/li>\n<li>\u4e91\u73af\u5883\uff1a\u5b9a\u671f\u6269\u5bb9\u6839\u78c1\u76d8 + \u4f7f\u7528 LVM \u52a8\u6001\u6269\u5c55<\/li>\n<li>\u89c4\u5212\u5206\u533a\uff1a\/var\u3001\/var\/lib\/docker\u3001\/home \u72ec\u7acb\u6302\u8f7d\u70b9<\/li>\n<\/ul>\n<h2 dir=\"auto\">\u56db\u3001\u603b\u7ed3\u4f18\u5148\u7ea7\u5904\u7406\u987a\u5e8f<\/h2>\n<ol dir=\"auto\">\n<li>\u68c0\u67e5 df -h + df -i<\/li>\n<li>\u6e05\u7406 journalctl\uff08vacuum-size 500M\u20131G\uff09<\/li>\n<li>apt clean + autoremove<\/li>\n<li>snap \u6e05\u7406\u65e7\u7248\u672c<\/li>\n<li>docker prune\uff08\u5982\u679c\u7528\u5bb9\u5668\uff09<\/li>\n<li>du \u5b9a\u4f4d\u5176\u4ed6\u5927\u76ee\u5f55\u9010\u4e2a\u6e05\u7406<\/li>\n<li>\u91cd\u542f\u76f8\u5173\u670d\u52a1\u91ca\u653e deleted \u6587\u4ef6<\/li>\n<li>\u5982\u679c\u4ecd\u4e0d\u8db3 \u2192 \u6269\u5bb9\u78c1\u76d8\uff08\u4e91\u5e73\u53f0\u63a7\u5236\u53f0 + growpart + resize2fs\uff09<\/li>\n<\/ol>\n<p dir=\"auto\">\u78c1\u76d8\u7a7a\u95f4\u4e0d\u8db3\u662f\u670d\u52a1\u5668\u8fd0\u7ef4\u4e2d\u6700\u5e38\u89c1\u7684\u201c\u6162\u6027\u75c5\u201d\uff0c\u901a\u8fc7\u4ee5\u4e0a\u8bca\u65ad+\u81ea\u52a8\u5316\u6e05\u7406\uff08cron + journald \u914d\u7f6e\uff09\uff0c\u7edd\u5927\u591a\u6570\u60c5\u51b5\u90fd\u80fd\u57285\u201315\u5206\u949f\u5185\u89e3\u51b3\uff0c\u5e76\u907f\u514d\u53cd\u590d\u53d1\u751f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ubuntu Server\uff08\u5c24\u5176\u662f24.04 LTS\u53ca\u540e\u7eed\u7248\u672c\uff09\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u7ecf\u5e38\u9047\u5230\u6839\u5206\u533a\uff08\/\uff09\u6216 \/var  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28],"tags":[],"class_list":["post-442451","post","type-post","status-publish","format-standard","hentry","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/442451","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=442451"}],"version-history":[{"count":1,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/442451\/revisions"}],"predecessor-version":[{"id":442452,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/442451\/revisions\/442452"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=442451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=442451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=442451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}