去掉内存和文件句柄限制
以coherence用户为例子:
修改:/etc/security/limits.conf
coherence hard nproc 655360
coherence soft nproc 655360
coherence hard nofile 65536
coherence soft nofile 65536
* hard memlock unlimited
* soft memlock unlimited
还要修改PROFILE
/etc/profile
ulimit -l unlimited
ulimit -u unlimited
还要修改
/etc/pam.d/login
session required /lib/security/pam_limits.so
需要重启才能生效。
执行:ulimit–l 确认
. Method 1:Changing Locked Memory Permanently
https://software.intel.com/en-us/blogs/2014/12/16/best-known-methods-for-setting-locked-memory-size
This method shows how to alter a configuration limit to allow auser to change the locked memory size.
1.1 Change locked memory size in the host:
Edit the file /etc/security/limits.conf
$ sudo vi /etc/security/limits.conf
Add the following line at the end of the file to set anunlimited locked memory for the user named “user1”. The second field value canbe “hard” or “soft”: “hard” enforces the resource limit, and “soft” defines thedefault value within the maximum value specified by “hard”.
user1 hard memlock unlimited
user1 soft memlock unlimited
By adding this, user1 can raise the locked memory size withoutlimit. To allow all users to set unlimited memlock, simply replace user1 withthe wildcard *
* hard memlock unlimited
* soft memlock unlimited
Reboot the system. Login and verify that the locked memory isnow set to unlimited:
$ ulimit –l
unlimited
So you limits.conf would have the line (to a maximum of 4G of memory)
luser hard as 4000000
单位是K
To increase the soft and hard limits ofmemlock, the following lines should be added to the file /etc/security/limits.conf:
username or * hard memlock size_in_kbytes
username or * soft memlock size_in_kbytes
For example, to set unlimited space forall users:
* soft memlockunlimited
* hard memlockunlimited
To set the limits for all users to 256MB:
* soft memlock262144
* hard memlock262144
Java.lang.OutOfMemoryError: unable to create new nativethread
最近在Linux服务器上发布应用时碰到一个如下的异常:
Caused by: java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:640)
初看可能会认为是系统的内存不足,如果这样想的话就被这段提示带到沟里面去了。
上面这段错误提示的本质是Linux操作系统无法创建更多进程,导致出错。因此要解决这个问题需要修改Linux允许创建更多的进程。
修改Linux最大进程数
我们可以通过ulimit-a来查看当前Linux系统的一些系统参数。
$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 62357
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 65536
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 4096
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
在上面这些参数中,通常我们关注得比较多的是一个进程可打开的最大文件数,即openfiles。系统允许创建的最大进程数量即是maxuser processes 这个参数。我们可以使用ulimit -u 4096 修改maxuser processes的值,但是只能在当前终端的这个session里面生效,重新登录后仍然是使用系统默认值。
正确的修改方式是修改/etc/security/limits.d/90-nproc.conf文件中的值。先看一下这个文件包含什么:
$ cat /etc/security/limits.d/90-nproc.conf
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.
* soft nproc 4096
我们只要修改上面文件中的4096这个值,即可。