{"id":63,"date":"2026-10-23T12:00:44","date_gmt":"2026-10-23T20:00:44","guid":{"rendered":"\/?p=63"},"modified":"2026-10-23T12:00:44","modified_gmt":"2026-10-23T20:00:44","slug":"post-mvkfzoh5","status":"publish","type":"post","link":"https:\/\/www.woiov.cn\/?p=63","title":{"rendered":"\u4e91\u4e3b\u673a\u7f16\u53f7\u7684\u5206\u914d\u54f2\u5b66\uff1a\u4e3a\u4ec0\u4e48\u4e0d\u76f4\u63a5 max+1"},"content":{"rendered":"<p>\u4e91\u4e3b\u673a\u5356\u51fa\u7b2c\u4e00\u53f0\u7684\u65f6\u5019\uff0c\u7f16\u53f7\u8fd9\u4ef6\u4e8b\u6839\u672c\u4e0d\u53eb\u95ee\u9898\u3002\u7b49\u5230\u7b2c\u4e09\u5341\u53f0\u3001\u7b2c\u4e94\u5341\u53f0\uff0c\u56de\u6536\u7684\u53f7\u5f00\u59cb\u548c\u65b0\u5f00\u7684\u53f7\u6324\u5728\u4e00\u8d77\uff0c\u5b83\u5c31\u6210\u4e86\u4e00\u4e2a\u80fd\u8ba9\u4f60\u534a\u591c\u722c\u8d77\u6765\u67e5\u65e5\u5fd7\u7684\u95ee\u9898\u3002<\/p>\n<p>\u72f8\u82b1\u4e91\u7ed9\u6bcf\u53f0\u5bb9\u5668\u5206\u914d ID \u7684\u903b\u8f91\uff0c\u524d\u540e\u6539\u8fc7\u4e09\u6b21\u3002\u73b0\u5728\u8fd9\u5957\u53eb\u300c\u53f7\u6bb5\u6c60\u300d\uff1a<strong>\u4e0d\u53d6\u6700\u5927\u503c\u52a0\u4e00\uff0c\u800c\u662f\u4ece\u8d77\u59cb\u53f7\u5f00\u59cb\u627e\u7b2c\u4e00\u4e2a\u7a7a\u95f2\u53f7\u3002<\/strong><\/p>\n<h3>max+1 \u7684\u4e09\u4e2a\u6bdb\u75c5<\/h3>\n<p>\u6700\u76f4\u89c9\u7684\u505a\u6cd5\u662f <code>max(\u5df2\u7528) + 1<\/code>\u3002\u7b2c\u4e00\u7248\u5c31\u662f\u8fd9\u4e48\u5199\u7684\uff0c\u8dd1\u4e86\u4e0d\u5230\u4e24\u5929\u5c31\u9732\u9985\u3002<\/p>\n<p><strong>\u4e00\u3001\u7f16\u53f7\u53ea\u589e\u4e0d\u51cf\u3002<\/strong> \u7528\u6237\u5220\u4e86\u673a\u5668\uff0c\u53f7\u5c31\u6c38\u8fdc\u7a7a\u5728\u90a3\u91cc\u3002\u5356\u51fa\u53bb\u4e00\u767e\u53f0\u3001\u56de\u6536\u516b\u5341\u53f0\uff0c\u4e0b\u4e00\u53f0\u62ff\u5230\u7684\u8fd8\u662f 101\u3002\u53f7\u6bb5\u8d8a\u957f\uff0c\u8fd0\u7ef4\u8bfb\u65e5\u5fd7\u8d8a\u7d2f\u2014\u2014\u4f60\u6ca1\u6cd5\u9760\u7f16\u53f7\u5224\u65ad&#8221;\u8fd9\u53f0\u673a\u5668\u5927\u6982\u4ec0\u4e48\u65f6\u5019\u5f00\u7684&#8221;\u3002<\/p>\n<p><strong>\u4e8c\u3001\u5e76\u53d1\u4e0b\u4f1a\u649e\u53f7\u3002<\/strong> <code>max+1<\/code> \u662f&#8221;\u5148\u67e5\u518d\u7b97&#8221;\uff0c\u67e5\u5b8c\u5230\u5199\u8fdb\u53bb\u4e4b\u95f4\u6709\u7a97\u53e3\u3002\u4e24\u4e2a\u8ba2\u5355\u540c\u65f6\u8fdb\u6765\uff0c\u90fd\u67e5\u5230 max=57\uff0c\u90fd\u60f3\u62ff 58\u3002\u8fd9\u4e0d\u662f\u7406\u8bba\u98ce\u9669\uff0c\u662f\u5fc5\u7136\u4e8b\u4ef6\u3002<\/p>\n<p><strong>\u4e09\u3001\u53f7\u6bb5\u4e0d\u53ef\u89c4\u5212\u3002<\/strong> \u6211\u4eec\u60f3\u7ed9\u7cfb\u7edf\u9884\u7559 100~199\uff0c\u7ed9\u6258\u7ba1\u5bb9\u5668\u7528 200 \u8d77\u3002<code>max+1<\/code> \u4e0d\u770b\u8fd9\u4e2a\uff0c\u4e00\u4e2a\u6570\u5b57\u4ece 1 \u5f00\u59cb\u5f80\u4e0a\u6da8\uff0c\u8fb9\u754c\u5168\u9760\u8fd0\u6c14\u3002<\/p>\n<h3>\u73b0\u5728\u7684\u5b9e\u73b0<\/h3>\n<p><code>server\/pve.mjs<\/code> \u91cc\u7684 <code>nextVmid<\/code>\uff1a<\/p>\n<pre class=\"wp-block-code\"><code>\nasync nextVmid(startFrom = 200, reserved = [], poolEnd = 999) {\n  const list = await this.guests().catch(() =&gt; [])\n  const used = new Set(list.map(g =&gt; parseInt(g.vmid, 10))\n                         .filter(n =&gt; Number.isFinite(n)))\n  for (const r of reserved || []) {\n    const n = parseInt(r, 10)\n    if (Number.isFinite(n)) used.add(n)\n  }\n  const start = Math.max(100, parseInt(startFrom, 10) || 200)\n  for (let v = start; v &lt;= poolEnd; v++) {\n    if (!used.has(v)) return String(v)\n  }\n  \/\/ \u53f7\u6bb5\u7528\u6ee1\uff1a\u9000\u56de PVE \u81ea\u5df1\u7684 nextid\uff0c\u4e0d\u786c\u6491\n  try {\n    const pveNext = parseInt(String(await api('\/cluster\/nextid')).trim(), 10)\n    if (Number.isFinite(pveNext)) return String(Math.max(pveNext, poolEnd + 1))\n  } catch (e) { \/* ignore *\/ }\n  return String(poolEnd + 1)\n}\n<\/code><\/pre>\n<p>\u4e09\u4e2a\u8bbe\u8ba1\u70b9\u3002<\/p>\n<p><strong>\u6700\u5c0f\u7a7a\u95f2\u53f7\uff08first-fit\uff09\u3002<\/strong> \u56de\u6536\u7684\u53f7\u7acb\u523b\u80fd\u518d\u7528\uff0c\u7f16\u53f7\u59cb\u7ec8\u7d27\u51d1\u5730\u805a\u5728 200~250 \u8fd9\u79cd\u533a\u95f4\u91cc\u3002\u4ee3\u4ef7\u662f\u53f7\u4f1a\u88ab\u590d\u7528\u2014\u2014\u8fd9\u5c31\u5f15\u51fa\u4e0b\u4e00\u4e2a\u95ee\u9898\u3002<\/p>\n<p><strong><code>reserved<\/code> \u4e0d\u662f\u53ef\u9009\u53c2\u6570\uff0c\u662f\u5b89\u5168\u8fb9\u754c\u3002<\/strong> \u53f7\u590d\u7528\u7684\u771f\u6b63\u5371\u9669\u4e0d\u5728\u7f16\u53f7\u672c\u8eab\uff0c\u5728\u4e8e\u65e7\u53f7\u4e0a\u53ef\u80fd\u8fd8\u6302\u7740\u4e1c\u897f\uff1a\u65e7\u8ba2\u5355\u3001\u65e7\u6388\u6743\u3001\u65e7\u8d26\u5355\u8bb0\u5f55\u3002\u5982\u679c PVE \u91cc\u5bb9\u5668\u5220\u4e86\u5c31\u5f53\u53f7\u7a7a\u95f2\uff0c\u4e0b\u4e00\u53f0\u65b0\u5bb9\u5668\u4f1a\u9876\u7740\u540c\u4e00\u4e2a vmid \u7ee7\u627f\u90a3\u4e9b&#8221;\u5c5e\u4e8e\u4e0a\u4e00\u4e2a\u7528\u6237&#8221;\u7684\u5f15\u7528\u3002\u6240\u4ee5\u5df2\u5360\u7528\u7684\u96c6\u5408\u5fc5\u987b\u662f <strong>PVE \u5b9e\u9645\u5bb9\u5668 \u222a \u672a\u7ec8\u7ed3\u8ba2\u5355\u91cc\u5f15\u7528\u7684\u53f7<\/strong>\u3002<\/p>\n<p><strong>\u53f7\u6bb5\u7528\u6ee1\u4e0d\u9000\u5316\u6210\u6b7b\u5faa\u73af\u3002<\/strong> 200~999 \u6ee1\u4e86\u5c31\u8c03 <code>\/cluster\/nextid<\/code> \u62ff\u53f7\uff0c\u4ece\u6c60\u5916\u7ee7\u7eed\u3002\u5b81\u53ef\u7f16\u53f7\u8df3\u51fa\u53bb\uff0c\u4e5f\u4e0d\u80fd\u8ba9\u4e0b\u5355\u6d41\u7a0b\u5361\u6b7b\u5728\u4e00\u4e2a\u7a7a\u6c60\u5b50\u4e0a\u3002<\/p>\n<h3>\u54ea\u4e9b\u8ba2\u5355\u7684\u53f7\u53ef\u4ee5\u56de\u6536<\/h3>\n<p>\u8fd9\u5f20\u8868\u662f\u6574\u4e2a\u903b\u8f91\u91cc\u6700\u5bb9\u6613\u5199\u9519\u7684\u5730\u65b9\uff0c\u5199\u53cd\u4e86\u5c31\u662f\u6570\u636e\u8d8a\u754c\uff1a<\/p>\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th>\u8ba2\u5355\u72b6\u6001<\/th>\n<th>\u53f7\u662f\u5426\u4fdd\u7559<\/th>\n<th>\u7406\u7531<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>pending<\/code><\/td>\n<td>\u4fdd\u7559<\/td>\n<td>\u7528\u6237\u5df2\u4e0b\u5355\uff0c\u5bb9\u5668\u53ef\u80fd\u6b63\u5728\u521b\u5efa<\/td>\n<\/tr>\n<tr>\n<td><code>paid<\/code><\/td>\n<td>\u4fdd\u7559<\/td>\n<td>\u94b1\u5230\u4e86\uff0c\u53f7\u5df2\u7ecf\u82b1\u51fa\u53bb<\/td>\n<\/tr>\n<tr>\n<td><code>provisioning<\/code><\/td>\n<td>\u4fdd\u7559<\/td>\n<td>\u6b63\u5728\u4ea4\u4ed8\u4e2d\uff0c\u6b64\u65f6\u590d\u7528\u4f1a\u76f4\u63a5\u8e29\u6389\u6b63\u5728\u521b\u5efa\u7684\u4efb\u52a1<\/td>\n<\/tr>\n<tr>\n<td><code>active<\/code><\/td>\n<td>\u4fdd\u7559<\/td>\n<td>\u673a\u5668\u5728\u8dd1<\/td>\n<\/tr>\n<tr>\n<td><code>failed<\/code><\/td>\n<td><strong>\u4fdd\u7559<\/strong><\/td>\n<td>\u4ea4\u4ed8\u5931\u8d25\u4f46\u5bb9\u5668\u53ef\u80fd\u5df2\u5efa\u6210\uff0c\u9700\u8981\u4eba\u5de5\u6838\u5bf9<\/td>\n<\/tr>\n<tr>\n<td><code>cancelled<\/code><\/td>\n<td>\u53ef\u56de\u6536<\/td>\n<td>\u5bb9\u5668\u5df2\u9500\u6bc1<\/td>\n<\/tr>\n<tr>\n<td><code>refunded<\/code><\/td>\n<td>\u53ef\u56de\u6536<\/td>\n<td>\u540c\u4e0a<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>\u6211\u4eec\u53ea\u628a <code>cancelled<\/code> \u548c <code>refunded<\/code> \u653e\u884c\uff0c\u5176\u4f59\u5168\u90e8\u4fdd\u7559\u3002<code>failed<\/code> \u5c24\u5176\u4e0d\u80fd\u653e\u2014\u2014\u5931\u8d25\u4e0d\u7b49\u4e8e\u6ca1\u521b\u5efa\uff0cPVE \u90a3\u8fb9\u7684\u5bb9\u5668\u53ef\u80fd\u8fd8\u5728\uff0c\u53ea\u662f\u6211\u4eec\u7684\u6d41\u7a0b\u6ca1\u8d70\u5b8c\u3002\u8fd9\u6761\u89c4\u5219\u5b81\u53ef\u4fdd\u5b88\uff1a\u591a\u7559\u51e0\u4e2a\u53f7\u4e0d\u7b97\u6d6a\u8d39\uff0c\u9519\u6740\u4e00\u4e2a\u53f7\u5c31\u662f\u628a\u522b\u4eba\u7684\u673a\u5668\u62c6\u4e86\u3002<\/p>\n<h3>\u591a\u8282\u70b9\u4e4b\u540e\u5192\u51fa\u6765\u7684\u65b0\u95ee\u9898<\/h3>\n<p>\u4ee3\u7801\u91cc\u6709\u8fd9\u4e48\u4e00\u884c\uff1a<\/p>\n<pre class=\"wp-block-code\"><code>\nif (nodeId &amp;&amp; it.nodeId &amp;&amp; it.nodeId !== nodeId) continue\n<\/code><\/pre>\n<p>\u591a\u8282\u70b9\u73af\u5883\u4e0b\uff0c\u53f7\u6bb5\u662f\u6309\u8282\u70b9\u72ec\u7acb\u7684\u2014\u2014node1 \u4e0a\u7684 201 \u548c node2 \u4e0a\u7684 201 \u662f\u4e24\u53f0\u4e0d\u540c\u673a\u5668\uff0c\u4e92\u4e0d\u5f71\u54cd\u3002\u56e0\u4e3a\u8fd9\u51e0\u53f0 PVE \u662f\u72ec\u7acb\u5b89\u88c5\u7684\uff0c\u6ca1\u6709\u7ec4\u6210\u96c6\u7fa4\u3002<\/p>\n<p><strong>\u8fd9\u91cc\u6709\u4e2a\u524d\u63d0\u5fc5\u987b\u5199\u6e05\u695a\uff1a\u4e00\u65e6\u628a\u591a\u53f0 PVE \u52a0\u8fdb\u540c\u4e00\u4e2a\u96c6\u7fa4\uff0c\u8fd9\u884c\u8fc7\u6ee4\u5c31\u662f\u9519\u7684\u3002<\/strong> \u96c6\u7fa4\u5185 vmid \u662f\u5168\u5c40\u552f\u4e00\u7684\uff0c\u6b64\u65f6\u8fd8\u6309\u8282\u70b9\u53bb\u91cd\uff0c\u4e24\u53f0\u8282\u70b9\u540c\u65f6\u5f00\u5bb9\u5668\u5c31\u4f1a\u649e\u540c\u4e00\u4e2a\u53f7\u3002\u771f\u5230\u90a3\u4e00\u6b65\uff0c<code>reserved<\/code> \u8981\u6539\u6210\u5168\u96c6\u7fa4\u6536\u96c6\uff0c\u8fc7\u6ee4\u903b\u8f91\u6574\u6bb5\u5220\u6389\u3002\u8fd9\u7c7b&#8221;\u73b0\u5728\u5bf9\u3001\u6761\u4ef6\u53d8\u4e86\u5c31\u9519&#8221;\u7684\u4ee3\u7801\uff0c\u6700\u597d\u50cf\u6ce8\u91ca\u4e00\u6837\u5199\u5728\u539f\u5730\u2014\u2014\u4e0d\u7136\u534a\u5e74\u540e\u63a5\u624b\u7684\u4eba\u53ea\u4f1a\u770b\u5230\u4e00\u884c\u83ab\u540d\u5176\u5999\u7684 <code>continue<\/code>\u3002<\/p>\n<h3>\u8fd8\u6ca1\u89e3\u51b3\u7684\uff1a\u7ade\u6001<\/h3>\n<p>\u8bda\u5b9e\u4e00\u70b9\uff0c\u8fd9\u5957\u73b0\u5728\u4ecd\u6709\u7a97\u53e3\u671f\u3002<code>nextVmid<\/code> \u662f&#8221;\u67e5\u2014\u7b97\u2014\u7528&#8221;\u4e09\u6b65\uff0c\u4e0d\u662f\u539f\u5b50\u64cd\u4f5c\u3002\u4e24\u4e2a\u8ba2\u5355\u51e0\u4e4e\u540c\u65f6\u8fdb\u6765\uff0c\u7406\u8bba\u4e0a\u80fd\u7b97\u51fa\u540c\u4e00\u4e2a\u53f7\uff0c\u7136\u540e\u5728 <code>createLxc<\/code> \u9636\u6bb5\u88ab PVE \u4ee5&#8221;vmid \u5df2\u5b58\u5728&#8221;\u9876\u56de\u6765\u3002<\/p>\n<p>\u76ee\u524d\u9760\u7684\u662f\u649e\u53f7\u540e\u521b\u5efa\u5931\u8d25\u3001\u8ba2\u5355\u8fdb <code>failed<\/code> \u8ba9\u4eba\u5de5\u4ecb\u5165\u2014\u2014\u4e0d\u4f18\u96c5\uff0c\u4f46\u81f3\u5c11\u4e0d\u4f1a\u9759\u9ed8\u51fa\u9519\u3002\u8981\u771f\u6b63\u89e3\u51b3\u5f97\u52a0\u4e00\u628a\u6309\u8282\u70b9\u7684\u4e92\u65a5\u9501\uff0c\u628a\u5206\u914d\u548c\u521b\u5efa\u4e32\u8d77\u6765\u3002\u8fd9\u4e8b\u8bb0\u5728\u5f85\u529e\u91cc\u4e86\uff0c\u8fd8\u6ca1\u505a\u3002<\/p>\n<p>\u7f16\u53f7\u8fd9\u79cd\u4e8b\uff0c\u7528\u6237\u4e00\u8f88\u5b50\u4e0d\u4f1a\u6ce8\u610f\u5230\u3002\u5b83\u505a\u5bf9\u4e86\u662f\u9690\u5f62\u7684\uff0c\u505a\u9519\u4e86\u662f\u6570\u636e\u4e8b\u6545\u3002\u6240\u4ee5\u6211\u4eec\u628a\u5b83\u5f53\u5b89\u5168\u8fb9\u754c\u6765\u5199\uff0c\u4e0d\u5f53\u6210\u8ba1\u6570\u5668\u6765\u5199\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e91\u4e3b\u673a\u5356\u51fa\u7b2c\u4e00\u53f0\u7684\u65f6\u5019\uff0c\u7f16\u53f7\u8fd9\u4ef6\u4e8b\u6839\u672c\u4e0d\u53eb\u95ee\u9898\u3002\u7b49\u5230\u7b2c\u4e09\u5341\u53f0\u3001\u7b2c\u4e94\u5341\u53f0\uff0c\u56de\u6536\u7684\u53f7\u5f00\u59cb\u548c\u65b0\u5f00\u7684\u53f7\u6324\u5728\u4e00\u8d77\uff0c\u5b83\u5c31\u6210\u4e86\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-63","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\/63","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=63"}],"version-history":[{"count":0,"href":"https:\/\/www.woiov.cn\/index.php?rest_route=\/wp\/v2\/posts\/63\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.woiov.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=63"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.woiov.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=63"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.woiov.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}