Apache2.2.14 (Ubuntu) modifies the maximum number of connections.

Source: Internet
Author: User
The website prohibits image leeching. This article applies to the UbuntuLinux system. First, you need to determine the working mode of the Server httpd, you can view it by executing the apachect2-l: You can see that there is prefork. c, so httpd is working in the prefork concurrency mode. Open the apache2 configuration file sudovi/etc/apache2/apache2.confapache2 concurrency control mode, including prefork and worker

The website prohibits image leeching. This article applies to Ubuntu Linux. First, you need to determine the httpd working mode of the server. You can run apachect2-l to view the following information:


We can see that there is prefork. c, so httpd is working in the prefork concurrency mode.

Open the configuration file sudo vi/etc/apache2/apache2.conf of apache2.

The concurrency control mode of apache2, including modifying the prefork and worker:

 


Then restart apache2:
Sudo/etc/init. d/apache2 stop
Sudo/etc/init. d/apache2 start
Complete the settings.
 
Note: The maximum value of MaxClients is 250 by default. to exceed this value, you must explicitly set ServerLimit, and set ServerLimit to be placed before MaxClients. The value must not be smaller than that of MaxClients. Otherwise, a prompt will be displayed when you restart the system. After you restart apache2, run pgrep httpd | wc-l repeatedly to check the number of connections. You can see that the number of connections does not increase after the value of MaxClients is reached, but the Website access is smooth at this time, you don't need to be greedy and set a higher value. Otherwise, the server memory will be consumed if the Website access suddenly increases. You can adjust the memory usage according to the future access pressure trend and memory usage changes, until an optimal setting value is found.

MaxRequestsPerChild cannot be set to 0, which may cause server crash due to memory leakage.


Appendix: Common parameter explanation


# With this parameter, you do not need to modify the source code like apache1 to modify the limit of 256 customers. It takes effect only when you put the lecture at the beginning. 2000 is the maximum value of this parameter.
ServerLimit 2000
# Specify the number of sub-processes created when the server starts. The default value of prefork is 5.
StartServers 25
# Specify the minimum number of idle sub-processes. The default value is 5. If the number of idle sub-processes is less than MinSpareServers, Apache will generate a new sub-process at a maximum speed per second. Do not set this parameter too large.
MinSpareServers 25
# Set the maximum number of idle sub-processes. The default value is 10. If there are idle sub-processes that exceed the number of MaxSpareServers, the parent process will kill the redundant sub-processes. Do not set this parameter too large. If you set the value of this command to a smaller value than MinSpareServers, Apache will automatically change it to "MinSpareServers + 1 ″.
MaxSpareServers 50
# Limit the maximum number of client access requests (number of concurrent threads in a single process) at the same time. The default value is 256. Any request that exceeds the limit of MaxClients will enter the waiting queue. Once a link is released, the request in the queue will be served. To increase this value, you must increase ServerLimit at the same time.
MaxClients 2000
# Each sub-process allows the maximum number of requests of the servo within its lifetime. The default value is 10000. When the limit of MaxRequestsPerChild is reached, the sub-process will end. If MaxRequestsPerChild is "0", the child process will never end.
MaxRequestsPerChild 10000

Setting MaxRequestsPerChild to a non-zero value has two advantages:
1. It can prevent (accidental) infinite Memory leakage and thus exhaust the memory.
2. A limited life cycle is provided for processes, which helps reduce the number of active processes when server load is reduced.
Working Method:
A separate control process (parent process) is responsible for generating child processes that are used to listen for requests and respond. Apache always tries to keep some standby (spare) or idle sub-processes to meet the upcoming requests. In this way, the client does not need to wait for the sub-process to generate before obtaining the service. In Unix systems, the parent process is usually run as root to stick port 80, while the child process generated by Apache is usually run as a low-privilege user. The User and Group commands are used to set low-privilege users for sub-processes. Users running a sub-process must have the read permission on the Content served by the sub-process, but must have as few permissions as possible for resources other than the service content.
We often need to check the number of httpd processes for optimization (that is, the number of concurrent requests that Apache can process in prefork mode ):
# Ps-ef | grep httpd | wc-l
The result is the number of concurrent requests that Apache can process. This value is automatically adjusted by Apache based on the load.

Reading:

Fully Distributed cluster configuration (load balancing) http://www.linuxidc.com/Linux/2013-08/89072.htm of Apache and Tomcat in Linux

Linux website architecture series-Apache-deployment http://www.linuxidc.com/Linux/2013-11/92304.htm

Apache log analysis tools-multi-site log analysis http://www.linuxidc.com/Linux/2013-11/92273.htm

Install an Apache http://www.linuxidc.com/Linux/2013-11/92266.htm that supports SSL in Ubuntu 13.10

Apache2 (http.2.4.6) + Tomcat 7.0 cluster installation and configuration http://www.linuxidc.com/Linux/2013-11/92322.htm

For more information about Ubuntu, see Ubuntu special page http://www.linuxidc.com/topicnews.aspx? Tid = 2

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.