系统优化

1.查看文件句柄命令

#查看文件句柄数设置
[root@web01 ~]# ulimit -n
65535

#查看总共打开的文件句柄数
[root@web01 ~]# lsof | wc -l

#查看进程打开的文件句柄数
[root@web01 ~]# lsof -p 71336 | wc -l

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     #生效
原文地址:https://www.cnblogs.com/chenlifan/p/13651933.html