centos8平台nginx服务配置打开文件限制max open files limits
2023-09-14 09:01:19 时间
一,nginx启动时提示打开文件数,ulimit的配置不起作用:
1,
2020/04/26 14:27:46 [notice] 1553#1553: getrlimit(RLIMIT_NOFILE): 1024:4096
用户可打开文件数
软限制是:1024
硬限制是: 4096
这个值太小,不适用于服务器用途
2,用root用户查看ulimit -n
[root@blog 1554]# ulimit -n 65535
检查limits.conf配置文件
[root@blog 1554]# cat /etc/security/limits.conf
limits.conf中有针对打开文件数的配置
* soft nofile 65535 * hard nofile 65535
可以看到不管ulimit命令还是配置文件,都做了打开文件数量的配置
3,确认当前进程是否有打开文件数量的限制?
用ps找到nginx的进程id:1554,查看master process进程的limits
[root@blog ~]# more /proc/1554/limits | grep 'open files' Max open files 1024 4096 files
确实存在和ulimit中不一致的数量限制
为什么ulimit的配置不起作用?
说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,ulimit配置不起作用的原因:
因为ulimit和limits.conf的配置只针对登录用户,
而对nginx这个systemd管理的服务不起作用,
服务的limit要在service文件中单独指定
三,配置nginx打开文件数量:
1,找到nginx的service文件
[root@blog 1554]# systemctl cat openresty.service # /usr/lib/systemd/system/openresty.service [Unit] Description=The OpenResty Application Platform After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/usr/local/openresty/nginx/logs/nginx.pid ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t ExecStart=/usr/local/openresty/nginx/sbin/nginx ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target
2,编辑service文件,
[root@blog ~]# vi /usr/lib/systemd/system/openresty.service
在service段增加一行:
LimitNOFILE=65535
这样systemd就能了解到要对服务做的限制了
3,重启:
[root@blog ~]# systemctl daemon-reload [root@blog ~]# systemctl stop openresty.service [root@blog ~]# systemctl start openresty.service
4,查看日志看是否起作用:
[root@blog ~]# tail -100 /data/logs/nginxlogs/error.log ... 2020/04/26 14:36:22 [notice] 1651#1651: getrlimit(RLIMIT_NOFILE): 65535:65535 ...
说明已经起作用
5,可以查看进程中限制信息看是否起作用:
找到进程id
[root@blog ~]# ps auxfww | grep nginx root 1652 0.0 0.0 50412 3348 ? Ss 14:36 0:00 nginx: master process /usr/local/openresty/nginx/sbin/nginx nginx 1653 0.0 0.0 81896 5908 ? S 14:36 0:00 \_ nginx: worker process nginx 1654 0.0 0.0 81896 5908 ? S 14:36 0:00 \_ nginx: worker process nginx 1655 0.0 0.0 81896 5908 ? S 14:36 0:00 \_ nginx: worker process nginx 1656 0.0 0.0 81896 5908 ? S 14:36 0:00 \_ nginx: worker process
我们查看pid 1652的打开文件限制:
[root@blog ~]# more /proc/1652/limits | grep 'open files' Max open files 65535 65535 files
可以看到修改已经生效
四,查看nginx的版本
[root@blog ~]# /usr/local/openresty/nginx/sbin/nginx -v nginx version: openresty/1.15.8.2
五,查看centos的版本
[root@blog ~]# cat /etc/redhat-release CentOS Linux release 8.0.1905 (Core)
相关文章
- vscode一键配置C/C++多个C及CPP文件编译与tasks.json和launch.json原理
- Apache日志文件每日自动切割的配置方法
- 【Android 安全】使用 360 加固宝加固应用 ( 购买高级加固服务 | 设置资源加固 | 设置 SO 文件保护配置 | 设置 SO 防盗用文件配置 | 反编译验证加固效果 )
- 基于redis.properties文件的配置及说明介绍
- 通过Java NIO 实现文件下载详解编程语言
- springmvc 项目完整示例07 设置配置整合springmvc springmvc所需jar包springmvc web.xml文件配置详解编程语言
- 文件利用Linux tar命令实现追加文件(linuxtar追加)
- Linux启动时要如何编辑和配置开机文件(linux开机配置文件)
- Linux中文件读写函数的使用(linux文件读写函数)
- 使用Linux命令行快速下载BT文件(linux命令行bt)
- Linux下快速无缝打印文件(linux 文件打印)
- 利用Oracle导出数据至文件的方法(oracle写数据到文件)
- 驭势而上YAM文件配置Redis(yam文件配置redis)
- 文件使用Oracle将数据保存为CSV文件(oracle保存为csv)
- php更改目录及子目录下所有的文件后缀扩展名的代码
- 让Apache支持shtml实现include文件解析的配置方法
- asp.net中资源文件的使用
- Web.Config文件配置之限制上传文件大小和时间的属性配置
- MongoDB学习笔记(五)MongoDB文件存取操作