Ubuntu 16 永久修改ulimit中的max file open限制

本文介绍如何在Ubuntu 16系统中增加最大文件打开数限制,通过修改系统配置文件来实现对nginx等服务中worker_connections参数的有效提升。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Ubuntu 16 – how to increase maximum file open limit ( ulimit -n )

以下内容为此网页搬运过来的
https://codingweb.lj.studio/ubuntu-16-increase-maximum-file-open-limit-ulimit-n/
版权归该文章作者所有。

If you are setting up nginx,chances are you will discover your worker_connections is at some low number, such as 1024.
You can’t increase this number unless you increase kernel limit as well.
First of all run cat /proc/sys/fs/file-max to discover your maximum limit.

abc@ubuntu:~$ cat /proc/sys/fs/file-max
1048576
abc@ubuntu:~$ ulimit -n
1024

As you can see there’s plenty of space for improvement. Lets say I want my new ‘ulimit -n’ to read 131072.

abc@ubuntu:~$ sudo nano /etc/sysctl.conf

add

fs.file-max = 131072

run

sudo sysctl -p

edit

sudo nano /etc/security/limits.conf

add

* soft     nproc          131072    
* hard     nproc          131072   
* soft     nofile         131072   
* hard     nofile         131072
root soft     nproc          131072    
root hard     nproc          131072   
root soft     nofile         131072   
root hard     nofile         131072
sudo nano /etc/pam.d/common-session

add

session required pam_limits.so

And that’s it. Log out and in and try ulimit -n

abc@ubuntu:~$ ulimit -n 131072

Now you can edit nginx as well

events {
    worker_connections 131072;
    use epoll;
    multi_accept on;
}
在Linux系统中,可以通过以下两种方式来修改Open File参数,包括临时修改永久修改。 1. 临时修改: - 使用ulimit命令:ulimit命令可以用于设置当前会话的资源限制。例如,要增加每个进程可打开的文件数限制,可以执行以下命令: ``` ulimit -n <新的文件数限制> ``` 该命令将临时修改当前会话的文件数限制,但在重新登录或会话结束后将恢复为默认值。 - 使用sysctl命令:sysctl命令可以用于临时修改内核参数。要修改打开文件描述符限制,可以执行以下命令: ``` sysctl -w fs.file-max=<新的文件描述符限制> ``` 该命令将会在当前会话中临时修改内核参数。但是,系统重启后将恢复为默认值。 2. 永久修改: - 修改配置文件:要永久修改Open File参数,可以编辑系统配置文件。具体的配置文件和参数名称可能因Linux发行版而异。以下是一些常见的配置文件和参数名: - /etc/security/limits.conf:可以设置用户级别的资源限制,包括文件描述符限制。 - /etc/sysctl.conf:可以设置内核级别的参数,包括文件数限制。 在相应的配置文件中,找到对应的参数,并修改为所需的值。保存更改后,需要重新启动系统或重启相应的服务才能生效。 请注意,对于临时修改,更改仅在当前会话中有效。而对于永久修改,更改将在系统重启后持久生效。建议谨慎修改系统参数,并在修改之前备份相关配置文件。如果您不确定如何修改配置文件,请参考相关文档或咨询系统管理员。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值