In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to optimize the Apache server of CentOS system, I believe that many inexperienced people are at a loss about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Apache is the Web server software used in the world. It can run on almost all widely used computer platforms, and is one of the Web server-side software because of its cross-platform and security. Now let's take a look at the optimization of Apache in CentOS systems.
1.Apache optimization
Apache can run normally on CentOS system. However, for sites with a large number of visitors, these default configurations of Apache cannot meet the requirements. We still need to adjust some parameters of Apache to enable Apache to perform better in a high traffic environment. In the CentOS system, let's explain some of the parameters in the Apache profile httpd.conf that have a great impact on performance.
(1) Timeout this parameter specifies the maximum wait time (in seconds) for the Apache before receiving the request or sending the requested content. If the Apache exceeds this time, the request is abandoned and the connection is released. The default value of this parameter is 120, which is recommended to be set to 60, and can be set to 30 for websites with a large number of visitors.
(2) KeepAlive this parameter controls whether Apache allows multiple requests in a connection. It is turned on by default. However, for most forum type sites, it is usually set to off to turn off this support.
(3) MPM-prefork.c Apache uses Prefork (process) working mode by default, so it can be said that the parameter setting of this part is the core and key to the performance of Apache. Users can find the following configuration segments in the configuration document:
StartServers5 MinSpareServers5 MaxSpareServers10 MaxClients15 MaxRequestsPerChild0 IfModule >
This is the configuration section that controls the work of the Apache process. In order to better understand the parameters in the above configuration, let's first take a look at how Apache controls the process. We know that in Unix systems, the daemon process (Daemon) of many services (Service) creates a process to respond to possible connection requests when it is started, and the service enters the port listening state. When a request from the client (Client) is sent to the port on which the service is listening, the service process will process the request. During the processing, the process is in an exclusive state. That is, if other requests arrive at this time, they can only be "queued" for the current request processing to complete and the service process to be released.
This will result in more and more requests waiting in the queue, which actually shows that the processing power of the service is very low. Apache solves this problem well by using Prefork mode. Let's take a look at how Apache actually works efficiently.
When Apache starts, Apache starts StartSpareServers idle processes and prepares to receive processing requests. When multiple requests arrive, StarSpareServers runs less and less. When idle processes are reduced to MinSpareServers, Apache will start StartsServers processes for backup in order to continue to have sufficient processes to process requests. This greatly reduces the possibility of queuing waiting for requests and improves service efficiency. This is why it is called Pre-fork. Let's continue to track the work of Apache. Let's assume that Apache has started 200 processes to process requests. Theoretically, there are 205processes in Apache at this time. After a period of time, assuming that 100 requests have been responded to and processed by Apache, then these 100processes are released as idle processes, and Apache has 105idle processes at this time. As for the service, it doesn't make any sense to start too many idle processes, but it will degrade the overall performance of the server, so will Apache really have 105 idle processes?
Of course not! In fact, Apache checks itself at any time, and when it finds that there are more than MaxSpareServers free processes, it automatically stops shutting down some processes to ensure that there are not too many idle processes. At this point, users should have some understanding of how Apache works. For more detailed instructions, please refer to the Apache manual documentation.
We still have two CentOS system parameters not covered: MaxClients and MaxRequestPerchild;MaxClients specify how many clients are allowed to connect to Apache at the same time, and if there are more than MaxClients connections, the client will get a "server busy" error page. We see that MaxClients is set to 15 by default, which is obviously not enough for some medium-sized and large sites! Maybe you need to allow 512 client connections at the same time to meet the application requirements, so let's modify MaxClients to 512, save httpd.conf and exit, restart Apache. Unfortunately, you see some errors during the restart process. Apache restart failed.
The error message tells you that MaxClients*** can only be set to 256. I'm sure you'll be disappointed. But don't be depressed, Apache, as the WebServer of the world, will not be so thin! By default, MaxClients can only be set to an integer of no more than 256. however, if you need to customize it at will, you need to use the ServerLimit parameter to use it. Simply put, ServerLimit is like a bucket, and MaxClients is like water. You can hold more water (MaxClients) by changing a larger bucket (set ServerLimit to a larger value), but be careful. The setting value of MaxClients cannot be greater than the setting value of ServerLimit!
Let's take a look at the MaxRequestPerChild parameter, which specifies how many threads can work simultaneously in a connection process. Perhaps this explanation is too professional, then you only need to think about "multiple points to download at the same time" in "Network Ant" and "Internet Express FlashGet". This parameter actually limits the number of "points" you can use. The default setting is 0, that is: no limit. However, it should be noted that setting this value too low will cause access problems. If there is no special need or the traffic pressure is not very large, you can keep the default value. If the traffic is high, it is recommended to set it to 2048.
Well, having explained so much, let's take a look at the recommended configuration of the modified Perfork.c configuration segment:
StartServers5 MinSpareServers5 MaxSpareServers10 ServerLimit1024 MaxClients768 MaxRequestsPerChild0 IfModule > after reading the above, have you mastered how to optimize the Apache server of CentOS system? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.