- A+
所属分类:系统管理
安装EPEL源,这博客啥都有,查看之前文章。
安装cpulimit
1 |
# yum install cpulimit |
使用cpulimit进行cpu利用率限制
1. 先了解一下cpulimit的参数
1 2 3 4 5 6 7 8 9 10 11 12 |
# cpulimit -h Usage: cpulimit [OPTIONS...] TARGET OPTIONS -l, --limit=N percentage of cpu allowed from 0 to 100 (required)//cpu限制的百分比 -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) //进程的pid -e, --exe=FILE name of the executable program file or path name //可执行程序 COMMAND [ARGS] run this command and limit it (implies -z) |
2. 根据进程ID限值
1 |
# cpulimit -p 1234 -l 40 |
此命令的含义为,限制pid号为1234的进程,最高只能使用40%的cpu。
3. 根据进程路径限制
1 |
# cpulimit -e /usr/local/nginx-1.4.1/sbin/nginx -l 50 |
限制nginx程序只能使用最高50%的cpu。
注意事项
- -l后面限制的cpu使用量,要根据实际的核心数量而成倍减少。比如上文中的进程1234,40%的限制生效在1核服务器中,如果是双核服务器,则应该限制到20%,四核服务器限制到10%以此类推。
- root用户可以限制所有的进程,普通用户只能限制自己有权限管理的进程。

微信公众号
扫一扫关注运维生存时间公众号,获取最新技术文章~