Linux ulimit 参数配置
ulimit 参数配置错误导致的常见报错
1. java.lang.OutOfMemoryError: unable to create new native thread
ulimit -u 配置过小
2. -bash: ulimit: max user processes: cannot modify limit: Operation not permitted
-bash: /home/oracle/.bash_profile: Too many open files
ulimit -n 配置过小
3. -bash: ulimit: open files: cannot modify limit: Operation not permitted
-bash: fork: Resource temporarily unavailable
ulimit -u 配置过小
解决方案:
fs.file-max 表示系统级别的能够打开的文件句柄的数量。是对整个系统的限制,并不是针对用户的。
ulimit -n 控制进程级别能够打开的文件句柄的数量。提供对shell及其启动的进程的可用文件句柄的控制。这是进程级别的。
soft为初始值,hard为最大值,重启服务器reboot使之生效。
# vim /etc/sysctl.conf, 加入以下内容,重启生效 fs.file-max = 6553560
vi /etc/security/limits.conf tomcat soft nofile 65535 tomcat hard nofile 65535 faculty soft nproc 65535 faculty hard nproc 65535
su - tomcat vi .bash_profile 添加一行 ulimit -u 65535 用root用户source使之生效
验证:
su- tomcat ulimit -a ps -U username | wc -l --查看用户进程使用情况 lsof | grep username | wc -l -- 查看用户打开文件句柄数量