zoukankan      html  css  js  c++  java
  • 修改nginx 进程最大文件句柄数

    修改nginx 进程最大文件句柄数

    1. 修改 cat /etc/sysctl.conf 中 fs.file-max参数
    fs.file-max=65535


    执行 sysctl -p 让修改的内核参数生效


    2.修改linux系统参数。追加下面内容到 /etc/security/limits.conf 文件
    *  soft  nofile  65535
    *  hard  nofile  65535


    命令如下:
    echo "* soft nofile 65535" >> /etc/security/limits.conf
    echo "* hard nofile 65535" >> /etc/security/limits.conf

    3. 修改 nginx systemd 启动参数


    cat /usr/lib/systemd/system/nginx.service


    [Unit]
    Description=The nginx HTTP and reverse proxy server
    After=network.target remote-fs.target nss-lookup.target
    [Service]
    Type=forking
    PIDFile=/run/nginx.pid
    # Nginx will fail to start if /run/nginx.pid already exists but has the wrong
    # SELinux context. This might happen when running `nginx -t` from the cmdline.
    # https://bugzilla.redhat.com/show_bug.cgi?id=1268621
    ExecStartPre=/usr/bin/rm -f /run/nginx.pid
    ExecStartPre=/usr/sbin/nginx -t
    ExecStart=/usr/sbin/nginx
    ExecReload=/bin/kill -s HUP $MAINPID
    KillSignal=SIGQUIT
    TimeoutStopSec=5
    KillMode=process
    PrivateTmp=true
    LimitNOFILE=65535 // 添加这一行


    [Install]
    WantedBy=multi-user.target


    4. 重新启动 nginx 进程
    systemctl daemon-reload
    systemctl restart nginx

    5. 查看nginx 进程 pid
    ps aux|grep nginx
    root 16257 0.0 0.0 123140 2488 ? Ss 16:48 0:00 nginx: master process /usr/sbin/nginx
    nginx 16258 0.2 0.0 123588 4060 ? S 16:48 0:02 nginx: worker process
    nginx 16259 0.3 0.0 123588 4052 ? S 16:48 0:03 nginx: worker process
    nginx 16260 1.8 0.0 123984 4552 ? S 16:48 0:16 nginx: worker process
    nginx 16261 0.6 0.0 123588 4056 ? S 16:48 0:06 nginx: worker process


    6. 查看进程的 limits 数值, 其中 max open files 已经调整为 65535

    cat /proc/16257/limits
    Limit Soft Limit Hard Limit Units
    Max cpu time unlimited unlimited seconds
    Max file size unlimited unlimited bytes
    Max data size unlimited unlimited bytes
    Max stack size 8388608 unlimited bytes
    Max core file size 0 unlimited bytes
    Max resident set unlimited unlimited bytes
    Max processes 31217 31217 processes
    Max open files 65535 65535 files
    Max locked memory 65536 65536 bytes
    Max address space unlimited unlimited bytes
    Max file locks unlimited unlimited locks
    Max pending signals 31217 31217 signals
    Max msgqueue size 819200 819200 bytes
    Max nice priority 0 0
    Max realtime priority 0 0
    Max realtime timeout unlimited unlimited us

  • 相关阅读:
    处理某客户p570硬盘故障所思
    Android手机使用WIFI及USB建立FTP服务器总结
    Metro界面的真正意义
    找工作之面试血泪史
    vim7.4官方源码在vs2013的编译方法及问题总结
    关于vs2012/2013的C编译器生成的exe的向后兼容xp的问题
    【转】一篇关于32位Linux内核使用大内存的文章——Hugemem Kernel Explained  &nb
    直接修改Android软件数据库来改变软件设置实例一则
    解决MyEclipse中安装或升级ADT之后SDK Target无法显示的问题
    国行Android手机使用google全套GMS服务小结
  • 原文地址:https://www.cnblogs.com/weifeng1463/p/15250422.html
Copyright © 2011-2022 走看看