OpenVZ:限制每个 VE 的 CPU 内核数

TiF*_*olk 5 openvz

有没有办法限制从 VE 内部看到的 CPU 内核数量?我有一个八核服务器,但我希望我的 VE 只能看到一个特定的核心。

谢谢!

Kyl*_*ndt 10

如果 vz 的编号为 101,则使用以下命令将其设置为两个 2 CPU(相应地更改编号):

vzctl set 101 --cpus 2 --save
Run Code Online (Sandbox Code Playgroud)

无需重新启动 VE。这--save使得当 VE 重新启动时,更改仍然存在。 vzctl --help对于可以设置的其他资源。


3di*_*nce 6

OpenVZ 并不是真正的虚拟化。这是容器化。因此,每个容器都将其所在的系统视为自己的系统。要控制每个 VE 可以获得多少 cpu 时间,您必须分配每个 VE cpucredits本页介绍如何设置每个 VE 的限制。

编辑:刚刚在 vzctl 手册页中找到了这个。
--cpulimit num[%] Limit of CPU usage for the VE, in per cent. Note if the computer has 2 CPUs, it has total of 200% CPU time. Default CPU limit is 0 (no CPU limit). --cpus num sets number of CPUs available in the VE.

所以凯尔的回答是正确的。但我会把这个答案留在这里 b/c 这里有不止一个 nob 需要调整。