网站首页 > 技术教程 正文
背景
服务是高并发的密集io型服务,连接数和打开文件数特别高。而在linux中,一切皆文件,所以连接数本身也会表现为文件打开数。默认情况下,linux单进程打开文件数的限制是1024 , 非常低,在密集io型服务里很容易超过。
一般的情况下,我们是根据服务器内存大小,以及单进程使用情况,来多开进程,同时限制单进程打开的文件数。但 dfyun 比较特殊——它是文件打开数特别多(连接数+本地文件打开数+遍历扫描文件操作等等) ,但占用的内存特别小。所以,我不需要根据内存来斟酌打开数值了,直接设置一个非常大的数据即可,让系统不再在文件数上做限制。
下面将直接上代码,放开linux设置,让其不再限制文件打开数。一些代码的细节可以看注释,如果有疑问,可直接上网查找该命令的概念。
操作
# vi /etc/sysctl.conf ,末尾添加
fs.file-max = 655350000
fs.nr_open = 655350000
# 执行命令生效
sysctl -p
# 查看 max-file:
cat /proc/sys/fs/file-max
# 查看当前系统总打开文件数
cat /proc/sys/fs/file-nr
# 输出: 9344 0 592026,
# 分别为:1.已经分配的文件句柄数,2.已经分配但没有使用的文件句柄数,3.最大文件句柄数。
# 修改系统对单个进程打开的文件数限制
ulimit -n 655350000
echo "* soft nofile 655350000" >> /etc/security/limits.conf
echo "* hard nofile 655350000" >> /etc/security/limits.conf
# 顺便附上查看各个进程打开的文件数的命令。显示格式是文件数 + 进程id
lsof -n |awk '{print $2}'|sort|uniq -c|sort -nr|more
# 如果有安装nginx做转发,则还需要设置nginx
#打开nginx本身的文件数限制
vi /etc/nginx/nginx.conf
# 找到相应位置覆盖修改这个配置
worker_rlimit_nofile 655350000;
events {
worker_connections 65535;
}
vi /etc/sysctl.conf 末尾添加tcp连接数相关配置
net.core.somaxconn = 20480
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 4096 16777216
net.ipv4.tcp_wmem = 4096 4096 16777216
net.ipv4.tcp_mem = 786432 2097152 3145728
net.ipv4.tcp_max_syn_backlog = 16384
net.core.netdev_max_backlog = 20000
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_max_orphans = 131072
net.ipv4.tcp_syncookies = 0
之后执行 sysctl -p 生效
- 上一篇: linux安装nikto(Linux安装软件)
- 下一篇: tomcat调优方案
猜你喜欢
- 2025-04-24 Linux 下安装最新版 MySQL
- 2025-04-24 快速教会你优雅的解决TCP客户端端口耗尽的问题
- 2025-04-24 Linux系统——用户、用户组、权限和文件属性
- 2025-04-24 Linux 远程数据同步工具详解
- 2025-04-24 高流量大并发Linux TCP性能调优
- 2025-04-24 linux 系统自动化巡检脚本总结
- 2025-04-24 Linux 解决 oracle ORA-12537: TNS:connection closed 问题
- 2025-04-24 Linux 网络错误 TCP: too many orphaned sockets 分析与解决
- 2025-04-24 MySQL max_connections 达到最大值 – 我们如何解决它
- 2025-04-24 socket连接数受端口号的限制?谬论
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)