linux宝塔面板环境安装cpulimit 解决cpu使用率过高

158次阅读
没有评论

前面说的挖矿教程的一大问题就是cpu一直飙在100%,这个真是时时刻刻在挑战良心云的底线啊。这篇文章就来说说如何安装安装cpulimit 解决cpu使用率过高,也就是把cpu使用率单核限制在75%。

linux宝塔面板环境安装cpulimit

1、安装cpulimit

安装自己用包安装即可。

1)Centos:

	
	
	<ol class="linenums" style="font-family:inherit;font-size:13px;font-style:inherit;margin-left:33px;vertical-align:baseline;">
		
		<li class="L0" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#777777;">
			<span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">yum install cpulimit</span> 
		</li>

	</ol>

2)Debian/Ubuntu

	
	
	<ol class="linenums" style="font-family:inherit;font-size:13px;font-style:inherit;margin-left:33px;vertical-align:baseline;">
		
		<li class="L0" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#777777;">
			<span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">apt</span><span class="pun" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#555555;">-</span><span class="kwd" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#22C3A8;">get</span><span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;"> install cpulimit</span> 
		</li>

	</ol>

3)如果没有包,也不能编译安装,可以安装EPEL源,如下:

隐藏的内容
		
		
		<ol class="linenums" style="font-family:inherit;font-size:13px;font-style:inherit;margin-left:33px;vertical-align:baseline;">
			
			<li class="L0" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#777777;">
				<span class="com" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#A17367;">#安装EPEL源</span> 
			</li>

			<li class="L1" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#777777;">
				<span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">yum </span><span class="pun" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#555555;">-</span><span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">y install epel</span><span class="pun" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#555555;">-</span><span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">release</span> 
			</li>

			<li class="L2" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#777777;">
				<span class="com" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#A17367;">#重新创建本地仓库缓存</span> 
			</li>

			<li class="L3" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#777777;">
				<span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">yum clean all </span><span class="pun" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#555555;">&&</span><span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;"> yum makecache</span> 
			</li>

			<li class="L4" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#777777;">
				<span class="com" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#A17367;">#然后yum下就可以了</span> 
			</li>

			<li class="L5" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#777777;">
				<span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">yum install cpulimit </span> 
			</li>

		</ol>

2、使用cpulimit

这里就简单说下使用命令了。太过复杂的,自己看相关文档。

1)命令格式 如下:

		
		
		<ol class="linenums" style="font-family:inherit;font-size:13px;font-style:inherit;margin-left:33px;vertical-align:baseline;">
			
			<li class="L0" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#777777;">
				<span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">cpulimit </span><span class="pun" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#555555;">-</span><span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">l </span><span class="pun" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#555555;">限制百分比</span><span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;"> </span><span class="pun" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#555555;">-</span><span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">p </span><span class="pun" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#555555;">进程号</span> 
			</li>

		</ol>

		
		
		<ol class="linenums" style="font-family:inherit;font-size:13px;font-style:inherit;margin-left:33px;vertical-align:baseline;">
			
			<li class="L0" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#777777;">
				<span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">cpulimit </span><span class="pun" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#555555;">-</span><span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">e </span><span class="pun" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#555555;">进程名</span><span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;"> </span><span class="pun" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#555555;">-</span><span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">l </span><span class="pun" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#555555;">限制百分比</span> 
			</li>

		</ol>

2)查找占用高的进程命令

这里查找挖矿进程,简单点可以用top命令来查看。如下:

大鸟这里占用73%,已经被限制过了,如果你没限制过,这里肯定是100%

pid:1633 (进程号)

COMMAND:xmrig(进程名)

linux宝塔面板环境安装cpulimit

3)安装screen

因为要时刻监控这个进程,所以你需要用到screen。

如果提示screen: command not found 命令不存在可以执行:

centos

		
		
		<ol class="linenums" style="font-family:inherit;font-size:13px;font-style:inherit;margin-left:33px;vertical-align:baseline;">
			
			<li class="L0" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#777777;">
				<span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">yum install screen</span> 
			</li>

		</ol>

Debian/Ubuntu

		
		
		<ol class="linenums" style="font-family:inherit;font-size:13px;font-style:inherit;margin-left:33px;vertical-align:baseline;">
			
			<li class="L0" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#777777;">
				<span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">apt</span><span class="pun" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#555555;">-</span><span class="kwd" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#22C3A8;">get</span><span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;"> install screen</span> 
			</li>

		</ol>

4)使用实例

这个时候开始执行限制的命令,如下。

		
		
		<ol class="linenums" style="font-family:inherit;font-size:13px;font-style:inherit;margin-left:33px;vertical-align:baseline;">
			
			<li class="L0" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#777777;">
				<span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">screen </span><span class="pun" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#555555;">-</span><span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">S xmrig </span><span class="com" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#A17367;">#新建会话</span> 
			</li>

			<li class="L1" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#777777;">
				<span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">cpulimit </span><span class="pun" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#555555;">-</span><span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">l </span><span class="lit" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#A17367;">75</span><span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;"> </span><span class="pun" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#555555;">-</span><span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">p </span><span class="lit" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#A17367;">1633</span><span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;"> </span><span class="com" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#A17367;">#利用pid限制程序运行的cpu</span> 
			</li>

			<li class="L2" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#777777;">
				<span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">cpulimit </span><span class="pun" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#555555;">-</span><span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">e xmrig </span><span class="pun" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#555555;">-</span><span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">l </span><span class="lit" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#A17367;">75</span><span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;"> </span><span class="com" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#A17367;">#利用进程名限制程序运行的cpu</span> 
			</li>

		</ol>

之后,按下CTRL+A+D 退出程序。

注意:VPS只要一个核心限制其CPU占用率为75%  如果是两个核心你需要限制到150%

5)使用效果

稍等一会,cpu使用就会限制到75左右。我们看腾讯云的后台管理,如下:

linux宝塔面板环境安装cpulimit

3、Linux查看进程号的其他方法

1)命令如下:

	
	
	<ol class="linenums" style="font-family:inherit;font-size:13px;font-style:inherit;margin-left:33px;vertical-align:baseline;">
		
		<li class="L0" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#777777;">
			<span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">ps aux</span><span class="pun" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#555555;">|</span><span class="pln" style="font-family:inherit;font-style:inherit;vertical-align:baseline;color:#666666;">grep xmrig</span> 
		</li>

	</ol>

2)实列

第一个红框标注的就是我们要找的,可以和top命令对比下。

linux宝塔面板环境安装cpulimit

之后,我们用上面的命令限制即可。

4、最后

限制cpu之后,你做个矿工是否会安心点呢,O(∩_∩)O。

评论(没有评论)