In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "Apache server optimization method", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Apache server optimization method" bar!
ExtendedStatus On sets off because it writes an extra time flag.
MPM:worker- multi-process multi-threading new design, suitable for high-traffic services, but unstable, object php and other support is very poor, not recommended, prefork- stability, wireless range, take up more memory.
HostnameLookups off is turned off, so that one less dns query, log processing can be used additional software.
Comment on the unwanted modules in the LoadMoule directive.
In general, modules that are not needed include:
The code is as follows:
LoadModule auth_basic_module modules/mod_auth_basic.so
# LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule authn_file_module modules/mod_authn_file.so
# LoadModule authn_alias_module modules/mod_authn_alias.so
LoadModule authn_anon_module modules/mod_authn_anon.so
# LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
# LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule ldap_module modules/mod_ldap.so
# LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule include_module modules/mod_include.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
LoadModule ext_filter_module modules/mod_ext_filter.so
LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule expires_module modules/mod_expires.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
LoadModule usertrack_module modules/mod_usertrack.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule mime_module modules/mod_mime.so
# LoadModule dav_module modules/mod_dav.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule info_module modules/mod_info.so
# LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule actions_module modules/mod_actions.so
LoadModule speling_module modules/mod_speling.so
# for example: if you need to debug php under ~ / username/, you can set the
# LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
# LoadModule proxy_module modules/mod_proxy.so
# LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
# LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
# LoadModule proxy_http_module modules/mod_proxy_http.so
# LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule cache_module modules/mod_cache.so
LoadModule suexec_module modules/mod_suexec.so
LoadModule disk_cache_module modules/mod_disk_cache.so
LoadModule file_cache_module modules/mod_file_cache.so
LoadModule mem_cache_module modules/mod_mem_cache.so
# cgi programs, such as awstats, need to be used
LoadModule cgi_module modules/mod_cgi.so
LoadModule version_module modules/mod_version.so
The above is only part of my summary is not needed, there are warrior advice, and those can not be.
Optimized Options Indexes Includes FollowSymLinks ExecCGI for the option of folder Directory
AllowOverride None
ExecCGI allows the execution of CGI scripts. If this option is not set, the CGI script cannot be executed. It is best not to turn it on if it is not necessary, there may be security problems.
Includes allows server-side inclusion. Server-side inclusion allows one HTML file to contain other files. This is not usually used, he has to check every html, so do not open it.
IncludesNOEXEC allows server-side inclusion, but the # exec and # include instructions in the CGI script are invalid. Not often. Turn it off.
Indexes displays a list of directory contents in a certain way if DirectoryIndex (such as index.html) does not exist in the requested directory. This is too much. Turn it on.
It is best for FollowSymLinks to turn off symbolic connections, and Apache must make additional system calls to verify symbolic connections. Each component of the file name requires an additional call. When this option is turned on, Apache checks whether each request contains a reference to a symbolic link, which calls the lstat () system call once for each path contained in the request. When requesting "/ index.html", Apache will make a lstat () call to "/ www", "/ www/htdocs", "/ www/htdocs/index.html". And the execution result of lstat () is not cached, so it is executed once for each request. Unless you are going to use symbolic links, use Options-FollowSymLinks to turn it off. Boot with a dash to disable this directive.
AllowOverride this option is to enable, such as including htaccess for permission control, Apache must first find out whether the file exists in the current directory, and if so, parse the file and apply the settings in the file in the current directory. To make matters worse, Apache not only looks at the current directory, but also checks to see if all the upper directories of the current directory include htaccess files to determine the settings based on all of these files. For example, if you request "/ index.html", Apache will try to open "/ .htaccess", "/ www/.htaccess", "/ www/ htdocs/.htaccess". The solution is to turn off AllowOverride None, of course, doing so statically can only be written in the configuration of VH, and after disabling the settings file is parsed only once when the server starts.
DirectoryIndex index*, does not use wildcards, but uses full lists, such as irectoryIndex index.cgi index.pl index.shtml index.html. Of course, at least it is better to specify a clear list of settings files, and it is most reasonable to put them in the first place.
Persistent link Keepalive is enabled so that the process remains busy waiting for a new request on the open connection. If KeepAliveTimeout is enabled, the default value is set to 5 seconds. Preferably no more than 60 seconds.
Disable Log
Writing log information is a time-consuming task, and although Apache keeps the log file open to save time opening the file, it still takes a lot of time. If there is no need to store log information, you can turn off this option to save more processor time, just comment out the log line in the settings file and turn it off. Of course, it is really necessary to add another single disk to manage log storage.
Static content aspect
If your WEB server uses a lot of static content or you use two WEB servers to deal with dynamic and static content, then your main goal now is to reduce the response time of the server to send the requested content, the easiest way is to use the mod_cache cache module. You can use mod_disk_cache and mod_mem_cache to provide disk-based caching and memory-based caching respectively.
Optimize dynamic content
Dynamic content is probably the most time-consuming part of all WEB servers, especially when using CGI, a simple program can increase response time by several seconds.
A big advantage of using script-based solutions is that they load an interpreter in Apache, which reduces the time it takes to reload the interpreter during execution, and some scenarios cache parsed scripts so that they can be executed directly the next time you encounter the same request without having to parse again. Of course, you can also apply service separation, such as using php's fastcgi to run behind and front to the Web server.
Tuning and optimizing specific systems is complex and time-consuming, and you need to adjust specific scripts to take advantage of the optimized results.
However, the optimization effect on dynamic content is very obvious. Simply changing the execution mode of perl scripts from CGI to mod_perl can reduce execution time by up to 70%. If we go further, we can also use persistent connections to the database or cache information between multiple requests, which is very useful for e-commerce sites and reduces the overhead of repeatedly loading information between different requests.
Generally speaking, dynamic content scripts and CGI are the most important aspects that affect the performance of a website (so good programmers are important). If you manage a typical Apache server, you will find that the time it takes for Apache to respond to an incoming connection and finally send the content to the customer is recorded in milliseconds, while the time waiting for the required data resources is often up to a few seconds.
Other optimization
You can change the priority of Apache (httpd) to-15, which is close to the upper limit (from the highest priority of-20 to the lowest priority of 19). You can use these two utilities from the command line:
* to stop an existing service and restart it at priority-15, issue the command nice-15 httpd
* to avoid stopping the service, issue the command renice-15-p 1996
The difference here is that renice requires a process ID (or pid). As mentioned above, you can use top to find out the pid. Nice and renice are very flexible programs.
Configure the mod_expires module (this is a very useful optimization)
Mod_expires can reduce the number of repeated requests by about 20-30%, so that the repeated users CACHE the results of the specified page requests locally and do not send requests to the server at all. It will not be updated unless users send no-cache, but be careful not to do so for files that update quickly.
Installation configuration of mod_expires:
The code is as follows:
ExpiresActive On
ExpiresDefault A60
ExpiresByType image/x-icon A2592000
ExpiresByType application/x-javascript A2592000
ExpiresByType text/css A2592000
ExpiresByType image/gif A604800
ExpiresByType image/png A604800
ExpiresByType image/jpeg A604800
ExpiresByType text/plain A604800
ExpiresByType application/x-shockwave-flash A604800
ExpiresByType video/x-flv A604800
ExpiresByType application/pdf A604800
ExpiresByType text/html A60
In fact, there is also a compression, I will not write, see my other article >
Http://www.php-oa.com/2008/08/20/gzipsquid.html compression ratio can be as high as 70%, which is very useful.
In addition, for high-speed web services, you can add noatime parameters to the / etc/fstab file.
The lnux file system keeps records when files are accessed, created, and updated. By default, the last-time-read property is updated when the file is read and written. Because write operations are more resource-consuming, reducing unnecessary iUnix can improve disk performance as a whole.
When attaching a file system, adding the noatime parameter prevents the modification of the access time of the inode node. If the file update time is not important for a specific application, such as a web service, you can add the noatime parameter to the / etc/fstab file
For example:
/ dev/sdb1 / mountlocation ext3 defaults,noatime 1 2
It is recommended to use a separate partition as the mounting point and turn on the noatime switch
You can also turn off the service (which everyone seems to understand), apmd,autofs,cups,hpoj.isdn,pcmcia,rhnsd,sendmail,xfs (font service)
Open time-wait socket in reuse TCP/IP
Sysctl-w net.ipv4.tcp_tw_reuse=1
Start the fast loop function of TIME-WAIT socket status
Sysctl = w net.ipv4.tcp_tw_recycle=1
This personal summary, coupled with the experience of some predecessors, the following optimization, generally speaking, in my use of more than a year, is still quite useful, optimization and non-optimization is still quite obvious.
Let's get to the point.
ExtendedStatus On sets off because it writes an extra time flag.
MPM:worker- multi-process multi-threading new design, suitable for high-traffic services, but unstable, object php and other support is very poor, not recommended, prefork- stability, wireless range, take up more memory.
HostnameLookups off is turned off, so that one less dns query, log processing can be used additional software.
Comment on the unwanted modules in the LoadMoule directive.
In general, modules that are not needed include:
LoadModule auth_basic_module modules/mod_auth_basic.so
# LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule authn_file_module modules/mod_authn_file.so
# LoadModule authn_alias_module modules/mod_authn_alias.so
LoadModule authn_anon_module modules/mod_authn_anon.so
# LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
# LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule ldap_module modules/mod_ldap.so
# LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule include_module modules/mod_include.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
LoadModule ext_filter_module modules/mod_ext_filter.so
LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule expires_module modules/mod_expires.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
LoadModule usertrack_module modules/mod_usertrack.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule mime_module modules/mod_mime.so
# LoadModule dav_module modules/mod_dav.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule info_module modules/mod_info.so
# LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule actions_module modules/mod_actions.so
LoadModule speling_module modules/mod_speling.so
# for example: if you need to debug php under ~ / username/, you can set the
# LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
# LoadModule proxy_module modules/mod_proxy.so
# LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
# LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
# LoadModule proxy_http_module modules/mod_proxy_http.so
# LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule cache_module modules/mod_cache.so
LoadModule suexec_module modules/mod_suexec.so
LoadModule disk_cache_module modules/mod_disk_cache.so
LoadModule file_cache_module modules/mod_file_cache.so
LoadModule mem_cache_module modules/mod_mem_cache.so
# cgi programs, such as awstats, need to be used
LoadModule cgi_module modules/mod_cgi.so
LoadModule version_module modules/mod_version.so
The above is only part of my summary can not be used, there are warrior advice and those can not be … .
Optimization of options for folder Directory
Options Indexes Includes FollowSymLinks ExecCGI
AllowOverride None
ExecCGI allows the execution of CGI scripts. If this option is not set, the CGI script cannot be executed. It is best not to turn it on if it is not necessary, there may be security problems.
Includes allows server-side inclusion. Server-side inclusion allows one HTML file to contain other files. This is not usually used, he has to check every html, so do not open it.
IncludesNOEXEC allows server-side inclusion, but the # exec and # include instructions in the CGI script are invalid. Not often. Turn it off.
Indexes displays a list of directory contents in a certain way if DirectoryIndex (such as index.html) does not exist in the requested directory. This is too much. Turn it on.
It is best for FollowSymLinks to turn off symbolic connections, and Apache must make additional system calls to verify symbolic connections. Each component of the file name requires an additional call. When this option is turned on, Apache checks whether each request contains a reference to a symbolic link, which calls the lstat () system call once for each path contained in the request. When requesting "/ index.html", Apache will make a lstat () call to "/ www", "/ www/htdocs", "/ www/htdocs/index.html". And the execution result of lstat () is not cached, so it is executed once for each request. Unless you are going to use symbolic links, use Options-FollowSymLinks to turn it off. Boot with a dash to disable this directive.
AllowOverride this option is to enable, such as including htaccess for permission control, Apache must first find out whether the file exists in the current directory, and if so, parse the file and apply the settings in the file in the current directory. To make matters worse, Apache not only looks at the current directory, but also checks to see if all the upper directories of the current directory include htaccess files to determine the settings based on all of these files. For example, if you request "/ index.html", Apache will try to open "/ .htaccess", "/ www/.htaccess", "/ www/htdocs/.htaccess". The solution is to turn off AllowOverride None, of course, doing so statically can only be written in the configuration of VH, and after disabling the settings file is parsed only once when the server starts.
DirectoryIndex index*, do not use wildcards, all use complete lists, such as: DirectoryIndex index.cgi index.pl index.shtml index.html. Of course, at least it is better to specify a clear list of settings files, and it is most reasonable to put them in the first place.
Persistent link Keepalive is enabled so that the process remains busy waiting for a new request on the open connection. If KeepAliveTimeout is enabled, the default value is set to 5 seconds. Preferably no more than 60 seconds.
Disable Log
Writing log information is a time-consuming task, and although Apache keeps the log file open to save time opening the file, it still takes a lot of time. If there is no need to store log information, you can turn off this option to save more processor time, just comment out the log line in the settings file and turn it off. Of course, it is really necessary to add another single disk to manage log storage.
Static content aspect
If your WEB server uses a lot of static content or you use two WEB servers to deal with dynamic and static content, then your main goal now is to reduce the response time of the server to send the requested content, the easiest way is to use the mod_cache cache module. You can use mod_disk_cache and mod_mem_cache to provide disk-based caching and memory-based caching respectively.
Optimize dynamic content
Dynamic content is probably the most time-consuming part of all WEB servers, especially when using CGI, a simple program can increase response time by several seconds.
A big advantage of using script-based solutions is that they load an interpreter in Apache, which reduces the time it takes to reload the interpreter during execution, and some scenarios cache parsed scripts so that they can be executed directly the next time you encounter the same request without having to parse again. Of course, you can also apply service separation, such as using php's fastcgi to run behind and front to the Web server.
Tuning and optimizing specific systems is complex and time-consuming, and you need to adjust specific scripts to take advantage of the optimized results.
However, the optimization effect on dynamic content is very obvious. Simply changing the execution mode of perl scripts from CGI to mod_perl can reduce execution time by up to 70%. If we go further, we can also use persistent connections to the database or cache information between multiple requests, which is very useful for e-commerce sites and reduces the overhead of repeatedly loading information between different requests.
Generally speaking, dynamic content scripts and CGI are the most important aspects that affect the performance of a website (so good programmers are important). If you manage a typical Apache server, you will find that the time it takes for Apache to respond to an incoming connection and finally send the content to the customer is recorded in milliseconds, while the time waiting for the required data resources is often up to a few seconds.
Other optimization
Configure the mod_expires module (this is a very useful optimization)
Mod_expires can reduce the number of repeated requests by about 20-30%, so that the repeated users CACHE the results of the specified page requests locally and do not send requests to the server at all. It will not be updated unless users send no-cache, but be careful not to do so for files that update quickly.
Installation configuration of mod_expires:
ExpiresActive On
ExpiresDefault A60
ExpiresByType image/x-icon A2592000
ExpiresByType application/x-javascript A2592000
ExpiresByType text/css A2592000
ExpiresByType image/gif A604800
ExpiresByType image/png A604800
ExpiresByType image/jpeg A604800
ExpiresByType text/plain A604800
ExpiresByType application/x-shockwave-flash A604800
ExpiresByType video/x-flv A604800
ExpiresByType application/pdf A604800
ExpiresByType text/html A60
In fact, there is another compression, so I won't write it. See my other article.
Http://www.php-oa.com/2008/08/20/gzipsquid.html compression ratio can be as high as 70%, which is very useful.
In addition, for high-speed web services, you can add noatime parameters to the / etc/fstab file.
The lnux file system keeps records when files are accessed, created, and updated. By default, the last-time-read property is updated when the file is read and written. Because write operations are more resource-consuming, reducing unnecessary iUnix can improve disk performance as a whole.
When attaching a file system, adding the noatime parameter prevents the modification of the access time of the inode node. If the file update time is not important for a specific application, such as a web service, you can add the noatime parameter to the / etc/fstab file
For example:
/ dev/sdb1 / mountlocation ext3 defaults,noatime 1 2
It is recommended to use a separate partition as the mounting point and turn on the noatime switch
You can also turn off the service (which everyone seems to understand), apmd,autofs,cups,hpoj.isdn,pcmcia,rhnsd,sendmail,xfs (font service)
Open time-wait socket in reuse TCP/IP
Sysctl-w net.ipv4.tcp_tw_reuse=1
Start the fast loop function of TIME-WAIT socket status
Sysctl = w net.ipv4.tcp_tw_recycle=1
Thank you for your reading, the above is the content of "the optimization method of Apache server". After the study of this article, I believe you have a deeper understanding of the optimization method of Apache server, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.