use*_*780 13 cpu process cpanel
我正在运行 centos、cpanel/whm,并且安装了 cpulimit。
我遇到的问题是我的一个用户使用了大量的 CPU。始终超过 100%,这使我的服务器变慢。
进一步的问题是他们是朋友而不是恶意的,所以我不想暂停他们。
还有一个问题是我不能通过进程来限制它,因为这个进程每秒都在变化。每次都是不同的过程。
我尝试了以下但它不起作用。
cpulimit -l 10 -e /home/[username]/public_html/theirwebsite.org/index.php
Run Code Online (Sandbox Code Playgroud)
我刚回来,
No process found
No process found
No process found
No process found
No process found
No process found
Run Code Online (Sandbox Code Playgroud)
等等
有两件事正在使用这种极端的 CPU 使用率。
首先是那个位置的文件,index.php
. 另一个是 [php],无论在 WHM 中意味着什么。但主要index.php
是问题所在。
如果我可以将该index.php
文件限制在该位置,则可能有助于缓解此问题。
顺便说一句,我尝试了该-P
标志,但与文档不同,它不能作为选项使用。
cpulimit -l 10 -P /home/[username]/public_html/theirwebsite.org/index.php
Run Code Online (Sandbox Code Playgroud)
返回
cpulimit: invalid option -- 'P'
Usage: cpulimit [OPTIONS...] TARGET
OPTIONS
-l, --limit=N percentage of cpu allowed from 0 to 1600 (required)
-v, --verbose show control statistics
-z, --lazy exit if there is no target process, or if it dies
-i, --include-children limit also the children processes
-h, --help display this help and exit
TARGET must be exactly one of these:
-p, --pid=N pid of the process (implies -z)
-e, --exe=FILE name of the executable program file or path name
COMMAND [ARGS] run this command and limit it (implies -z)
Run Code Online (Sandbox Code Playgroud)
所以看起来我必须用-e
旗帜来做。
理想情况下,我想限制整个用户帐户。
是的,我知道 cloudlinux,但我现在不能这样做。在我能做到这一点之前,我需要帮助手动完成一些不需要重启服务器的事情。
Car*_*ein 12
你试过Cgroups吗?
sudo yum install libcgroup
并启动它sudo
service cgconfig start
。sudo ls /cgroup
创建一个名为limitcpu
. 以 group 开头的行创建 cgroup 并设置子系统参数。
示例 /etc/cgconfig.conf:
group limitcpu{
cpu {
cpu.shares = 200;
# cpu.cfs_period_us
# cpu.cfs_quota_us
}
memory {
}
}
Run Code Online (Sandbox Code Playgroud)
对于 CPU 限制,您可以使用几个可调参数来限制明显的 CPU 使用率
如果 cgroup 中的任务应该能够在每 1 秒中访问单个 CPU 0.1 (10%) 秒,请将 cpu.cfs_quota_us 设置为 100000,将 cpu.cfs_period_us 设置为 1000000。
Cgred 是一项服务(启动 cgrulesengd 服务),它根据 /etc/cgrules.conf 文件中设置的参数将任务移动到 cgroup 中。/etc/cgrules.conf 文件中的条目可以采用以下两种形式之一:
user subsystems control_group
user:command subsystems control_group
Run Code Online (Sandbox Code Playgroud)
其中user
以“@”字符为前缀的用户名或组名。替换subsystems
为逗号分隔的子系统名称列表,control_group
代表 cgroup 的路径,command
代表进程名称或进程的完整命令路径。
示例 etc/cgrules.conf:
*:firefox cpu,memory browsers/
@admin:memhog memory limitmem/
cpuhog cpu limitcpu/
Run Code Online (Sandbox Code Playgroud)
firefox
任何用户运行的进程都将自动添加到浏览器中,cgroup
并限制在 CPU 和内存子系统中。
memhog
admin
组中任何人运行的进程将被添加到 cgrouplimitmem
并限制在内存子系统中。
- 您的用户 ,cpuhog
将被添加到 cgroup 'limitcpu' 并限制在 cpu 子系统中。
在提前用例中,您可以尝试使用模板。
例如,在 /etc/cgconfig.conf 中指定以下模板:
template users/%g/%u {
cpuacct{
}
cpu {
cpu.shares = "1000";
}
}
Run Code Online (Sandbox Code Playgroud)
然后使用 /etc/cgrules.conf 条目第三行中的 users/%g/%u 模板,可以如下所示:
peter:ftp cpu users/%g/%u
Run Code Online (Sandbox Code Playgroud)
%g and %u
根据 ftp 进程的所有者,上面使用的变量会自动替换为组和用户名。
如果该进程属于 adminstaff 组的 peter,则将上述路径转换为users/adminstaff/peter
.
然后 cgred 服务搜索这个目录,如果它不存在,cgred 创建它并将进程分配给 users/adminstaff/peter/tasks。
请注意,模板规则仅适用于配置文件中模板的定义,因此即使在 /etc/cgconfig.conf 中定义了“group users/adminstaff/peter”,它也会被忽略以支持“template users/%g/%你”。
你是对的,你不能限制你的朋友使用进程(PID),Apache 会为它收到的每个请求生成一个新进程(Worker),每次都会分配一个新的 PID。
根据您在 中设置的 PHP 处理程序WHM -> MultiPHP Manager -> PHP Handlers
,Apache 将单独运行 PHP 脚本,或者以拥有该文件的用户身份运行它们。如果您使用suPHP
作为处理程序,PHP 进程将由拥有该文件的帐户执行。
如果脚本由所有者执行,您可以通过将其添加到文件来限制帐户的 CPU 使用率/etc/security/limits.conf
。虽然您不能使用它来精确限制 cpu 百分比,但您可以修改它们的“nice”值,以便它们的进程比服务器上的其他进程具有更低的优先级。这样,其他进程就不必等待那么长时间。
我自己从未使用过这个(我运行 CloudLinux),但我相信以下条目应该有助于解决问题:
username hard priority 30
Run Code Online (Sandbox Code Playgroud)
这将用户执行的进程的最大优先级设置为30。据我了解,较高的优先级实际上意味着其他进程(优先级较低)获得更多的CPU时间。
在我运行 cPanel 的服务器上,大多数进程的优先级为 20,因此按照上述逻辑,将该用户的优先级设置为 30 应该允许其他进程在这些进程之前执行。