更改nginx软件“进程最大可打开文件数”的设置

https://blog.csdn.net/huangbaokang/article/details/79917023 这篇博客只是操作系统级别的“进程最大可打开文件”的限制。

在nginx.conf文件中加入worker_rlimit_nofile配置

未加这个配置的时候,启动好了nginx服务,我们可以查看到当前nginx进程最大可打开的文件数。如下:

[root@localhost ~]# ps -ef|grep nginx
root 927 1 0 15:32 ? 00:00:00 nginx: master process /root/hbk/nginx2/sbin/nginx
root 928 927 0 15:32 ? 00:00:00 nginx: worker process
root 929 927 0 15:32 ? 00:00:00 nginx: worker process
root 930 927 0 15:32 ? 00:00:00 nginx: worker process
root 931 927 0 15:32 ? 00:00:00 nginx: worker process
root 1065 1049 0 15:34 pts/0 00:00:00 grep –color=auto nginx
1
2
3
4
5
6
7
8
在我这里,有1个master process和4个worker process,随便找一个进程查看:

[root@localhost ~]# cat /proc/928/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 3818 3818 processes
Max open files 1024 4096 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 3818 3818 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
可以看出,未配置worker_rlimit_nofile,在我的linux下open files 显示的是

Max open files 1024 4096
1
配置改写
user root;
worker_processes 4;
worker_rlimit_nofile 65535;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;

events {
worker_connections 65535;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
主要是进行了两处改写,加上worker_rlimit_nofile 65535; 和设置worker_connections 65535;

重启nginx服务之后,再次验证。

[root@localhost nginx2]# sbin/nginx -s reload
[root@localhost nginx2]# ps -ef|grep nginx
root 927 1 0 15:32 ? 00:00:00 nginx: master process /root/hbk/nginx2/sbin/nginx
root 1098 927 2 15:52 ? 00:00:00 nginx: worker process
root 1099 927 2 15:52 ? 00:00:00 nginx: worker process
root 1100 927 2 15:52 ? 00:00:00 nginx: worker process
root 1101 927 2 15:52 ? 00:00:00 nginx: worker process
root 1103 1049 0 15:52 pts/0 00:00:00 grep –color=auto nginx
[root@localhost nginx2]# cat /proc/1100/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 3818 3818 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 3818 3818 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
可以看到,max open files 变成了65535了。温馨提示,在生产环境下,一定要确保Nginx工作进程的配置信息是经过优化的,否则Nginx对并发请求的处理能力将会大打折扣。
———————
作者:黄宝康
来源:CSDN
原文:https://blog.csdn.net/huangbaokang/article/details/79930189
版权声明:本文为博主原创文章,转载请附上博文链接!

发表评论

电子邮件地址不会被公开。 必填项已用*标注