1.limit memery
以root身份登陆
echo "app hard rss 2097152" >> /etc/security/limits.conf
echo "#Sets up app user limits according to /etc/security/limits.conf" >/etc/pam.d/login
echo "session required pam_limits.so" > /etc/pam.d/login
登陆app的账户,检查最大使用内存
sudo su - app #切换账户
ulimit -a 检查memery limit size 2G*1024*1024 ==2097152:
max memory size (kbytes, -m) 2097152
2. limit cpu
https://github.com/opsengine/cpulimit
下载: cpulimit-master.zip
2、编译
unzip cpulimit-master.zip
cd cpulimit-master/src
修改makefile
CC=arm-hisiv300-linux-gcc
make
限制进程号1313的程序使用30% cpu利用率
# cpulimit -p 1313 -l 30
自动限制当前进程使用CPU超过20%的进程,将他限制为10%
cpulimit --pid `ps aux|awk '{if($3 > 20) print $2}'` --limit 10
4
cpulimit命令:
用法:cpulimit TARGET [选项...]
目标必须完全是以下之一:
-p,--pid =进程的N pid(隐含-z)
-e,--exe =可执行程序文件的文件名或绝对路径名选件
选项
-l,--limit =允许的cpu百分比从0到100(必填)
-v,--verbose显示控件统计信息
-z,--lazy如果没有合适的目标进程,或者死了,则退出
-h,--help显示此帮助并退出
3.limit disk========https://blog.51cto.com/13570193/2071900
mount -o grpquota,usrquota /dev/sda /data
quotacheck -ucvg /dev/sda
ll /data |grep aquota
setquota -u admin 7000 10000 0 0 /dev/sda # 7M warn 10M top
edquota -u admin
(soft hard of block is set)
启动quotaconfig
quotaon /dev/sda