{"id":75,"date":"2026-11-04T12:00:25","date_gmt":"2026-11-04T20:00:25","guid":{"rendered":"\/?p=75"},"modified":"2026-11-04T12:00:25","modified_gmt":"2026-11-04T20:00:25","slug":"post-mw1l9hqp","status":"publish","type":"post","link":"https:\/\/www.woiov.cn\/?p=75","title":{"rendered":"LXC \u4e0d\u662f\u5c0f\u53f7\u865a\u62df\u673a\uff1a\u4e94\u4e2a\u5728\u5bb9\u5668\u91cc\u771f\u649e\u8fc7\u7684\u8fb9\u754c"},"content":{"rendered":"<h2>LXC \u4e0d\u662f\u5c0f\u53f7\u865a\u62df\u673a\uff1a\u4e94\u4e2a\u5728\u5bb9\u5668\u91cc\u771f\u649e\u8fc7\u7684\u8fb9\u754c<\/h2>\n<p>\u6258\u7ba1\u4e1a\u52a1\u8dd1\u5728 PVE \u7684 LXC \u4e0a\uff0c\u4e00\u5f00\u59cb\u6211\u4ee5\u4e3a\u5bb9\u5668\u5c31\u662f&#8221;\u8f7b\u4e00\u70b9\u7684\u865a\u62df\u673a&#8221;\uff0c\u76f4\u5230\u4e00\u8fde\u4e32\u95ee\u9898\u7528\u540c\u4e00\u79cd\u65b9\u5f0f\u6559\u80b2\u6211\u2014\u2014<strong>\u5bb9\u5668\u5171\u4eab\u5bbf\u4e3b\u5185\u6838\uff0c\u4f60\u4ee5\u4e3a\u7684\u9694\u79bb\u8fb9\u754c\uff0c\u6709\u4e00\u534a\u662f\u5047\u8c61<\/strong>\u3002<\/p>\n<p>\u4e0b\u9762\u4e94\u4e2a\u5751\uff0c\u90fd\u662f\u5728\u8fd9\u5957\u7cfb\u7edf\u4e0a\u5b9e\u9645\u8e29\u51fa\u6765\u7684\uff0c\u4e0d\u662f\u6284\u6765\u7684\u3002<\/p>\n<h3>\u4e00\u3001\u5185\u6838\u662f\u5171\u4eab\u7684\uff0c\u6a21\u5757\u88c5\u4e0d\u8fdb\u53bb<\/h3>\n<p>\u865a\u62df\u673a\u91cc <code>modprobe<\/code> \u968f\u4fbf\u88c5\uff0c\u5bb9\u5668\u91cc\u4e0d\u884c\u3002\u5bb9\u5668\u6ca1\u6709\u81ea\u5df1\u7684\u5185\u6838\uff0c\u5b83\u770b\u5230\u7684 <code>\/lib\/modules<\/code> \u662f\u5bbf\u4e3b\u7684\uff0c\u800c <code>CAP_SYS_MODULE<\/code> \u9ed8\u8ba4\u662f\u6536\u7740\u7684\u3002<\/p>\n<p>\u7b2c\u4e00\u6b21\u649e\u4e0a\u662f\u5728\u5bb9\u5668\u91cc\u60f3\u5f00 <code>overlay<\/code> \u505a\u955c\u50cf\u5c42\u7f13\u5b58\uff1a<\/p>\n<pre class=\"wp-block-code\"><code>\n$ modprobe overlay\nmodprobe: ERROR: could not insert 'overlay': Operation not permitted\n<\/code><\/pre>\n<p>\u89e3\u6cd5\u4e0d\u662f\u52a0\u6743\u9650\uff0c\u662f<strong>\u63d0\u524d\u5728\u5bbf\u4e3b\u4e0a\u786e\u8ba4\u6a21\u5757\u5df2\u52a0\u8f7d<\/strong>\uff1a<\/p>\n<pre class=\"wp-block-code\"><code>\n# \u5bbf\u4e3b\u673a\u6267\u884c\nlsmod | grep -E 'overlay|nf_tables'\n<\/code><\/pre>\n<p>\u540c\u7406\uff0c\u5bb9\u5668\u91cc\u7684 iptables \u80fd\u4e0d\u80fd\u7528\uff0c\u53d6\u51b3\u4e8e\u5bbf\u4e3b\u5185\u6838\u7f16\u4e86\u54ea\u5957\u540e\u7aef\u3002\u5bbf\u4e3b\u7528 <code>nf_tables<\/code>\uff0c\u5bb9\u5668\u91cc\u7684\u8001 <code>iptables-legacy<\/code> \u5c31\u4f1a\u62a5 <code>can't initialize iptables table<\/code>\u3002\u8fd9\u7c7b\u95ee\u9898\u6392\u67e5\u65b9\u5411\u6c38\u8fdc\u662f\u300c\u5f80\u4e0a\u627e\u4e00\u5c42\u300d\uff0c\u4e0d\u662f\u300c\u5f80\u4e0b\u52a0\u53c2\u6570\u300d\u3002<\/p>\n<h3>\u4e8c\u3001systemd \u4e0d\u662f\u6807\u914d\uff0ctimer \u8981\u7559\u9000\u8def<\/h3>\n<p>\u6211\u4eec\u7684\u5bb9\u5668\u8981\u505a\u4e00\u4ef6\u4e8b\uff1a\u6bcf 10 \u5206\u949f\u4e0a\u62a5\u4e00\u6b21\u81ea\u8eab\u4fe1\u606f\u3002\u65b9\u6848\u5f88\u81ea\u7136\u2014\u2014\u88c5\u4e2a systemd timer\u3002<\/p>\n<p>\u95ee\u9898\u5728\u4e8e\uff0c\u6a21\u677f\u5bb9\u5668\u4e0d\u4e00\u5b9a\u5e26 systemd\u3002\u6709\u4e9b\u7cbe\u7b80\u955c\u50cf\u7684 PID 1 \u662f <code>bash<\/code> \u6216\u8005 <code>tini<\/code>\uff0c<code>systemctl<\/code> \u76f4\u63a5\u4e0d\u5b58\u5728\u3002\u811a\u672c\u7b2c\u4e00\u5929\u5728 A \u673a\u5668\u8dd1\u5f97\u597d\u597d\u7684\uff0c\u6362\u5230 B \u673a\u5668\u5c31\u9759\u9ed8\u4e0d\u6267\u884c\uff0c\u65e5\u5fd7\u91cc\u4e00\u4e2a\u5b57\u90fd\u6ca1\u6709\u3002<\/p>\n<p>\u73b0\u5728\u7684\u521d\u59cb\u5316\u811a\u672c\u6539\u6210\u4e24\u6bb5\u5f0f\uff1a<\/p>\n<pre class=\"wp-block-code\"><code>\nif command -v systemctl &gt;\/dev\/null 2&gt;&amp;1 &amp;&amp; [ -d \/run\/systemd\/system ]; then\n    install -m 644 lihua-report.service \/etc\/systemd\/system\/\n    install -m 644 lihua-report.timer   \/etc\/systemd\/system\/\n    systemctl daemon-reload &amp;&amp; systemctl enable --now lihua-report.timer\nelse\n    # \u9000\u56de cron\uff0c\u6ce8\u610f\u5bb9\u5668\u91cc cron \u4e5f\u672a\u5fc5\u5728\u8dd1\n    ( crontab -l 2&gt;\/dev\/null; echo \"*\/10 * * * * \/usr\/local\/bin\/lihua-report.sh\" ) | crontab -\n    pgrep -x cron &gt;\/dev\/null || (service cron start || \/etc\/init.d\/cron start) 2&gt;\/dev\/null\nfi\n<\/code><\/pre>\n<p>\u5224\u65ad <code>[ -d \/run\/systemd\/system ]<\/code> \u6bd4 <code>command -v systemctl<\/code> \u66f4\u53ef\u9760\u2014\u2014\u6709\u4e9b\u955c\u50cf\u88c5\u7740 systemctl \u4e8c\u8fdb\u5236\uff0c\u4f46\u6ca1\u771f\u7684\u4ee5 systemd \u542f\u52a8\u3002<\/p>\n<h3>\u4e09\u3001\u5185\u5b58\u548c CPU \u770b\u5230\u7684\u662f\u5bbf\u4e3b\u7684\u8138<\/h3>\n<p>\u5bb9\u5668\u91cc\u7684 <code>\/proc\/meminfo<\/code>\u3001<code>\/proc\/cpuinfo<\/code> \u9ed8\u8ba4\u663e\u793a<strong>\u5bbf\u4e3b<\/strong>\u7684\u6570\u636e\uff0c\u4e0d\u662f\u914d\u989d\u3002\u8fd9\u76f4\u63a5\u5751\u4e86\u6211\u4eec\u7684 Lynis \u5de1\u68c0\uff1a\u5728\u4e00\u53f0 1G \u5185\u5b58\u7684\u5bb9\u5668\u91cc\uff0cLynis \u8bfb\u5230\u5bbf\u4e3b\u6709 64G\uff0c\u5224\u5b9a\u5185\u5b58\u5145\u8db3\uff0c\u7ed9\u51fa\u4e00\u4e2a\u6f02\u4eae\u4f46\u6beb\u65e0\u610f\u4e49\u7684\u5206\u6570\u3002<\/p>\n<p>\u8981\u8ba9\u5b83\u770b\u5230\u771f\u5b9e\u914d\u989d\uff0c\u5f97\u5728\u5bb9\u5668\u914d\u7f6e\u91cc\u6302 lxcfs\uff1a<\/p>\n<pre class=\"wp-block-code\"><code>\nlxc.mount.entry: \/var\/lib\/lxcfs\/proc\/meminfo proc\/meminfo none bind,ro,create=file 0 0\nlxc.mount.entry: \/var\/lib\/lxcfs\/proc\/cpuinfo proc\/cpuinfo none bind,ro,create=file 0 0\n<\/code><\/pre>\n<p>\u6ca1\u6302 lxcfs \u4e4b\u524d\uff0c\u4efb\u4f55&#8221;\u5bb9\u5668\u5185\u8d44\u6e90\u91c7\u96c6&#8221;\u7c7b\u7684\u529f\u80fd\u90fd\u4e0d\u53ef\u4fe1\u3002\u8fd9\u6761\u7ecf\u9a8c\u540e\u6765\u88ab\u5199\u8fdb\u4e86\u4e0a\u62a5\u811a\u672c\u7684\u5b57\u6bb5\u8bf4\u660e\u91cc\u3002<\/p>\n<h3>\u56db\u3001\u6269\u5bb9\u8981\u4e24\u5934\u505a<\/h3>\n<p>\u7ed9\u5bb9\u5668\u52a0\u78c1\u76d8\uff0c\u53ea\u505a\u4e00\u6b65\u662f\u4e0d\u591f\u7684\uff1a<\/p>\n<pre class=\"wp-block-code\"><code>\n# \u5bbf\u4e3b\u4fa7\uff1a\u628a\u865a\u62df\u76d8\u6491\u5927\npct resize 212 rootfs +10G\n\n# \u5bb9\u5668\u4fa7\uff1a\u6587\u4ef6\u7cfb\u7edf\u5f97\u81ea\u5df1\u957f\nresize2fs \/dev\/mapper\/pve-vm--212--disk--0\n<\/code><\/pre>\n<p>\u53ea\u505a\u7b2c\u4e00\u6b65\uff0c<code>df -h<\/code> \u7eb9\u4e1d\u4e0d\u52a8\uff0c\u7528\u6237\u4f1a\u4ee5\u4e3a\u4f60\u6ca1\u5904\u7406\u3002\u65e9\u671f\u6709\u8fc7\u4e00\u6b21\u5de5\u5355\uff0c\u7528\u6237\u8bf4&#8221;\u6269\u5bb9\u4e86\u4f46\u8fd8\u662f\u6ee1\u7684&#8221;\uff0c\u67e5\u4e0b\u6765\u662f\u7b2c\u4e8c\u6b65\u6f0f\u4e86\u3002<\/p>\n<p>\u5982\u679c\u662f LVM-thin\uff0c\u8fd8\u5f97\u6ce8\u610f <code>pct resize<\/code> \u4e4b\u540e thin pool \u7684\u5269\u4f59\u7a7a\u95f4\uff0c<code>lvs<\/code> \u91cc <code>Data%<\/code> \u8d85\u8fc7 85% \u5c31\u8be5\u505c\u4e86\u3002<\/p>\n<h3>\u4e94\u3001\u7f51\u7edc\u90a3\u4e00\u534a\u5728\u5bbf\u4e3b\u8eab\u4e0a<\/h3>\n<p>\u5bb9\u5668\u91cc\u7684 <code>eth0<\/code> \u662f <code>veth<\/code> \u7684\u4e00\u7aef\uff0c\u53e6\u4e00\u7aef\u5728\u5bbf\u4e3b\u4e0a\u3002\u8fd9\u610f\u5473\u7740\uff1a<\/p>\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th>\u60f3\u505a\u7684\u4e8b<\/th>\n<th>\u5728\u54ea\u4e00\u4fa7\u505a<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u6539 IP \/ \u7f51\u5173<\/td>\n<td>\u5bb9\u5668\u5185 <code>\/etc\/network\/interfaces<\/code> \u6216 netplan<\/td>\n<\/tr>\n<tr>\n<td>\u6293\u5305\u770b\u771f\u5b9e\u6d41\u91cf<\/td>\n<td>\u5bbf\u4e3b\u4e0a\u7684 <code>vethXXX<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u9650\u901f<\/td>\n<td>\u5bbf\u4e3b <code>tc<\/code>\uff0c\u5bb9\u5668\u91cc\u65e0\u6548<\/td>\n<\/tr>\n<tr>\n<td>\u770b\u5bf9\u7aef MAC<\/td>\n<td>\u5bbf\u4e3b <code>ip link<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u9632\u706b\u5899<\/td>\n<td>\u4e24\u5934\u90fd\u53ef\u80fd\u6709\uff0c\u7406\u6e05\u54ea\u5c42\u5148\u751f\u6548<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>\u6211\u4eec\u505a\u591a\u79df\u6237\u9694\u79bb\u65f6\u6700\u8d39\u52b2\u7684\u5c31\u662f\u8fd9\u4e00\u5c42\u2014\u2014\u5bb9\u5668\u91cc\u5199\u7684\u89c4\u5219\u611f\u89c9\u751f\u6548\u4e86\uff0c\u5b9e\u9645\u6d41\u91cf\u5728\u5bbf\u4e3b\u90a3\u4fa7\u5c31\u5df2\u7ecf\u88ab\u653e\u884c\u6216\u4e22\u5f03\u3002\u6392\u67e5\u65f6\u5148 <code>ip link<\/code> \u5728\u5bbf\u4e3b\u627e\u5230\u5bf9\u5e94\u7684 <code>veth<\/code>\uff0c\u518d <code>tcpdump -i vethXXX<\/code>\uff0c\u6bd4\u5728\u5bb9\u5668\u91cc\u731c\u5feb\u5341\u500d\u3002<\/p>\n<h3>\u4ec0\u4e48\u65f6\u5019\u8be5\u7528 KVM<\/h3>\n<p>\u4e0d\u662f\u6240\u6709\u4e1a\u52a1\u90fd\u9002\u5408\u5bb9\u5668\u3002\u5224\u65ad\u6807\u51c6\u5f88\u6734\u7d20\uff1a<\/p>\n<ul>\n<li><strong>\u9700\u8981\u72ec\u7acb\u5185\u6838<\/strong>\uff08\u81ea\u5b9a\u4e49\u6a21\u5757\u3001\u7279\u5b9a\u5185\u6838\u7248\u672c\u3001eBPF \u91cd\u5ea6\u4f7f\u7528\uff09\u2192 KVM<\/li>\n<li><strong>\u9700\u8981\u5d4c\u5957\u865a\u62df\u5316<\/strong>\uff08\u91cc\u9762\u8fd8\u8981\u8dd1 Docker \u7684 Docker\uff09\u2192 KVM\uff0c\u6216\u8005\u81f3\u5c11\u5f00 <code>nesting=1<\/code> \u5e76\u63a5\u53d7\u6027\u80fd\u635f\u5931<\/li>\n<li><strong>\u8d44\u6e90\u9694\u79bb\u8981\u6c42\u786c<\/strong>\uff08\u9632\u90bb\u5c45\u5435\u95f9\uff09\u2192 KVM\uff0c\u5bb9\u5668\u5171\u4eab\u5185\u6838\u8c03\u5ea6\uff0ccgroup \u53ea\u80fd\u7f13\u89e3\u4e0d\u80fd\u6d88\u706d<\/li>\n<li><strong>\u53ea\u662f\u8dd1\u4e2a Web \u670d\u52a1\u3001\u5b9a\u65f6\u4efb\u52a1\u3001\u8f7b\u91cf\u6570\u636e\u5e93<\/strong> \u2192 LXC\uff0c\u542f\u52a8\u5feb\u3001\u5185\u5b58\u7701\u3001\u5907\u4efd\u5c0f<\/li>\n<\/ul>\n<p>\u6211\u4eec\u73b0\u5728\u7684\u505a\u6cd5\u662f\u5206\u5c42\uff1a\u63a7\u5236\u53f0\u548c\u6570\u636e\u5e93\u8dd1 LXC\uff0c\u9700\u8981\u8dd1\u5d4c\u5957\u5bb9\u5668\u7684\u7528\u6237\u673a\u5668\u7528 KVM\u3002\u6df7\u5408\u90e8\u7f72\u7684\u4ee3\u4ef7\u662f\u4e24\u5957\u76d1\u63a7\u548c\u4e24\u5957\u5907\u4efd\u7b56\u7565\uff0c\u4f46\u6bd4\u5f3a\u884c\u7edf\u4e00\u8981\u7701\u5fc3\u3002<\/p>\n<h3>\u4e00\u53e5\u8bdd\u603b\u7ed3<\/h3>\n<p>\u5bb9\u5668\u7684\u95ee\u9898\u51e0\u4e4e\u90fd\u80fd\u5f52\u7eb3\u6210\u540c\u4e00\u53e5\uff1a<strong>\u4f60\u5728\u91cc\u9762\u770b\u5230\u7684\u4e1c\u897f\uff0c\u6765\u6e90\u5728\u5916\u9762<\/strong>\u3002\u9047\u5230\u602a\u73b0\u8c61\uff0c\u5148\u5f80\u4e0a\u627e\u4e00\u5c42\u2014\u2014\u5bbf\u4e3b\u5185\u6838\u3001\u5bbf\u4e3b cgroup\u3001\u5bbf\u4e3b\u7f51\u7edc\u3001\u5bbf\u4e3b\u5b58\u50a8\u3002\u8fd9\u4e00\u6761\u6bd4\u4efb\u4f55\u5177\u4f53\u547d\u4ee4\u90fd\u503c\u94b1\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>LXC \u4e0d\u662f\u5c0f\u53f7\u865a\u62df\u673a\uff1a\u4e94\u4e2a\u5728\u5bb9\u5668\u91cc\u771f\u649e\u8fc7\u7684\u8fb9\u754c \u6258\u7ba1\u4e1a\u52a1\u8dd1\u5728 PVE \u7684 LXC \u4e0a\uff0c\u4e00\u5f00\u59cb\u6211\u4ee5\u4e3a\u5bb9\u5668\u5c31\u662f&#038;#\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-75","post","type-post","status-publish","format-standard","hentry","category-cat-e68a80e69cafe697"],"_links":{"self":[{"href":"https:\/\/www.woiov.cn\/index.php?rest_route=\/wp\/v2\/posts\/75","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.woiov.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.woiov.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.woiov.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.woiov.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=75"}],"version-history":[{"count":0,"href":"https:\/\/www.woiov.cn\/index.php?rest_route=\/wp\/v2\/posts\/75\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.woiov.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=75"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.woiov.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=75"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.woiov.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}