<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Cgroup - 标签 - CYBER ZEN</title><link>https://hex2rgb.github.io/tags/cgroup/</link><description>Cgroup - 标签 - CYBER ZEN</description><generator>Hugo -- gohugo.io</generator><language>zh-CN</language><lastBuildDate>Wed, 16 Sep 2026 10:00:00 +0800</lastBuildDate><atom:link href="https://hex2rgb.github.io/tags/cgroup/" rel="self" type="application/rss+xml"/><item><title>Docker 容器全局资源限制方案（systemd slice + cgroup v2）</title><link>https://hex2rgb.github.io/posts/docker-cgroup-slice-global-limit/</link><pubDate>Wed, 16 Sep 2026 10:00:00 +0800</pubDate><author>Cyber Zen</author><guid>https://hex2rgb.github.io/posts/docker-cgroup-slice-global-limit/</guid><description><![CDATA[<h1 id="docker-容器全局资源限制方案systemd-slice--cgroup-v2">Docker 容器全局资源限制方案（systemd slice + cgroup v2）</h1>
<blockquote>
<p><strong>环境</strong>：Ubuntu 22.04 / systemd 249 / cgroup v2 / 8C 8T / 16G 物理内存 / 4G Swap / 1Panel 物理机部署
<strong>目标</strong>：所有容器合计硬上限 CPU=6.5 核、内存=14.5G，容器间弹性抢占，不逐个设置 <code>--cpus</code> / <code>--memory</code>，保护宿主机不因容器内存耗尽而宕机。</p>
</blockquote>
<hr>
<h2 id="一最终参数">一、最终参数</h2>
<table>
  <thead>
      <tr>
          <th>资源</th>
          <th>宿主机总量</th>
          <th>容器上限</th>
          <th>宿主机保留</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>CPU</td>
          <td>8 逻辑核</td>
          <td>6.5 核（650%）</td>
          <td>1.5 核</td>
      </tr>
      <tr>
          <td>物理内存</td>
          <td>16G</td>
          <td>14.5G</td>
          <td>1.5G</td>
      </tr>
      <tr>
          <td>Swap</td>
          <td>4G</td>
          <td>0</td>
          <td>4G</td>
      </tr>
  </tbody>
</table>
<blockquote>
<p><strong>说明</strong>：14.5G 是较激进的取值。若实际运行中 1Panel 响应变慢或 SSH 卡顿，建议下调至 14G（宿主机保留 2G），只损失 0.5G 容器额度，稳定性明显提升。</p>
</blockquote>
<hr>
<h2 id="二前置检查">二、前置检查</h2>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="复制到剪贴板"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># 1. systemd 版本（MemoryMax 需 ≥ 231，MemorySwapMax 需 ≥ 232）</span>
</span></span><span class="line"><span class="cl">systemd --version
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># 2. cgroup 版本（应为 cgroup2fs）</span>
</span></span><span class="line"><span class="cl">stat -fc %T /sys/fs/cgroup/
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># 3. Docker cgroup driver（需为 systemd）</span>
</span></span><span class="line"><span class="cl">sudo docker info <span class="p">|</span> grep -i cgroup</span></span></code></pre></div></div>
<p>本环境结果：</p>]]></description></item></channel></rss>