修改nginx 进程最大文件句柄数
修改nginx 进程最大文件句柄数
1. 修改 cat /etc/sysctl.conf 中 fs.file-max参数
fs.file-max=65535
执行 sysctl -p 让修改的内核参数生效
2.修改linux系统参数。追加下面内容到 /etc/security/limits.conf 文件
* soft nofile 65535
* hard nofile 65535
命令如下:
echo "* soft nofile 65535" >> /etc/security/limits.conf
echo "* hard nofile 65535" >> /etc/security/limits.conf
3. 修改 nginx systemd 启动参数
cat /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
LimitNOFILE=65535 // 添加这一行
[Install]
WantedBy=multi-user.target
4. 重新启动 nginx 进程
systemctl daemon-reload
systemctl restart nginx
5. 查看nginx 进程 pid
ps aux|grep nginx
root 16257 0.0 0.0 123140 2488 ? Ss 16:48 0:00 nginx: master process /usr/sbin/nginx
nginx 16258 0.2 0.0 123588 4060 ? S 16:48 0:02 nginx: worker process
nginx 16259 0.3 0.0 123588 4052 ? S 16:48 0:03 nginx: worker process
nginx 16260 1.8 0.0 123984 4552 ? S 16:48 0:16 nginx: worker process
nginx 16261 0.6 0.0 123588 4056 ? S 16:48 0:06 nginx: worker process
6. 查看进程的 limits 数值, 其中 max open files 已经调整为 65535
cat /proc/16257/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 8388608 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 31217 31217 processes
Max open files 65535 65535 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 31217 31217 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
2019-09-10 dubbo-admin管理平台搭建