Linux参数优化

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  
其中open files                      (-n) 1024 表示每个用户最大允许打开的文件数量是1024

查看当前系统打开的文件数量

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 生效






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值