nginx文件服务器限制,centos8平台nginx服务配置打开文件限制max open files limits

一,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 -n65535

检查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 files1024 4096 files

确实存在和ulimit中不一致的数量限制

为什么ulimit的配置不起作用?

说明:作者:刘宏缔 邮箱: 371125307@qq.com

二,ulimit配置不起作用的原因:

因为ulimit和limits.conf的配置只针对登录用户,

而对nginx这个systemd管理的服务不起作用,

服务的limit要在service文件中单独指定

三,配置nginx打开文件数量:

1,找到nginx的service文件

[root@blog 1554]# systemctl catopenresty.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 | grepnginx

root1652 0.0 0.0 50412 3348 ? Ss 14:36 0:00 nginx: master process /usr/local/openresty/nginx/sbin/nginx

nginx1653 0.0 0.0 81896 5908 ? S 14:36 0:00\_ nginx: worker process

nginx1654 0.0 0.0 81896 5908 ? S 14:36 0:00\_ nginx: worker process

nginx1655 0.0 0.0 81896 5908 ? S 14:36 0:00\_ nginx: worker process

nginx1656 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 files65535 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 release8.0.1905 (Core)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值