zoukankan      html  css  js  c++  java
  • centos8平台nginx服务配置打开文件限制max open files limits

    一,nginx启动时提示打开文件数,ulimit的配置不起作用:

    1,

    2020/04/26 14:27:46 [notice] 1553#1553: getrlimit(RLIMIT_NOFILE): 1024:4096

    用户可打开文件数

    软限制是:1024

    硬限制是: 4096

    这个值太小,不适用于服务器用途

    2,用root用户查看ulimit -n

    [root@blog 1554]# ulimit -n
    65535

    检查limits.conf配置文件

    [root@blog 1554]# cat /etc/security/limits.conf

    limits.conf中有针对打开文件数的配置

    * soft nofile 65535
    * hard nofile 65535

    可以看到不管ulimit命令还是配置文件,都做了打开文件数量的配置

    3,确认当前进程是否有打开文件数量的限制?

    用ps找到nginx的进程id:1554,查看master process进程的limits

    [root@blog ~]# more /proc/1554/limits | grep 'open files'
    Max open files            1024               4096                files

    确实存在和ulimit中不一致的数量限制

    为什么ulimit的配置不起作用?

    说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

             对应的源码可以访问这里获取: https://github.com/liuhongdi/

     说明:作者:刘宏缔 邮箱: 371125307@qq.com

    二,ulimit配置不起作用的原因:

    因为ulimit和limits.conf的配置只针对登录用户,

    而对nginx这个systemd管理的服务不起作用,

    服务的limit要在service文件中单独指定

    三,配置nginx打开文件数量:

     1,找到nginx的service文件

    [root@blog 1554]# systemctl cat openresty.service
    # /usr/lib/systemd/system/openresty.service
    [Unit]
    Description=The OpenResty Application Platform
    After=syslog.target network.target remote-fs.target nss-lookup.target
    
    [Service]
    Type=forking
    PIDFile=/usr/local/openresty/nginx/logs/nginx.pid
    ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t
    ExecStart=/usr/local/openresty/nginx/sbin/nginx
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s QUIT $MAINPID
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target

    2,编辑service文件,

    [root@blog ~]# vi /usr/lib/systemd/system/openresty.service

    在service段增加一行:

    LimitNOFILE=65535

    这样systemd就能了解到要对服务做的限制了

    3,重启:

    [root@blog ~]# systemctl daemon-reload
    [root@blog ~]# systemctl stop openresty.service
    [root@blog ~]# systemctl start openresty.service

    4,查看日志看是否起作用:

    [root@blog ~]# tail -100 /data/logs/nginxlogs/error.log
    ...
    2020/04/26 14:36:22 [notice] 1651#1651: getrlimit(RLIMIT_NOFILE): 65535:65535
    ...

    说明已经起作用

    5,可以查看进程中限制信息看是否起作用:

    找到进程id

    [root@blog ~]# ps auxfww | grep nginx
    root      1652  0.0  0.0  50412  3348 ?        Ss   14:36   0:00 nginx: master process /usr/local/openresty/nginx/sbin/nginx
    nginx     1653  0.0  0.0  81896  5908 ?        S    14:36   0:00  \_ nginx: worker process
    nginx     1654  0.0  0.0  81896  5908 ?        S    14:36   0:00  \_ nginx: worker process
    nginx     1655  0.0  0.0  81896  5908 ?        S    14:36   0:00  \_ nginx: worker process
    nginx     1656  0.0  0.0  81896  5908 ?        S    14:36   0:00  \_ nginx: worker process

    我们查看pid 1652的打开文件限制:

    [root@blog ~]# more /proc/1652/limits | grep 'open files'
    Max open files            65535                65535                files

    可以看到修改已经生效

    四,查看nginx的版本

    [root@blog ~]# /usr/local/openresty/nginx/sbin/nginx -v
    nginx version: openresty/1.15.8.2

    五,查看centos的版本 

    [root@blog ~]# cat /etc/redhat-release
    CentOS Linux release 8.0.1905 (Core)
  • 相关阅读:
    vue封装一些常用组件loading、switch、progress
    个人推荐的两款vue导出EXCEL插件
    解决react项目中跨域和axios封装使用
    vue仿阿里云后台管理(附加阿里巴巴图标使用)
    简单的利用nginx部署前端项目
    Python3 SMTP发送邮件
    WINDOWS和UNIX换行符的理解
    Forward Proxy vs Reverse Proxy
    Authentication token is no longer valid
    SNMP Introduction
  • 原文地址:https://www.cnblogs.com/architectforest/p/12794986.html
Copyright © 2011-2022 走看看