• 文件句柄


    1,文件句柄

    在linux/unix操作系统中一切皆文件,我们的设备是文件,文件是文件,文件夹也是文件。当我们用户每发起一次请求,就会产生一个文件句柄。文件句柄可以简单的理解为文件句柄就是一个索引。文件句柄就会随着请求量的增多,进程调用频繁增加,那么产生的文件句柄也就会越多。

    系统默认对文件句柄是有限制的,不可能会让一个进程无限制的调用句柄。因为系统资源是有限的,所以我们需要限制每一个服务能够使用多大的文件句柄。操作系统默认使用的文件句柄是1024个句柄。

    2、设置方式
    • 系统全局性修改

    • 用户局部性修改

    • 进程局部性修改

    3、系统全局性修该和用户局部性修改

    [root@nginx-server ~]# vim /etc/security/limits.conf 

    #* soft core 0
    #* hard rss 10000
    #@student hard nproc 20
    #@faculty soft nproc 20
    #@faculty hard nproc 50
    #ftp hard nproc 0
    #@student - maxlogins 4

    #root只是针对root这个用户来限制,soft只是发提醒,操作系统不会强制限制,一般的站点设置为一万左右就ok了
    root soft nofile 65535
    root hard nofile 65535
    # *代表通配符 所有的用户
    * soft nofile 25535
    * hard nofile 25535

    可以看到root*,root代表是root用户,*代表的是所有用户,后面的数字就是文件句柄大小。大家可以根据个人业务来进行设置。

    [root@nginx-server ~]# vim /etc/nginx/nginx.conf
    user nginx;
    worker_processes  1;  

    error_log /var/log/nginx/error.log warn;
    pid       /var/run/nginx.pid;

    worker_rlimit_nofile 65535; #进程限制

    events {
      worker_connections  1024;
    }

    http {
      include       /etc/nginx/mime.types;
      default_type application/octet-stream;

      log_format main  '$http_user_agent' '$remote_addr - $remote_user [$time_local] "$request" '
                         '$status $body_bytes_sent "$http_referer" '
                         '"$http_user_agent" "$http_x_forwarded_for" '
                         '"$args" "$request_uri"';

      access_log /var/log/nginx/access.log main;

      sendfile       on;
       #tcp_nopush     on;

      keepalive_timeout  65;

       #gzip on;

      include /etc/nginx/conf.d/*.conf;
    }

    worker_rlimit_nofile 是在进程上面进行限制。

  • 相关阅读:
    自学人工智能之数学篇,数学入门并不难
    2018-8-10-win10-uwp-使用资源在后台创建控件
    2019-9-2-win10-uwp-弹起键盘不隐藏界面元素
    2019-7-31-程序猿修养-日志应该如何写
    2018-11-19-WPF-在image控件用鼠标拖拽出矩形
    2019-8-31-C#-如何给-ValueTuple-返回值添加注释
    2019-11-12-浅谈-Windows-桌面端触摸架构演进
    2018-8-10-win10-uwp-打开文件管理器选择文件
    2018-8-10-win10-uwp-验证输入-自定义用户控件
    2019-8-31-dotnet-特性-DynamicallyInvokable-是用来做什么的
  • 原文地址:https://www.cnblogs.com/wyglog/p/12491444.html
Copyright © 2020-2023  润新知