刘来 發表於 2019-12-7 15:53:00

CentOS修改ulimit

<h1 id="h1-u6982u8FF0">一、概述</h1>
<p>查看limit配置</p>
<div class="cnblogs_code">
<pre># ulimit -<span style="color: rgba(0, 0, 0, 1)">a
core </span><span style="color: rgba(0, 0, 255, 1)">file</span> size          (blocks, -c) <span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
data seg size         (kbytes, </span>-<span style="color: rgba(0, 0, 0, 1)">d) unlimited
scheduling priority             (</span>-e) <span style="color: rgba(128, 0, 128, 1)">0</span>
<span style="color: rgba(0, 0, 255, 1)">file</span> size               (blocks, -<span style="color: rgba(0, 0, 0, 1)">f) unlimited
pending signals               (</span>-i) <span style="color: rgba(128, 0, 128, 1)">7257</span><span style="color: rgba(0, 0, 0, 1)">
max locked memory       (kbytes, </span>-l) <span style="color: rgba(128, 0, 128, 1)">64</span><span style="color: rgba(0, 0, 0, 1)">
max memory size         (kbytes, </span>-<span style="color: rgba(0, 0, 0, 1)">m) unlimited
open files                      (</span>-n) <span style="color: rgba(128, 0, 128, 1)">1024</span><span style="color: rgba(0, 0, 0, 1)">
pipe size            (</span><span style="color: rgba(128, 0, 128, 1)">512</span> bytes, -p) <span style="color: rgba(128, 0, 128, 1)">8</span><span style="color: rgba(0, 0, 0, 1)">
POSIX message queues   (bytes, </span>-q) <span style="color: rgba(128, 0, 128, 1)">819200</span><span style="color: rgba(0, 0, 0, 1)">
real</span>-<span style="color: rgba(0, 0, 255, 1)">time</span> priority            (-r) <span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
stack size            (kbytes, </span>-s) <span style="color: rgba(128, 0, 128, 1)">8192</span><span style="color: rgba(0, 0, 0, 1)">
cpu </span><span style="color: rgba(0, 0, 255, 1)">time</span>               (seconds, -<span style="color: rgba(0, 0, 0, 1)">t) unlimited
max user processes            (</span>-u) <span style="color: rgba(128, 0, 128, 1)">7257</span><span style="color: rgba(0, 0, 0, 1)">
virtual memory          (kbytes, </span>-<span style="color: rgba(0, 0, 0, 1)">v) unlimited
</span><span style="color: rgba(0, 0, 255, 1)">file</span> locks                      (-x) unlimited</pre>
</div>
<p>其中最大进程数和最大文件打开数,需要修改一下。否则相关软件,无法启动。</p>
<p>&nbsp;</p>
<h1 id="h1-u6C38u4E45u751Fu6548u7684u65B9u6CD5">二、永久生效的方法</h1>
<h2>环境说明</h2>
<p>操作系统:centos 6.9</p>
<p>&nbsp;</p>
<h2 id="h2-limits-conf">limits.conf</h2>
<p>修改<span style="color: rgba(255, 0, 0, 1)"><code>/etc/security/limits.conf</code></span>文件</p>
<p>在文件末尾添加</p>
<div class="cnblogs_code">
<pre>* soft nofile <span style="color: rgba(128, 0, 128, 1)">204800</span>
* hard nofile <span style="color: rgba(128, 0, 128, 1)">204800</span>
* soft nproc <span style="color: rgba(128, 0, 128, 1)">204800</span>
* hard nproc <span style="color: rgba(128, 0, 128, 1)">204800</span></pre>
</div>
<p>&nbsp;</p>
<p>说明:</p>
<div class="cnblogs_code">
<pre>*<span style="color: rgba(0, 0, 0, 1)">             代表针对所有用户
noproc   是代表最大进程数
nofile   是代表最大文件打开数</span></pre>
</div>
<p>&nbsp;</p>
<h2 id="h2-90-nproc-conf">90-nproc.conf</h2>
<p>光修改上面一个文件是不行的,还需要修改一个文件。<br>修改<span style="color: rgba(255, 0, 0, 1)"><code>/etc/security/limits.d/90-nproc.conf</code></span>文件<br>删掉默认配置,修改如下:</p>
<div class="cnblogs_code">
<pre>*          soft    nproc   <span style="color: rgba(128, 0, 128, 1)">204800</span>
*          hard    nproc   <span style="color: rgba(128, 0, 128, 1)">204800</span></pre>
</div>
<p>&nbsp;</p>
<p>修改2个配置文件之后,重启后生效</p>
<div class="cnblogs_code">
<pre>reboot -f</pre>
</div>
<p>&nbsp;</p>
<h2 id="h2-u67E5u770Bu914Du7F6E">查看配置</h2>
<div class="cnblogs_code">
<pre># ulimit -<span style="color: rgba(0, 0, 0, 1)">a
core </span><span style="color: rgba(0, 0, 255, 1)">file</span> size          (blocks, -c) <span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
data seg size         (kbytes, </span>-<span style="color: rgba(0, 0, 0, 1)">d) unlimited
scheduling priority             (</span>-e) <span style="color: rgba(128, 0, 128, 1)">0</span>
<span style="color: rgba(0, 0, 255, 1)">file</span> size               (blocks, -<span style="color: rgba(0, 0, 0, 1)">f) unlimited
pending signals               (</span>-i) <span style="color: rgba(128, 0, 128, 1)">15238</span><span style="color: rgba(0, 0, 0, 1)">
max locked memory       (kbytes, </span>-l) <span style="color: rgba(128, 0, 128, 1)">64</span><span style="color: rgba(0, 0, 0, 1)">
max memory size         (kbytes, </span>-<span style="color: rgba(0, 0, 0, 1)">m) unlimited
open files                      (</span>-n) <span style="color: rgba(128, 0, 128, 1)">204800</span><span style="color: rgba(0, 0, 0, 1)">
pipe size            (</span><span style="color: rgba(128, 0, 128, 1)">512</span> bytes, -p) <span style="color: rgba(128, 0, 128, 1)">8</span><span style="color: rgba(0, 0, 0, 1)">
POSIX message queues   (bytes, </span>-q) <span style="color: rgba(128, 0, 128, 1)">819200</span><span style="color: rgba(0, 0, 0, 1)">
real</span>-<span style="color: rgba(0, 0, 255, 1)">time</span> priority            (-r) <span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
stack size            (kbytes, </span>-s) <span style="color: rgba(128, 0, 128, 1)">10240</span><span style="color: rgba(0, 0, 0, 1)">
cpu </span><span style="color: rgba(0, 0, 255, 1)">time</span>               (seconds, -<span style="color: rgba(0, 0, 0, 1)">t) unlimited
max user processes            (</span>-u) <span style="color: rgba(128, 0, 128, 1)">204800</span><span style="color: rgba(0, 0, 0, 1)">
virtual memory          (kbytes, </span>-<span style="color: rgba(0, 0, 0, 1)">v) unlimited
</span><span style="color: rgba(0, 0, 255, 1)">file</span> locks                      (-x) unlimited</pre>
</div>
<p>&nbsp;</p>
<p>本文参考链接:</p>
<p>https://blog.csdn.net/xzw_123/article/details/46878459</p>
<p>&nbsp;</p><br><br>
来源:https://www.cnblogs.com/xiao987334176/p/12011480.html
頁: [1]
查看完整版本: CentOS修改ulimit