How to change the number of opened files in Linux

Source: Internet
Author: User
This article describes how to change the number of opened files in linux. content related to linux file descriptors can be found

Operating system version: Redhat 5.4
Problem background: in Tsung stress testing, if you want to create as many tcp requests as possible, you can only create 1013 requests at a time.
Cause Analysis: By default, the number of files opened in Linux is 1024, and the number of files used elsewhere is reduced to 11, and the remaining number is 1013.

Solution:
1) run the ulimit-n or ulimit-a command first, and the number of opened files is 1024.


Copy codeThe code is as follows:
[Root @ SamuluIndex ~] # Ulimit-n
1024


2) use ulimit-n 65535 to change the number of opened files to the maximum value of 65535, and then use ulimit-n to verify that the modification was successful.


Copy codeThe code is as follows:
[Root @ SamuluIndex ~] # Ulimit-n 65535
[Root @ SamuluIndex ~] # Ulimit-n
65535


After running tsung start, you can only create 1013 requests. In addition, after you log on again, you will find that the number of opened files is reset back to the default 1024. This solution is not available.

3) add the following two lines of records at the end of/etc/security/limits. conf:


Copy codeThe code is as follows:
* Soft nofile 65535
* Hard nofile 65535


Verification is successful.

Additional information:

Modify the maximum number of files opened in linux

To view the maximum number of opened files, run the following command.
Ulimit-n
This number indicates the maximum number of files that a common user can open in a single session.
Note. If it is root, the following operations cannot increase the output of ulimit-n. This is because the root user is not restricted by this ulimit. Only common users are subject to this restriction.
To increase the maximum number of opened files to a value greater than 1024 by default, you need to modify two places on the system.

In this case, we increase the maximum number of opened files to 2048. All steps must be performed by the root user. Normal users need to log on again to make the settings take effect.
1. set the system according to the maximum number of opened files, and check the/proc/sys/fs/file-max file to confirm that the maximum number of opened files has been correctly set.
# Cat/proc/sys/fs/file-max
If the value is too small, modify the variable of the file/etc/sysctl. conf to the appropriate value. This will take effect after each restart. If the value is large enough, skip the next step.
# Echo 2048>/proc/sys/fs/file-max edit the file/etc/sysctl. conf and insert it to the downstream.
Fs. file-max = 2048
2. set the maximum number of opened files in the/etc/security/limits. conf file. The following is a prompt line:
# Add the following line.
*-Nofile 2048
This line sets the default number of files opened by each user to 2048.
Note that "nofile" has two possible restrictions. Yes Hard and soft.
To make the maximum number of files opened after modification take effect, you must set these two restrictions.
If the "-" character is used , The hard and soft settings are set at the same time.
Hard limit indicates the maximum value that can be set in the soft limit.
The soft limit refers to the setting value that takes effect for the current system.
The hard limit value can be reduced by common users. But cannot be added.
Soft restrictions cannot be set more than hard restrictions.
Only root users can increase the hard limit value.
When the file limit description is added, you can simply double the current value.
The example is as follows. if you want to increase the default value by 1024, it is best to increase it to 2048. if you want to continue to increase it, you need to set it to 4096.
3. Add the following line to the/etc/pam. d/login and/etc/pam. d/xdm file, if it does not already exist:
Session required/lib/security/pam_limits.so
4. logout and logon
Or dynamically load it in the shell configuration file.
For example, bashrc Riga:
Ulimit-HSn 2048

II. Installation

Tar zxvf mysql-5.1.50-linux-i686-glibc23.tar.gz
Cp-rf mysql-5.1.50-linux-i686-glibc23/usr/local/
Cd/usr/local/
Music mysql-5.1.50-linux-i686-glibc23/mysql
Install it as the default path, so that no soft link is required for the program directory.
Groupadd mysql
Useradd-g mysql
Cd mysql/
Cp support-files/my-medium.cnf/etc/my. cnf
Sed-I's/log-bin = mysql-bin/# log-bin = mysql-bin/g'/etc/my. cnf
Sed-I's/binlog_format = mixed/# binlog_format = mixed/g'/etc/my. cnf
Sed-I's/skip-locking/nmax_connections = 1000/nwait_timeout = 5/g'/etc/my. cnf
Next, initialize the database.
Scripts/mysql_install_db -- user = mysql
Install mysql service control
Cp support-files/mysql. server/etc/rc. d/init. d/mysqld
Chmod 755/etc/rc. d/init. d/mysqld
Chkconfig -- add mysqld
Chkconfig mysqld on
Service mysqld start
Bin/mysqladmin-u root password 123654

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.