{"id":210664,"date":"2026-02-05T19:36:18","date_gmt":"2026-02-05T11:36:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/?p=210664"},"modified":"2026-02-05T19:36:18","modified_gmt":"2026-02-05T11:36:18","slug":"ubuntu-%e6%9c%8d%e5%8a%a1%e5%99%a8%e9%83%a8%e7%bd%b2%e4%b8%8e%e6%97%a5%e5%b8%b8%e7%bb%b4%e6%8a%a4%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/210664\/","title":{"rendered":"Ubuntu \u670d\u52a1\u5668\u90e8\u7f72\u4e0e\u65e5\u5e38\u7ef4\u62a4\u6307\u5357"},"content":{"rendered":"<p dir=\"auto\">Ubuntu Server \u662f\u751f\u4ea7\u73af\u5883\u4e2d\u5e7f\u6cdb\u4f7f\u7528\u7684 Linux \u53d1\u884c\u7248\uff0c\u4ee5\u5176\u7a33\u5b9a\u6027\u3001\u957f\u671f\u652f\u6301\u548c\u4e30\u5bcc\u7684\u751f\u6001\u8457\u79f0\u3002\u672c\u6307\u5357\u805a\u7126 24.04 LTS\uff08Noble Numbat\uff09\u53ca\u540e\u7eed\u7248\u672c\uff0c\u9002\u7528\u4e8e Web \u670d\u52a1\u3001API\u3001\u6570\u636e\u5e93\u3001\u5bb9\u5668\u7b49\u5e38\u89c1\u573a\u666f\u3002\u4ece\u90e8\u7f72\u5230\u65e5\u5e38\u7ef4\u62a4\uff0c\u63d0\u4f9b\u5b9e\u7528\u3001\u53ef\u843d\u5730\u7684\u6b65\u9aa4\u4e0e\u6700\u4f73\u5b9e\u8df5\uff0c\u5e2e\u52a9\u65b0\u624b\u5230\u4e2d\u7ea7\u8fd0\u7ef4\u4eba\u5458\u6784\u5efa\u53ef\u9760\u7684\u751f\u4ea7\u73af\u5883\u3002<\/p>\n<h3 dir=\"auto\">\u4e00\u3001\u90e8\u7f72\u9636\u6bb5\uff1a\u4ece\u96f6\u5230\u751f\u4ea7\u5c31\u7eea<\/h3>\n<h4 dir=\"auto\">1. \u9009\u62e9\u5b89\u88c5\u4ecb\u8d28\u4e0e\u521d\u59cb\u5b89\u88c5<\/h4>\n<ul dir=\"auto\">\n<li>\u4e0b\u8f7d\u5b98\u65b9 <strong>Ubuntu Server 24.04 LTS minimal ISO<\/strong>\uff08\u63a8\u8350 live-server \u955c\u50cf\uff09\u3002<\/li>\n<li>\u5b89\u88c5\u65f6\u4f18\u5148\u9009\u62e9 <strong>Minimal installation<\/strong>\uff0c\u53ea\u52fe\u9009 OpenSSH server\u3002<\/li>\n<li>\u5206\u533a\u5efa\u8bae\uff1a\n<ul dir=\"auto\">\n<li>\/boot \u6216 \/boot\/efi\uff1a1GB\uff08FAT32 \u6216 ext4\uff09<\/li>\n<li>\/\uff1a\u5269\u4f59\u7a7a\u95f4\uff08ext4 \u6216 xfs\uff09<\/li>\n<li>\u53ef\u9009\u5355\u72ec \/var\uff08\u65e5\u5fd7\u3001\u6570\u636e\u5e93\uff09\u3001\/home\u3001\/tmp\uff08tmpfs \u6216 noexec \u6302\u8f7d\uff09<\/li>\n<\/ul>\n<\/li>\n<li>\u521b\u5efa\u666e\u901a\u7528\u6237\uff08\u52a0\u5165 sudo \u7ec4\uff09\uff0c<strong>\u7981\u7528 root \u5bc6\u7801\u767b\u5f55<\/strong>\u3002<\/li>\n<li>\u5b89\u88c5\u5b8c\u6210\u540e\u7acb\u5373\uff1a\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>text<\/div>\n<div>\n<div>\n<div><\/div>\n<\/div>\n<\/div>\n<div>\n<pre tabindex=\"0\"><code>sudo apt update &amp;&amp; sudo apt full-upgrade -y &amp;&amp; sudo apt autoremove\r\nsudo reboot<\/code><\/pre>\n<\/div>\n<div><\/div>\n<\/div>\n<div><\/div>\n<\/div>\n<\/div>\n<\/li>\n<\/ul>\n<h4 dir=\"auto\">2. SSH \u5b89\u5168\u914d\u7f6e\uff08\u5fc5\u987b\u7b2c\u4e00\u65f6\u95f4\u5b8c\u6210\uff09<\/h4>\n<p dir=\"auto\">\u7f16\u8f91 \/etc\/ssh\/sshd_config\uff1a<\/p>\n<ul dir=\"auto\">\n<li>PermitRootLogin no<\/li>\n<li>PasswordAuthentication no\uff08\u540e\u7eed\u5168\u7528\u5bc6\u94a5\uff09<\/li>\n<li>PubkeyAuthentication yes<\/li>\n<li>Port 2222\uff08\u53ef\u9009\u6539\u7aef\u53e3\u964d\u4f4e\u626b\u63cf\uff09<\/li>\n<li>\u91cd\u542f\uff1asudo systemctl restart ssh<\/li>\n<\/ul>\n<p dir=\"auto\">\u751f\u6210\u5e76\u4e0a\u4f20\u5bc6\u94a5\uff1a<\/p>\n<ul dir=\"auto\">\n<li>\u672c\u5730\uff1assh-keygen -t ed25519<\/li>\n<li>\u4e0a\u4f20\uff1assh-copy-id \u7528\u6237\u540d@\u670d\u52a1\u5668IP<\/li>\n<li>\u6d4b\u8bd5\u65e0\u5bc6\u7801\u767b\u5f55\u540e\uff0c\u5220\u9664\u5bc6\u7801\u8ba4\u8bc1\u914d\u7f6e\u3002<\/li>\n<\/ul>\n<h4 dir=\"auto\">3. \u9632\u706b\u5899\u4e0e\u7f51\u7edc\u57fa\u7840<\/h4>\n<p dir=\"auto\">\u4f7f\u7528 <strong>ufw<\/strong>\uff08\u7b80\u5355\u9ad8\u6548\uff09\uff1a<\/p>\n<ul dir=\"auto\">\n<li>sudo ufw allow OpenSSH\uff08\u6216\u81ea\u5b9a\u4e49\u7aef\u53e3\uff09<\/li>\n<li>sudo ufw allow 80,443\/tcp\uff08Web \u670d\u52a1\uff09<\/li>\n<li>sudo ufw enable<\/li>\n<li>sudo ufw status verbose<\/li>\n<\/ul>\n<p dir=\"auto\">\u73b0\u4ee3\u7f51\u7edc\u914d\u7f6e\u4f7f\u7528 <strong>netplan<\/strong>\uff08\/etc\/netplan\/ \u4e0b yaml \u6587\u4ef6\uff09\uff1a<\/p>\n<ul dir=\"auto\">\n<li>\u8bbe\u7f6e\u9759\u6001 IP\u3001DNS\u3001gateway<\/li>\n<li>sudo netplan apply<\/li>\n<\/ul>\n<h4 dir=\"auto\">4. \u7cfb\u7edf\u52a0\u56fa\u57fa\u7840<\/h4>\n<ul dir=\"auto\">\n<li>\u5b89\u88c5 fail2ban\uff1asudo apt install fail2ban<\/li>\n<li>\u542f\u7528 unattended-upgrades\uff08\u81ea\u52a8\u5b89\u5168\u8865\u4e01\uff09\uff1a sudo dpkg-reconfigure &#8211;priority=low unattended-upgrades<\/li>\n<li>\u6ce8\u518c Ubuntu Pro\uff08\u514d\u8d39\u4e2a\u4eba\/\u5c0f\u56e2\u961f\uff09\uff1a sudo pro attach\uff08\u83b7\u53d6\u514d\u8d39 token\uff09 \u542f\u7528 Livepatch\uff08\u65e0\u91cd\u542f\u5185\u6838\u8865\u4e01\uff09\u548c ESM\uff08\u6269\u5c55 Universe \u5b89\u5168\u7ef4\u62a4\uff09\u3002<\/li>\n<li>\u6700\u5c0f\u5316\u670d\u52a1\uff1asudo systemctl disable &#8211;now \u4e0d\u9700\u8981\u7684\u670d\u52a1\uff08\u5982 bluetooth\u3001cups \u7b49\uff09\u3002<\/li>\n<\/ul>\n<h4 dir=\"auto\">5. \u5e38\u7528\u5de5\u5177\u5b89\u88c5<\/h4>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>text<\/div>\n<div>\n<div>\n<div><\/div>\n<\/div>\n<\/div>\n<div>\n<pre tabindex=\"0\"><code>sudo apt install htop ncdu curl wget git unzip tree net-tools sysstat needrestart -y<\/code><\/pre>\n<\/div>\n<div><\/div>\n<\/div>\n<div><\/div>\n<\/div>\n<\/div>\n<h3 dir=\"auto\">\u4e8c\u3001\u65e5\u5e38\u7ef4\u62a4\uff1a\u5de1\u68c0\u3001\u66f4\u65b0\u3001\u76d1\u63a7<\/h3>\n<h4 dir=\"auto\">1. \u6bcf\u65e5\u5de1\u68c0\u6e05\u5355\uff085-10 \u5206\u949f\uff09<\/h4>\n<ul dir=\"auto\">\n<li>uptime \/ w \u2192 \u8d1f\u8f7d\u3001\u5728\u7ebf\u7528\u6237<\/li>\n<li>free -h \u2192 \u5185\u5b58 available<\/li>\n<li>df -h \/ df -i \u2192 \u78c1\u76d8\u7a7a\u95f4 &amp; inode<\/li>\n<li>top \/ htop \u2192 \u524d\u51e0\u540d\u8fdb\u7a0b\u5360\u7528<\/li>\n<li>journalctl -p err -b \u2192 \u5f53\u5929\u9519\u8bef\u65e5\u5fd7<\/li>\n<li>grep &#8220;Failed password&#8221; \/var\/log\/auth.log | tail -20 \u2192 \u66b4\u529b\u7834\u89e3\u5c1d\u8bd5<\/li>\n<li>sudo needrestart \u2192 \u68c0\u67e5\u66f4\u65b0\u540e\u9700\u91cd\u542f\u7684\u670d\u52a1\/\u5185\u6838<\/li>\n<\/ul>\n<h4 dir=\"auto\">2. \u66f4\u65b0\u7b56\u7565\uff082026 \u5e74\u63a8\u8350\uff09<\/h4>\n<ul dir=\"auto\">\n<li><strong>\u5b89\u5168\u8865\u4e01<\/strong>\uff1a\u542f\u7528 unattended-upgrades\uff0c\u9ed8\u8ba4\u6bcf\u65e5\u81ea\u52a8\u5e94\u7528\u3002<\/li>\n<li><strong>\u5b8c\u6574\u5347\u7ea7<\/strong>\uff1a\u6bcf\u5468\u6216\u6bcf\u6708\u7ef4\u62a4\u7a97\u53e3\uff1a\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>text<\/div>\n<div>\n<div>\n<div><\/div>\n<\/div>\n<\/div>\n<div>\n<pre tabindex=\"0\"><code>sudo apt update &amp;&amp; sudo apt full-upgrade -y &amp;&amp; sudo apt autoremove\r\nsudo needrestart<\/code><\/pre>\n<\/div>\n<div><\/div>\n<\/div>\n<div><\/div>\n<\/div>\n<\/div>\n<\/li>\n<li><strong>\u5185\u6838 Livepatch<\/strong>\uff1a\u542f\u7528\u540e\u5185\u6838\u5b89\u5168\u8865\u4e01\u65e0\u9700\u91cd\u542f\uff08Ubuntu Pro\uff09\u3002<\/li>\n<li><strong>\u91cd\u542f\u7b56\u7565<\/strong>\uff1a\u975e Livepatch \u5185\u6838\u66f4\u65b0\u540e\uff0c\u9009\u62e9\u4f4e\u5cf0\u671f\u91cd\u542f\uff1b\u5efa\u8bae\u6bcf\u6708\u81f3\u5c11\u4e00\u6b21\u5b8c\u6574\u91cd\u542f\u9a8c\u8bc1\u7a33\u5b9a\u6027\u3002<\/li>\n<\/ul>\n<h4 dir=\"auto\">3. \u65e5\u5fd7\u4e0e\u7a7a\u95f4\u7ba1\u7406<\/h4>\n<ul dir=\"auto\">\n<li>journalctl &#8211;vacuum-time=60d \u6216 &#8211;vacuum-size=5G \u2192 \u9650\u5236\u65e5\u5fd7\u4f53\u79ef<\/li>\n<li>sudo apt clean &amp;&amp; sudo apt autoclean \u2192 \u6e05 deb \u7f13\u5b58<\/li>\n<li>ncdu \/ \u2192 \u4ea4\u4e92\u5f0f\u67e5\u627e\u5927\u6587\u4ef6\/\u76ee\u5f55<\/li>\n<li>find \/var\/log -type f -mtime +90 -delete \u2192 \u5220\u9664 90 \u5929\u524d\u65e7\u65e5\u5fd7\uff08\u8c28\u614e\uff09<\/li>\n<\/ul>\n<h4 dir=\"auto\">4. \u5907\u4efd\u57fa\u7840<\/h4>\n<ul dir=\"auto\">\n<li>\u914d\u7f6e rsync \u589e\u91cf\u5907\u4efd\uff1a\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>text<\/div>\n<div>\n<div>\n<div><\/div>\n<\/div>\n<\/div>\n<div>\n<pre tabindex=\"0\"><code>rsync -avz --delete \/\u91cd\u8981\u76ee\u5f55\/ backup@\u8fdc\u7a0bIP:\/backup\/<\/code><\/pre>\n<\/div>\n<div><\/div>\n<\/div>\n<div><\/div>\n<\/div>\n<\/div>\n<\/li>\n<li>\u6570\u636e\u5e93\uff1amysqldump \u6216 pg_dump + cron<\/li>\n<li>\u7f6e cron \u5b9a\u65f6\u4efb\u52a1\uff08crontab -e\uff09\uff1a\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>text<\/div>\n<div>\n<div>\n<div><\/div>\n<\/div>\n<\/div>\n<div>\n<pre tabindex=\"0\"><code>0 3 * * * \/root\/backup.sh  # \u6bcf\u5929\u51cc\u6668 3 \u70b9\u5907\u4efd\r\n0 4 * * 0 \/root\/full-upgrade.sh  # \u6bcf\u5468\u65e5\u5347\u7ea7<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/li>\n<\/ul>\n<h4 dir=\"auto\">5. \u76d1\u63a7\u4e0e\u544a\u8b66\u5165\u95e8<\/h4>\n<ul dir=\"auto\">\n<li>\u5b89\u88c5 netdata\uff08\u4e00\u952e\u5b9e\u65f6\u76d1\u63a7\uff09\uff1abash &lt;(curl -Ss <a href=\"https:\/\/my-netdata.io\/kickstart.sh\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">https:\/\/my-netdata.io\/kickstart.sh<\/a>)<\/li>\n<li>\u6216 prometheus-node-exporter + Grafana\uff08\u66f4\u4e13\u4e1a\uff09<\/li>\n<li>\u7b80\u5355\u811a\u672c\u76d1\u63a7\u78c1\u76d8\/\u8d1f\u8f7d\uff0c\u4f4e\u4e8e\u9608\u503c\u53d1\u90ae\u4ef6\u6216 webhook\u3002<\/li>\n<\/ul>\n<h3 dir=\"auto\">\u4e09\u3001\u5e38\u89c1\u751f\u4ea7\u573a\u666f\u6269\u5c55<\/h3>\n<ul dir=\"auto\">\n<li><strong>Web \u670d\u52a1\u5668<\/strong>\uff1aNginx\/Apache + Let&#8217;s Encrypt SSL + systemd \u670d\u52a1\u7ba1\u7406\u3002<\/li>\n<li><strong>\u5bb9\u5668\u5316<\/strong>\uff1aDocker\/Podman \u6216 MicroK8s\uff08\u5355\u8282\u70b9 K8s\uff09\u3002<\/li>\n<li><strong>\u6570\u636e\u5e93<\/strong>\uff1aPostgreSQL\/MySQL\/MongoDB \u2192 \u5355\u72ec\u5206\u533a\u3001\u5b9a\u671f vacuum\/optimize\u3002<\/li>\n<li><strong>\u591a\u673a\u7ba1\u7406<\/strong>\uff1aAnsible \u6279\u91cf\u914d\u7f6e\u3001Landscape\uff08Canonical \u5b98\u65b9\uff09\u6216\u81ea\u5efa\u811a\u672c\u3002<\/li>\n<\/ul>\n<h3 dir=\"auto\">\u56db\u3001\u603b\u7ed3\uff1a\u751f\u4ea7\u7ea7\u7ef4\u62a4\u5fc3\u6cd5<\/h3>\n<ul dir=\"auto\">\n<li><strong>\u6700\u5c0f\u5316 + \u81ea\u52a8\u5316<\/strong>\uff1a\u51cf\u5c11\u624b\u52a8\u64cd\u4f5c\uff0c\u542f\u7528 unattended-upgrades + Livepatch\u3002<\/li>\n<li><strong>\u5b9a\u671f\u9a8c\u8bc1<\/strong>\uff1a\u6bcf\u5468\u68c0\u67e5\u65e5\u5fd7\u3001\u6bcf\u6708\u6a21\u62df\u6545\u969c\/\u91cd\u542f\u3002<\/li>\n<li><strong>\u6587\u6863 &amp; \u53d8\u66f4\u8bb0\u5f55<\/strong>\uff1a\u6240\u6709\u6539\u52a8\u8bb0\u5728 README \u6216 git \u4ed3\u5e93\u3002<\/li>\n<li><strong>\u9ec4\u91d1\u6392\u67e5\u987a\u5e8f<\/strong>\uff1auptime \u2192 free -h \u2192 df -h\/-i \u2192 top \u2192 journalctl -xe \u2192 needrestart<\/li>\n<\/ul>\n<p dir=\"auto\">\u9075\u5faa\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u80fd\u8ba9 Ubuntu Server \u5728 2026 \u5e74\u7684\u751f\u4ea7\u73af\u5883\u4e2d\u4fdd\u6301\u9ad8\u53ef\u7528\u3001\u4f4e\u98ce\u9669\u3002\u5b9e\u9645\u73af\u5883\u56e0\u4e1a\u52a1\u800c\u5f02\uff0c\u5efa\u8bae\u4ece\u5c0f\u89c4\u6a21\u5f00\u59cb\u5b9e\u8df5\uff0c\u9010\u6b65\u81ea\u52a8\u5316\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ubuntu Server \u662f\u751f&#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-210664","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/210664","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=210664"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/210664\/revisions"}],"predecessor-version":[{"id":210665,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/210664\/revisions\/210665"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=210664"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=210664"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=210664"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}