{"id":6524,"date":"2025-12-26T11:03:46","date_gmt":"2025-12-26T03:03:46","guid":{"rendered":"https:\/\/dingxuan.info\/wp\/?p=6524"},"modified":"2025-12-26T12:00:18","modified_gmt":"2025-12-26T04:00:18","slug":"ubuntu%e5%a6%82%e4%bd%95%e8%ae%be%e7%bd%ae%e8%87%aa%e5%8a%a8%e6%89%a7%e8%a1%8capt-upgrade","status":"publish","type":"post","link":"https:\/\/dingxuan.info\/wp\/?p=6524","title":{"rendered":"ubuntu\u5982\u4f55\u8bbe\u7f6e\u81ea\u52a8\u6267\u884capt upgrade"},"content":{"rendered":"<p>\u5728 Ubuntu \u4e2d\u8bbe\u7f6e\u81ea\u52a8\u66f4\u65b0\u548c\u5347\u7ea7\uff0c\u6700\u63a8\u8350\u3001\u6700\u6807\u51c6\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 <strong><code>unattended-upgrades<\/code><\/strong> \u5de5\u5177\u3002\u5b83\u6bd4\u7b80\u5355\u7684 Cron \u811a\u672c\u66f4\u5b89\u5168\uff0c\u56e0\u4e3a\u5b83\u80fd\u5904\u7406\u5305\u4f9d\u8d56\u5173\u7cfb\u3001\u914d\u7f6e\u4fdd\u7559\u4ee5\u53ca\u7cfb\u7edf\u9501\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u8be6\u7ec6\u7684\u8bbe\u7f6e\u6b65\u9aa4\uff1a<\/p>\n<!--more-->\n<h3 class=\"wp-block-heading\">\u65b9\u6cd5\u4e00\uff1a\u4f7f\u7528 <code>unattended-upgrades<\/code> (\u5b98\u65b9\u63a8\u8350)<\/h3>\n<h4 class=\"wp-block-heading\">1. \u5b89\u88c5\u5e76\u542f\u7528\u670d\u52a1<\/h4>\n<p>\u5927\u591a\u6570 Ubuntu \u7248\u672c\u9ed8\u8ba4\u5df2\u5b89\u88c5\u6b64\u5de5\u5177\u3002\u5982\u679c\u6ca1\u6709\uff0c\u8bf7\u5148\u5b89\u88c5\uff1a<\/p>\n<pre><code class=\"language-bash\">sudo apt update\nsudo apt install unattended-upgrades\n<\/code><\/pre>\n<p>\u63a5\u4e0b\u6765\uff0c\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u542f\u7528\u81ea\u52a8\u66f4\u65b0\uff08\u4f1a\u5f39\u51fa\u4e00\u4e2a\u84dd\u8272\u754c\u9762\uff0c\u9009\u62e9 <strong>Yes<\/strong> \u5e76\u56de\u8f66\uff09\uff1a<\/p>\n<pre><code class=\"language-bash\">sudo dpkg-reconfigure --priority=low unattended-upgrades\n<\/code><\/pre>\n<p><em>\u8fd9\u4f1a\u81ea\u52a8\u521b\u5efa <code>\/etc\/apt\/apt.conf.d\/20auto-upgrades<\/code> \u914d\u7f6e\u6587\u4ef6\u3002<\/em><\/p>\n<h4 class=\"wp-block-heading\">2. \u914d\u7f6e\u66f4\u65b0\u8303\u56f4\uff08\u91cd\u8981\uff09<\/h4>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u8be5\u5de5\u5177\u901a\u5e38<strong>\u53ea\u5b89\u88c5\u5b89\u5168\u66f4\u65b0<\/strong>\u3002\u5982\u679c\u4f60\u5e0c\u671b\u5b83\u50cf\u6267\u884c <code>apt upgrade<\/code> \u4e00\u6837\u66f4\u65b0\u6240\u6709\u8f6f\u4ef6\uff0c\u9700\u8981\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<p>\u6253\u5f00\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code class=\"language-bash\">sudo nano \/etc\/apt\/apt.conf.d\/50unattended-upgrades\n<\/code><\/pre>\n<p>\u627e\u5230 <code>Unattended-Upgrade::Allowed-Origins<\/code> \u90e8\u5206\u3002\n\u4f60\u9700\u8981<strong>\u53d6\u6d88\u6ce8\u91ca<\/strong>\uff08\u53bb\u6389\u884c\u9996\u7684 <code>\/\/<\/code>\uff09\u5305\u542b <code>-updates<\/code> \u7684\u90a3\u4e00\u884c\u3002<\/p>\n<p>\u4fee\u6539\u524d\uff1a<\/p>\n<pre><code class=\"language-conf\">Unattended-Upgrade::Allowed-Origins {\n        &quot;${distro_id}:${distro_codename}&quot;;\n        &quot;${distro_id}:${distro_codename}-security&quot;;\n        \/\/ Extended Security Maintenance; doesn&#039;t necessarily exist for\n        \/\/ every release and this system may not be enabled\n        &quot;${distro_id}ESMApps:${distro_codename}-apps-security&quot;;\n        &quot;${distro_id}ESM:${distro_codename}-infra-security&quot;;\n\/\/      &quot;${distro_id}:${distro_codename}-updates&quot;;  &lt;-- \u8fd9\u4e00\u884c\u901a\u5e38\u662f\u88ab\u6ce8\u91ca\u7684\n\/\/      &quot;${distro_id}:${distro_codename}-proposed&quot;;\n\/\/      &quot;${distro_id}:${distro_codename}-backports&quot;;\n};\n<\/code><\/pre>\n<p><strong>\u4fee\u6539\u540e\uff08\u542f\u7528\u666e\u901a\u66f4\u65b0\uff09\uff1a<\/strong><\/p>\n<pre><code class=\"language-conf\">Unattended-Upgrade::Allowed-Origins {\n        &quot;${distro_id}:${distro_codename}&quot;;\n        &quot;${distro_id}:${distro_codename}-security&quot;;\n        ...\n        &quot;${distro_id}:${distro_codename}-updates&quot;;  &lt;-- \u53bb\u6389\u53cc\u659c\u6760\n        ...\n};\n<\/code><\/pre>\n<h4 class=\"wp-block-heading\">3. \u914d\u7f6e\u81ea\u52a8\u91cd\u542f\uff08\u53ef\u9009\uff09<\/h4>\n<p>\u5982\u679c\u66f4\u65b0\u4e86\u5185\u6838\uff08Kernel\uff09\uff0c\u901a\u5e38\u9700\u8981\u91cd\u542f\u624d\u80fd\u751f\u6548\u3002\u4f60\u53ef\u4ee5\u8bbe\u7f6e\u81ea\u52a8\u91cd\u542f\u3002<\/p>\n<p>\u5728\u540c\u4e00\u4e2a\u6587\u4ef6 (<code>50unattended-upgrades<\/code>) \u4e2d\u5411\u4e0b\u6eda\u52a8\uff0c\u627e\u5230\u4ee5\u4e0b\u8bbe\u7f6e\u5e76\u4fee\u6539\uff1a<\/p>\n<pre><code class=\"language-conf\">\/\/ \u8bbe\u7f6e\u4e3a true \u542f\u7528\u81ea\u52a8\u91cd\u542f\nUnattended-Upgrade::Automatic-Reboot &quot;true&quot;;\n\n\/\/ \u8bbe\u7f6e\u91cd\u542f\u65f6\u95f4\uff08\u4f8b\u5982\u51cc\u6668 02:00\uff09\nUnattended-Upgrade::Automatic-Reboot-Time &quot;02:00&quot;;\n<\/code><\/pre>\n<h4 class=\"wp-block-heading\">4. \u81ea\u52a8\u6e05\u7406\u65e7\u5185\u6838\u548c\u4f9d\u8d56\uff08\u53ef\u9009\uff09<\/h4>\n<p>\u4e3a\u4e86\u9632\u6b62 <code>\/boot<\/code> \u5206\u533a\u586b\u6ee1\uff0c\u5efa\u8bae\u5f00\u542f\u81ea\u52a8\u79fb\u9664\u672a\u4f7f\u7528\u7684\u4f9d\u8d56\uff1a<\/p>\n<pre><code class=\"language-conf\">Unattended-Upgrade::Remove-Unused-Dependencies &quot;true&quot;;\nUnattended-Upgrade::Remove-New-Unused-Dependencies &quot;true&quot;;\n<\/code><\/pre>\n<p>\u4fdd\u5b58\u6587\u4ef6\u5e76\u9000\u51fa (<code>Ctrl+O<\/code>, <code>Enter<\/code>, <code>Ctrl+X<\/code>)\u3002<\/p>\n<h4 class=\"wp-block-heading\">5. \u68c0\u67e5\u6267\u884c\u9891\u7387<\/h4>\n<p>\u68c0\u67e5 <code>\/etc\/apt\/apt.conf.d\/20auto-upgrades<\/code> \u6587\u4ef6\uff0c\u786e\u4fdd\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-conf\">APT::Periodic::Update-Package-Lists &quot;1&quot;;\nAPT::Periodic::Unattended-Upgrade &quot;1&quot;;\n<\/code><\/pre>\n<ul>\n<li>&#8220;1&#8221; \u8868\u793a\u6bcf\u5929\u6267\u884c\u4e00\u6b21\u3002<\/li>\n<li>&#8220;0&#8221; \u8868\u793a\u7981\u7528\u3002<\/li>\n<\/ul>\n<h4 class=\"wp-block-heading\">6. \u6d4b\u8bd5\u914d\u7f6e<\/h4>\n<p>\u4f60\u53ef\u4ee5\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u6a21\u62df\u8fd0\u884c\uff08\u4e0d\u4f1a\u771f\u7684\u5b89\u88c5\uff09\uff0c\u67e5\u770b\u662f\u5426\u6709\u62a5\u9519\uff1a<\/p>\n<pre><code class=\"language-bash\">sudo unattended-upgrades --dry-run --debug\n<\/code><\/pre>\n<hr \/>\n<h3 class=\"wp-block-heading\">\u65b9\u6cd5\u4e8c\uff1a\u4f7f\u7528 Crontab (\u7b80\u5355\u7c97\u66b4\uff0c\u4e0d\u63a8\u8350\u7528\u4e8e\u751f\u4ea7\u73af\u5883)<\/h3>\n<p>\u5982\u679c\u4f60\u4e0d\u60f3\u4f7f\u7528\u4e13\u95e8\u7684\u5de5\u5177\uff0c\u53ea\u60f3\u5f3a\u5236\u6bcf\u5929\u8fd0\u884c\u547d\u4ee4\uff0c\u53ef\u4ee5\u4f7f\u7528 Crontab\u3002\n<strong>\u6ce8\u610f\uff1a<\/strong> \u8fd9\u79cd\u65b9\u6cd5\u5728\u9047\u5230\u914d\u7f6e\u6587\u4ef6\u51b2\u7a81\uff08\u9700\u8981\u6309 Y\/N\uff09\u65f6\u53ef\u80fd\u4f1a\u5361\u4f4f\u6216\u5931\u8d25\u3002<\/p>\n<ol>\n<li>\n<p>\u7f16\u8f91 Crontab\uff1a<\/p>\n<pre><code class=\"language-bash\">sudo crontab -e\n<\/code><\/pre>\n<\/li>\n<li>\n<p>\u5728\u6587\u4ef6\u672b\u5c3e\u6dfb\u52a0\u4e00\u884c\uff08\u4f8b\u5982\u6bcf\u5929\u51cc\u6668 3 \u70b9\u6267\u884c\uff09\uff1a<\/p>\n<pre><code class=\"language-bash\">0 3 * * * apt update &amp;&amp; apt upgrade -y &amp;&amp; apt autoremove -y\n<\/code><\/pre>\n<ul>\n<li><code>-y<\/code> \u53c2\u6570\u8868\u793a\u81ea\u52a8\u786e\u8ba4\u6240\u6709\u63d0\u793a\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<hr \/>\n<h3 class=\"wp-block-heading\">\u5982\u4f55\u67e5\u770b\u66f4\u65b0\u65e5\u5fd7\uff1f<\/h3>\n<p>\u5982\u679c\u4f7f\u7528\u65b9\u6cd5\u4e00 (<code>unattended-upgrades<\/code>)\uff0c\u65e5\u5fd7\u6587\u4ef6\u4f4d\u4e8e\uff1a\n<code>\/var\/log\/unattended-upgrades\/<\/code><\/p>\n<p>\u4f60\u53ef\u4ee5\u67e5\u770b\u6700\u8fd1\u7684\u65e5\u5fd7\uff1a<\/p>\n<pre><code class=\"language-bash\">cat \/var\/log\/unattended-upgrades\/unattended-upgrades.log\n<\/code><\/pre>\n<h3 class=\"wp-block-heading\">\u603b\u7ed3\u5efa\u8bae<\/h3>\n<ul>\n<li><strong>\u4e2a\u4eba\u7535\u8111\/\u6d4b\u8bd5\u673a<\/strong>\uff1a\u63a8\u8350\u4f7f\u7528 <strong>\u65b9\u6cd5\u4e00<\/strong>\uff0c\u5e76\u5f00\u542f <code>-updates<\/code> \u6e90\u3002<\/li>\n<li><strong>\u751f\u4ea7\u73af\u5883\u670d\u52a1\u5668<\/strong>\uff1a\n<ul>\n<li>\u63a8\u8350\u4f7f\u7528 <strong>\u65b9\u6cd5\u4e00<\/strong>\uff0c\u4f46\u901a\u5e38<strong>\u53ea\u5f00\u542f <code>-security<\/code> (\u5b89\u5168\u66f4\u65b0)<\/strong>\u3002<\/li>\n<li>\u5bf9\u4e8e\u666e\u901a\u7684\u5e94\u7528\u66f4\u65b0\uff0c\u5efa\u8bae\u4eba\u5de5\u624b\u52a8\u6267\u884c\uff0c\u4ee5\u514d\u81ea\u52a8\u66f4\u65b0\u5bfc\u81f4\u670d\u52a1\u517c\u5bb9\u6027\u95ee\u9898\u6302\u6389\u3002<\/li>\n<li>\u81ea\u52a8\u91cd\u542f\u529f\u80fd\u5728\u751f\u4ea7\u73af\u5883\u9700\u8c28\u614e\u5f00\u542f\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>\u5728 Ubuntu \u4e2d\u8bbe\u7f6e\u81ea\u52a8\u66f4\u65b0\u548c\u5347\u7ea7\uff0c\u6700\u63a8\u8350\u3001\u6700\u6807\u51c6\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 unattended-upgrades \u5de5 &hellip; <a href=\"https:\/\/dingxuan.info\/wp\/?p=6524\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">ubuntu\u5982\u4f55\u8bbe\u7f6e\u81ea\u52a8\u6267\u884capt upgrade<\/span><\/a><\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[117],"tags":[],"class_list":["post-6524","post","type-post","status-publish","format-standard","hentry","category-network"],"_links":{"self":[{"href":"https:\/\/dingxuan.info\/wp\/index.php?rest_route=\/wp\/v2\/posts\/6524","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dingxuan.info\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dingxuan.info\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dingxuan.info\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dingxuan.info\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6524"}],"version-history":[{"count":3,"href":"https:\/\/dingxuan.info\/wp\/index.php?rest_route=\/wp\/v2\/posts\/6524\/revisions"}],"predecessor-version":[{"id":6529,"href":"https:\/\/dingxuan.info\/wp\/index.php?rest_route=\/wp\/v2\/posts\/6524\/revisions\/6529"}],"wp:attachment":[{"href":"https:\/\/dingxuan.info\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dingxuan.info\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dingxuan.info\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}