1.文件句柄
文件句柄,文件描述符,会随着进程数增加而增加。
Linux是有文件句柄限制的,而且默认不是很高,一般都是1024,作为一台生产服务器,其实很容易就达到 这个数量,因此我们需要把这个值改大一些。我们可以用ulimit -n 来查看当前用户句柄数限制
2.设置文件句柄数
1)系统全局设置
[root@web01 ~]# vim /etc/security/limits.conf
* - nofile 65535
* soft nofile 65535
* hard nofile 65535
* #代表所有用户
- #超过文件句柄数时,什么都不干
soft #超过文件句柄数时,仅提示
hard #超过文件句柄数时,直接限制
2)用户局部设置
[root@web01 ~]# vim /etc/security/limits.conf
root - nofile 65535
root soft 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.ip_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 = 1
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