如何通过cgroup限制apache内存

我想限制用户www-data在Ubuntu Server 14.04 LTS中使用的总内存。 我读过我可以通过cgroups做到这一点。

这是我到目前为止所做的:

 # install apt-get install cgroup-bin # create group for user www-data cgcreate -a 'www-data' -g memory,cpu:'www-data' # validate that the cgroup fs was created ll /sys/fs/cgroup/cpu/www-data ll /sys/fs/cgroup/memory/www-data # adjust cpu and memory echo 100 > /sys/fs/cgroup/cpu/www-data/cpu.shares echo 100000000 > /sys/fs/cgroup/memory/www-data/memory.limit_in_bytes 

怎么办? 如何对用户www-data强制执行这些设置?

编辑:请注意,如果有更好/最好的方法通过其他方式(例如systemd )执行此操作,请建议。

执行该过程的设置会更有意义

 sudo cgexec -g cpu:cpulimited /usr/sbin/apachectl start