From: http://blog.9cbs.net/airskys/
Apache is a historic and powerful web server, but its rich features often don't know where to start with a newcomer. I personally feel that Apache's design fully reflects the advantages of modular design. By installing in dynamic module loading (DSO) mode, any sub-application module can make plug-in flexible configuration by simple modification of the configuration file. Then we can start from a simple static HTML service, a module for learning. From a simple HTML Static Service (Core), to complex dynamic page services (Core PHP, Core RESIN, CORE PHP MOD_GZIP, CORE RESIN MOD_EXPIRE).
This article introduces the planning, HTTPD installation / application module configuration, upgrade / maintenance of the WEB service from the simplified installation ==> Performance. Allows Apache and PHP, Resin's independent upgrades, completely without affecting each other.
Web Application Capacity Plan: WEB Services Plan and Some Simple Estimation Formulas for WEB Services Depending on Hardware Configuration and Web Applications; Apache Installation: Apache's Universal Simplified Installation Options for easy applications; modify hard_server_limit: vi /Path/to/apache_src/src/include/httpd.h#define hard_server_limit 2560 <=== Add a "0" Apache after the original HARD_SERVER_LIMIT 256: ./ Configure --prefix = / Home / Apache --Nable -Shared = max-enable-module = MOST Optional Application Module / Tool Installation: PHP RESIN MOD_GZIP MOD_EXPIRE and Modules between MOD_PHPs: ./ Configure --with-apxs = / Home / Apache / bin / apxs --enable-track-vars --with-mysqlmod_resin installation: ./ Configure --with-apxs = / home / apache / bin / apxs mod_gzip installation: / Home / Apache / bin / apxs -i -a -c MOD_GZIP.C Tools: Qiao Runter CRONOLOG installation: http://www.cronolog.org Upgrade / Maintenance: See how universal and modular installation processes how to simplify daily upgrade / maintenance; follow the above methods: System The role of administrators and application administrators can be clearly separated and independent of each other. System Installation: The system administrator's responsibility is to install a DSO mode Apache, then COLON, the application installation: The application administrator is responsible for the module required for the specific application, such as PHP RESIN, etc., and sets the httpd.conf Configuration. System Upgrade: System Administrator: Upgrade Operating System / Upgrade Apache App Upgrade: Application Administrator: Upgrade Application Module, PHP RESIN, etc.
Capacity plan for web applications
Apache is primarily a memory consumption type of service applications, my personal summary of the empirical formula: apache_max_process_with_good_perfermance <(total_hardware_memory / apache_memory_per_process) * 2apache_max_process = apache_max_process_with_good_perfermance * 1.5 Why is there a apache_max_process_with_good_perfermance and apache_max_process it? The reason is that the system can use more memory for a cache for the file system under low load, thereby further increasing the response speed of a single request. Under the high load, the single request response speed of the system will be a lot, and the system will cause system efficiency drastically due to the start of using the hard disk to do virtual memory switching space. In addition, the same service: 2G memory machine Apache_max_process is typically only 1.7 times that of 1G memory, because Apache itself will decline due to excessive process.
Example 1: A APACHE MOD_PHP server: A apache process generally requires 4M memory so on a 1G memory machine: apache_max_process_with_good_perferMance <(1G / 4M) * 2 = 500Apache_max_process = 500 * 1.5 = 750 So plan your application Try to run below 500 times to maintain a relatively high efficiency, and set the soft limit of Apache at 800.
Example 2: A Apache MOD_RESIN server: A Apache process generally requires 2M memory on a 2G memory machine: apache_max_process_with_good_perferMance <(2G / 2M) * 2 = 2000Apache_max_process = 2000 * 1.5 = 3000
The above estimates are estimated by small file services (a request is generally below 20K). For file download type sites, it may also be affected by other factors: such as bandwidth.
Apache installation process
The number of hard-limit hard_server_limit in the server: The maximum number of processes in the source code of Apache is 256, need to modify apache_1.3.xx / src / include / httpd.h # ifndef hard_server_limit # ifdef Win32 # define hard_server_limit 1024 # Elif Defined (NetWare) #define hard_server_limit 2048 # Else # define hard_server_limit 2560 <=== Add a "0" # endif # Endif
Explanation: Apache default maximum number of users is 256: This configuration is a very good default setting for server memory or 256M, but with the sharp decline of memory cost, the server memory configuration of large sites is generally better than At that time, it was a quantity level. So the hard limit of 256 processes is too wasteful for a 1G memory machine, and Apache's soft limit MAX_CLIENT is limited to hard_server_limit, so if the web server memory is greater than 256M, it should be increased to Apache's hard_server_limit. According to personal experience: 2560 It has been able to meet the capacity planning of most of the server that is less than 2G memory (see it later after planning of Apache's soft limit). Compilation of Apache: The following general compilation options can meet the installation of any module after any module ./configure --prefix = / another_driver / apache / --enable-shared = max-able-module = MOST, such as: ./ Configure --PREfix = / home / apache / --enable-shared = max --enable-module = MOST
Explanation: - prefix = / another_driver / apache /: It is recommended to install the Apache service on another drive device. The data is accessed, more important, greatly facilitating system upgrade, application backup and recovery process.
--Shared-module = max: Using a dynamic loading method to load a sub-module will bring 5% performance drop, but it is more important than what is convenient for the configuration: such as the module upgrade, system upgrade risk reduces, Installation process standardization, etc.
--Nable-module = MOST: MOST can be compiled with some uncommon module, such as the mod_expire told later is not in the default module of Apache.
If you don't want Build So, you can do this: ./ Configure / "- with-layout = apache" / "- prefix = / path / to / apache" / "- disable-module = access" / "- disable -Module = ActionS "/" - Disable-module = autoIndex "/" - disable-module = env "/" - disable-module = IMAP "/" - disable-module = negotiation "/" - disable -Module = STENVIF "/" - disable-module = status "/" - disable-module = userdir "/" - disable-module = cgi "/" - disable-module = include "/" - disable -Module = auth "/" - disable-module = asis "
However, the results will find that such compilation can only have a small increase in service performance (5%), but there is a flexibility of the system upgrade and module upgrade, whether it is a module or Apache itself, Apache and PHP must be Source adds together to recompile. Apache's default configuration file is generally relatively large: you can use the way to remove the annotation. Regenerate: Then enter the specific cultivation process allows you to customize you faster. Grep -v "#" httpd.conf.default> httpd.conf
The general project that needs to be modified has the following:
# 服务 服务 端, the default is 8080, it is recommended to adjust the entire Apache configuration to the port 8080 => 80 after adjusting the service port port 8080 => 80
# 服务 名: Default No servername name.example.com # Maximum service process: MaxClients 256 => 800 based on service capacity prediction
# 缺 启 启 服务号 启 后 号: When the service is relatively stable, you can setServers 5 => 200 according to the HTTPD number setting under the average load.
Don't modify: I have previously suggested modifications: minSpareServers 5 => 100maxSpareServers 10 => 200
But from my experience: The default is already very optimized, and the number of Apache has adjusted the sub-sharing process is still better.
Special modification: in Solaris or some more prone to memory leaks: maxrequestsperchild 0 => 3000
Application module and tool installation configuration:
Due to the dynamic load mode using the module, it is convenient to customize the Apache to you need by simple configuration adjustment: It is best to clear all the unusual modules (whether it is safe or efficient). For example: For static page servers: What other sub-modules are not loaded, adding a PHP module for PHP applications, and load the RESIN module on the Java application. Moreover, the plugging of various modules is very simple, so you can easily remove unwanted modules during the debugging process without recompilation.
In general, the modules may not be required include: #LoadModule env_module libexec / mod_env.so # LoadModule negotiation_module libexec / mod_negotiation.so # LoadModule status_module libexec / mod_status.so # server side include outdated #LoadModule includes_module libexec / mod_include.so # do not need all the files will not be listed #LoadModule autoindex_module libexec / mod_autoindex.so # default directory index files try not to use CGI: Apache has been the most safety place #LoadModule cgi_module libexec / mod_cgi.so # LoadModule asis_module libexec /mod_asis.so#LoadModule imap_module libexec / mod_imap.so # LoadModule action_module libexec / mod_actions.so # do not use secure authentication can greatly improve the speed of access #LoadModule access_module libexec / mod_access.so # LoadModule auth_module libexec / mod_auth.so # LoadModule setenvif_module libexec /mod_setenvif.so best retention are: # for custom log format LoadModule config_log_module libexec / mod_log_config.so # LoadModule mime_module libexec association for increased file application / mod_mime.so # for default index files: index.php, etc. LoadModule Dir_Module Libexec / MOD_DIR.SO
Useable available: # 比,,,
Common modules: The most commonly used possible is the front end of the PHP and Java application servers. In addition, from performance, using mod_gzip can reduce traffic, reduce the load for transmission, and mod_expires can reduce 10%. Request, let the duplicate user request results for the specified page requests in the local area, do not request a request to the server at all.
It is recommended to put all Module configurations to the configuration of the corresponding module inside:
PHP installation: / path / to / php_src / configure --with-apxs = / path / to / apache / bin / apxs --with-other-modules-you-nesed requires modification configuration: addtype application / x-httpd -php .php .php3 .any_file_in_php
RESIN installation setting: / path / to / resin / src / configure --with-apxs = / path / to / apache / bin / apxs Concrete Resin settings in another file: such as / home / resin / conf / resin.conf
Note: All .GIF files expires all files after 1 month after 1 day after expiration
MOD_GZIP installation: / pat / to / apache / bin / apxs -i -a -c mod_gzip.c
Configuration: MOD_GZIP MOD_PHPLOADMODULE GZIP_MODULE MODULES / MOD_GZIP.SO
... addmodule mod_gzip.c
...
MOD_GZIP and MOD_PHP: Do not let MOD_GZIP and MOD_PHP use the same temporary directory, PHP_SESSION storage directory can be set to session.save_path = / tmp / php_gzip to load after mod_caucho, otherwise MOD_GZIP does not load after mod_caucho, otherwise MOD_GZIP Enact ... othr modulesaddmodule mod_so.caddmodule mod_caucho.c # notice: mod_gzip must loading instim_cauchoaddmodule mod_gzip.caddmodule mod_expires.c ...
Configuration: mod_gzip resin
Customlog "| / usr / local / sbin / cronolog / home / apache / logs /% w / access_log" combined
The log will truncate and store it in the directory of the name of the name in the sky: such as: log / 1 is Monday, log / 5 is Friday, log / 0 is a daily log: 30 4 * * * / usr / bin / gzip -f / home / apache / logs / `date -d yesterday % W` / access_log log regular deletion: 30 5 * * * / usr / bin / find / home / apache / logs / Name Access_log.gz -mtime 3 | xargs -r / bin / rm -f
Upgrade maintenance:
Since the dynamic module load mode (DSO mode) is used to install Apache, Apache's HTTPD core service and application module is very flexible, it is recommended to put all independent modules in
Installation and maintenance process:
System Installation: System Administrator's duty is to install the system and a Apache installed in DSO mode, then Colon. Application installation: The application administrator is responsible for the module required for the specific application and sets httpd. System Upgrade: System Administrator: Upgrade System / Upgrade Apache App Upgrade: Apply Administrator: Upgrade Application Module: PHP Caucho and other System Backup / Recovery: If Apache is not on the default system disk, you only need to back up the Apache directory. After the hardware problem of the system partition, use the pre-prepared system colon, and then directly restore the physical disk where Apache is located.
System Administrator: Apache's Sector Installation Os Apache (Httpd Core Only) Application Administrator: Application Module Custom Pure Static Page Services Corephp Dynamic Page Core SO PHPJAVA Application Core SO Caucho SSL Application Example: www.example .comimage.example.combbs.example.commall.example.com
Example: Apache and PHP modules independently upgraded.
If Apache is installed in the following way: ./ Configure --prefix = / home / apache --enable-shared = max --Nable-module = MOST PHP is installed in the following way: ./ Configure --with-apxs = / HOME / APACHE / BIN / APXS --ENABLE-TRACK-VARS --With-mysql is still: ./ configure --prefix = / home / apache --enable-shared = max --enable -Module = MOST Makesu # / Home / Apache / Bin / Apachectl Stop # Make Install When upgrading PHP, it is still: ./ Configure --with-apxs = / home / apache / bin / apxs --enable-track-vars --with-mysqlmakesu # / home / apache / bin / apachectl stop # make install # / home / apache / bin / apachectl Start Tip:
After Apache installation, there is no but useful files in the root directory:
Favicon.ico: Favicon.ico is a 16x16 site icon file, if the browser finds this file, use this icon to replace the web icon of the browser in the address bar. Mainstream browsers such as IE6 and Mozilla support this feature. For example: http://www.chedong.com/favicon.ico robots.txt: The page of reptiles (Spider) websites used to tell the search engine can be indexed, those can't. For details, please refer to: http://www.robotstxt.org/wc/robots.html
Reference documentation:
Apachehttp://httpd.apache.org
Phphttp://www.php.net
Resinhttp://www.caucho.com
MOD_GZIPHTTP: //SourceForge.Net/Projects/mod-gzip/
Cronologyttp://www.cronolog.org
MOD_EXPIRES