Nginx 500错误 ----- nginx:accept() failed (24: Too many open files) 201

    xiaoxiao2021-04-13  23

    原文地址

    centos  中 ulimit -n 为1024, 当Nginx连接数超过1024时,error.log中就出现以下错误:

    [alert] 12766#0: accept() failed (24: Too many open files)

    使用 ulimit -n 655350 可以把打开文件数设置足够大, 同时修改nginx.conf , 添加 worker_rlimit_nofile 655350; (与error_log同级别)

    这样就可以解决Nginx连接过多的问题,Nginx就可以支持高并发。<还要修改nginx>

    另外, ulimit -n 还会影响到MySQL 的并发连接数。把他提高,也就提高了mysql并发。

    注意: 用ulimit -n 2048 修改只对当前的shell有效,退出后失效。

    修改方法

    若要令修改ulimits的数值永久生效,则必须修改配置文档,可以给ulimit修改命令放入/etc/profile里面,这个方法实在是不方便,

    还有一个方法是修改/etc/security/limits.conf

    /etc/security/limits.conf 格式,文件里面有很详细的注释,比如

    * soft nofile 655360

    * hard nofile 655360

    星号代表全局, soft为软件,hard为硬件,nofile为这里指可打开文件数。

    把以上两行内容加到 limits.conf文件中即可。

    另外,要使 limits.conf 文件配置生效,必须要确保 pam_limits.so 文件被加入到启动文件中。查看 /etc/pam.d/login 文件中有:

    session required /lib/security/pam_limits.so

    修改完重新登录就可以见到效果,可以通过 ulimit -n 查看。

    转载请注明原文地址: https://ju.6miu.com/read-668793.html

    最新回复(0)