1、openfiles参数优化
有时应用程序会报Too many open files的错误,是因为open files数目不够,系统默认是1024。
ulimit -a
core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 20 file size (blocks, -f) unlimited pending signals (-i) 16382 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) unlimited virtual memory (kbytes, -v) unlimited file locks (-x) unlimited |
查看当前系统打开的文件数量
lsof | wc -l |
查看某个进程打开的文件数量
lsof -p pid | wc -l |
设置open files数值的方法
临时设置 ulimit -n 2048 重启系统后会还原默认值 永久设置 vi /etc/security/limits.d/90-nproc.conf 末尾处添加: * soft nofile 51200 软限制 * hard nofile 51200 硬限制 软限制要小于等于硬限制 * soft nproc 11000 *hard nproc 11000注:* 表示所有用户,可根据需要设置某一个用户,例如: testuser soft nofile 51200 testuser hard nofile 51200 testuser soft nproc 11000 testuser hard nproc 11000 |
2、修改网络
net.ipv4.tcp_max_tw_buckets = 6000 net.ipv4.ip_local_port_range = 1024 65000 net.ipv4.tcp_syncookies = 1 net.core.somaxconn = 262144 net.core.netdev_max_backlog = 262144 net.ipv4.tcp_max_orphans = 262144 net.ipv4.tcp_max_syn_backlog = 262144 net.ipv4.tcp_synack_retries = 1 net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_timestamps=0 net.ipv4.tcp_tw_reuse=1 net.ipv4.tcp_tw_recycle=1 net.ipv4.tcp_fin_timeout=30 net.ipv4.tcp_keepalive_time=1800 net.ipv4.tcp_max_syn_backlog=4096 执行sysctl -p 生效 |