Introduction
The /etc/security/limits.conf
configuration file of the Linux can be used to limit system resources. You can use the configuration file to limit the number of files, threads, memory, and other resource usage to improve system stability. The nofile
parameter indicates the maximum number of files opened by all users in the system. The value /proc/sys/fs/nr_open
parameter indicates the maximum number of files that a single process can allocate to the system. If the value of the nofile
parameter in the system exceeds the value of the nr_opn
parameter, the instance may not be connected remotely. This article describes how to modify the value of the limits.conf
parameter in the nofile
configuration file.
Background
Alibaba Cloud reminds you that:
- Before you perform operations that may cause risks, such as modifying instance configurations or data, we recommend that you check the disaster recovery and fault tolerance capabilities of the instances to ensure data security.
- You can modify the configurations and data of instances including but not limited to Elastic Compute Service (ECS) and Relational Database Service (RDS) instances. Before the modification, we recommend that you create snapshots or enable RDS log backup.
- If you have authorized or submitted sensitive information such as the logon account and password in the Alibaba Cloud Management Console, we recommend that you modify such information in a timely manner.
- Detach the system disk of the abnormal ECS instance and attach the disk as a data disk to a normal ECS instance. For more information, seehow to log on to an abnormal system disk by attaching a data disk to an ECS instance. For more information, see Step 1 to step 4.
- Log on to a normal ECS instance and run the following command to edit the configuration file
/etc/security/limits.conf
.vim /etc/security/limits.conf
- In the configuration file section, find the
root soft nofile
androot hard nofile
parameters and set them to the following values: After the settings are complete, pressShift
+:
Key, then Enterthe wq
, and finally Pressthe Enter
key to save and exit.root soft nofile 65535
root hard nofile 65535Note:
- soft nofile: The Warning value of the number of files opened by the user. It is recommended that you modify it to the default value of 65535. If you understand the role of this system parameter, you can also modify it to the expected value according to your needs. For more information about this parameter, see more information.
- hard nofile: the actual threshold of the number of files opened by users. If the number of files opened by users exceeds this parameter value, an error is reported. We recommend that you change the default value to 65535. If you understand the function of this system parameter, you can change it to the expected value according to your needs. For more information about this parameter, see more information.
- This method takes effect permanently after you set parameters. If you need to temporarily set the
nofile
parameter, you can use theuitit-n}#nofile]
command to set thenofile
parameter.
- See step 5 "how to log on to an abnormal system disk by using an ECS instance as a data disk to restore the system disk of an abnormal ECS instance."
- Remotely log on to the repaired ECS instance and make sure that it is working properly again.
References
- Notes for soft nofile
The value ofsoftnofile
cannot be greater than the value ofhardnofile
. - hard nofile notes
Thehardnofile
value cannot be greater than the value of/proc/sys/fs/nr_open
parameter. If the value of thenofile
parameter is greater than the value of thenr_open
parameter, the user may fail to log on to the instance. - In addition to resource parameter configurations, the Linux of a kernel parameter also determines the performance of the server to a certain extent. For more information about kernel parameter, see Introduction to common kernel network parameters of Linux instances and FAQ.
Application scope
- Elastic Compute Service