开发者

linux系统的文件句柄数详解

目录
  • 1.文件句柄
  • 2.设置文件句柄数
    • 1)系统全局设置
    • 2)用户局部设置
    • 3)针对nginx服务
  • 3.系统优化
    • 总结

      1.文件句柄

      文件句柄,文件描述符,会随着进程数增加而增加。

      linux是有文件句柄限制的,而且默认不是很高,一般都是1024,作为一台生产服务器,其实很容易就达编程客栈到 这个数量,因此我们需要把这个值改大一些。我们可以用ulimit -n 来查看当前用户句柄数限制

      2.设置文件句柄数

      1)系统全局设置

      [root@web01 ~]# vim /etc/security/limits.conf
      * - nofile 65535
      * soft nofile 65535
      * hard nofile 65535
      
      *		#代表所有用户
      -		#超过文件句柄数时,什么都不干
      soft	#超过文件句柄数时,仅提示
      hard	#超过文件句柄数时php,直接限制
      
      

      2)用户局部设置

      [root@web01 ~]# vim /etc/security/limits.conf
      root - nofile 65535
      root uujbwTgsoft nofile 65535
      root hard nofile 65535
      
      

      3)针对nginx服务

      [root@web01 ~]# vim /etc/nginx/nginx.conf 
      user  www;
      worker_processes  1;
      #添加下面一行
      worker_rlimit_nofile 65535;
      
      

      3.系统优化

      [root@web01 ~]# vim /etc/sysctl.conf
      net.ipv4.tcp_fin_timeout = 2
      net.ipv4.tcp_tw_reuse = 1
      net.ipv4.tcp_tw_recycle = 1
      net.ipv4.tcp_syncookies = 1
      net.ipv4.tcp_keepalive_time = 600
      net.ipv4.ipuujbwTg_local_port_range = 4000   65000
      net.ipv4.tcp_max_syn_backlog = 16384
      net.ipv4.tcp_max_tw_buckets = 36000
      net.ipv4.route.gc_timeout = 100
      net.ipv4.tcp_syn_retries = 1javascript
      net.ipv4.tcp_synack_retries = 1
      net.core.somaxconn = 16384
      net.core.netdev_max_backlog = 16384
      net.ipv4.tcp_max_orphans = 16384
      net.ipv4.ip_forward = 1
      
      #配置立即生效
      [root@web01 ~]# sysctl -p
      
      

      总结

      以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程客栈(www.devze.com)。

      0

      上一篇:

      下一篇:

      精彩评论

      暂无评论...
      验证码 换一张
      取 消

      最新运维

      运维排行榜