How Linux expands the number of file openers

  
                

Linux When you are doing Tsung stress test, you may need to create multiple tcp requests, but the system file open number is fixed, can not meet the demand, this is the need to modify the file open number, the following small series Let me introduce how to modify the number of files opened in the Linux system.

Operating System Version: Redhat 5.4

background to the issue: Tsung stress test, we want to make as many tcp requests and found that you can only build 1013 request.

Reason analysis: The default number of file openers in Linux is 1024, minus 11 used in other places, and the rest is 1013.

Solution:

1) First use the ulimit -n or ulimit -a command to find that the number of open files is 1024

The code is as follows:

[root@SamuluIndex ~]# ulimit -n

1024

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

The code is as follows:

[root@SamuluIndex ~]# ulimit -n 65535

[root@SamuluIndex ~]# ulimit -n

65535< Br>

At this point, run tsung start and find that only 1013 requests can still be created. In addition, after logging in again, it is found that the number of file openes is reset back to the default of 1024. Explain that this solution does not work.

3) Add the following two lines to the end of /etc/security/limits.conf

The code is as follows:

* soft nofile 65535

* hard Nofile 65535

Re-verification, success.

Supplementary information:

Modify the maximum number of open files in the Linux system

The maximum number of open files currently set can be viewed by the following command.

ulimit -n

This number shows the maximum number of files a normal user can open in a single session.

Note. If it is root, the following operations cannot increase the output of ulimit -n. Because the user root user is not subject to this ulimit limit. Only ordinary users will be subject to this restriction.

In order to increase the maximum number of open files to the default value of 1024 or more, you need to modify 2 places on the system.

In this case, we increased the maximum number of open files to 2048. All steps require root user operations. Ordinary users need to log in again for the settings to take effect.

1. Set the system according to the maximum number of open files, and check the /proc/sys/fs/file-max file to confirm that the maximum number of open files has been set correctly.

# cat /proc/sys/fs/file-max

If the setting is too small, modify the /etc/sysctl.conf variable to the appropriate value. This will take effect after each reboot. If the setting is large enough, skip the next step.

# echo 2048 》 /proc/sys/fs/file-maxEdit the file /etc/sysctl.conf and insert it into the downlink.

fs.file-max = 2048

2. Set the maximum number of open files in the /etc/security/limits.conf file. Here is a line:

# "domain" "type" "item" "value" add the following line.

* - nofile 2048

This line sets the default number of open files per user to 2048.

Note that there are two possible restrictions on the &noquo;nofile” item. It is hard and soft under "type".

In order for the maximum number of open files to be modified to take effect, these two restrictions must be set.

If you set "type" with the “-” character, the hard and soft settings will be set at the same time.

The hard limit indicates the maximum value that can be set in the soft limit.

The soft limit refers to the setting value that is currently in effect for the system.

The hard limit value can be lowered by ordinary users. But can't increase.

The soft limit cannot be set higher than the hard limit.

Only the root user can increase the hard limit.

When adding a file limit description, you can simply double the current value.

The example is as follows. If you want to increase the default value of 1024, it is better to increase it to 2048. If you want to continue to increase, 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 loaded in the shell configuration file.

如.bashrc Riga:

ulimit -HSn 2048

Second, install

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/

mv mysql-5.1 .50-linux-i686-glibc23/mysql

Install as the default path, so you don't have to make soft links for the program directory

groupadd mysql

useradd -g mysql 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/skip-locking/nmax_connections = 1000/nwait_timeout = 5/g’ /etc/my.cnf

Next to 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< Br>

service mysqld start

bin/mysqladmin -u root password 123654

The above is the method of modifying the number of open files under Linux. Usually, the number of open files is absolutely sufficient. If you really need to modify the file open number, you can try the method described in this article. What are you waiting for?

Copyright © Windows knowledge All Rights Reserved