From the perspective of simplified installation ==> Performance Tuning ==> convenient maintenance, we will discuss the WEB service planning ==> HTTPD installation/application module configuration ==> upgrade/maintenance processes.
The upgrade of APACHE and application modules such as php resin does not affect each other.
Abstract:
WEB application capacity planning: WEB service planning and some simple estimation formulas based on hardware configuration and WEB application characteristics;
APACHE installation process: common and simplified Installation Options of apache facilitate modular configuration of future applications;
Modify HARD_SERVER_LIMIT:
Vi/path/to/apache_src/src/include/httpd. h
# Define HARD_SERVER_LIMIT 2560 <= Add "0" to the original HARD_SERVER_LIMIT 256"
Apache Compilation:
/Path/to/apache_src/configure -- prefix =/another_driver/apache -- enable-shared = max -- enable-module = most
Installation of optional application modules/tools: php resin mod_gzip mod_expire and cooperation between various modules;
PHP installation:
/Path/to/php_src/configure -- with-apxs =/path/to/apache/bin/apxs -- enable-track-vars -- with-other-modules-you-need
Mod_resin installation:
/Path/to/resin/src/configure -- with-apxs =/path/to/apache/bin/apxs
Mod_gzip installation:
/Path/to/apache/bin/apxs-I-a-c mod_gzip.c
Tool: cronolog installation: http://www.cronolog.org
Upgrade/maintenance: see how the General and modular installation process simplifies routine upgrade/maintenance work;
Follow these steps: the roles and responsibilities of system administrators and application administrators can be clearly separated and independent from each other.
System installation: The System Administrator is responsible for installing the system => installing an APACHE server that can adapt to any situation, then COLON,
Application installation: The application Administrator is responsible for the modules required by the specific application and sets HTTPD.
System Upgrade: System Administrator: upgrade the system/Upgrade APACHE
Application upgrade: System Administrator: Upgrade application module
Specific instructions:
WEB application capacity planning
APACHE is mainly a memory-consuming service application. I personally sum up the following formula:
Apache_max_process_with_good_perfermance <(total_hardware_memory/apache_memory_per_process) * 2
Apache_max_process = apache_max_process_with_good_perfermance * 1.5
Why is there an apache_max_process_with_good_perfermance and apache_max_process? The reason is that at a low load, the system can use more memory for the file system cache to further improve the response speed of a single request. Under high load, the system's single request response speed will be much slower, and beyond the apache_max_process, the system will crash due to the use of the hard disk for Virtual Memory swap space. In addition, the same service: apache_max_process of 2 GB memory machines is generally set to 1.7 times of 1 GB memory, because APACHE itself will cause performance degradation due to managing more processes.
Example 1:
An apache + mod_php server: A apache process generally requires 4 MB of memory
Therefore, on a machine with 1 GB memory: apache_max_process_with_good_perfermance <(1g/4 m) * 2 = 500
Apache_max_process = 500*1.5 = 750
Therefore, plan your application to make the service run below 500 APACHE as much as possible, and set the APACHE soft limit to 800.
Example 2:
An apache + mod_resin server: an apache process generally requires 2 MB of memory.
On a machine with 2 GB memory: apache_max_process_with_good_perfermance <(2g/2 m) * 2 = 2000
Therefore, apache_max_process = 2000*1.5 = 3000
The above estimates are based on the small file service (a request is generally smaller than 20 KB ). File Download websites may also be affected by other factors, such as bandwidth.
APACHE installation process
Modify the maximum number of servers HARD_SERVER_LIMIT:
In UNIX operating systems such as FREEBSD and LINUX, the default maximum number of APACHE processes is 256. You 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 "0" to the original HARD_SERVER_LIMIT 256"
# Endif
# Endif
Explanation:
The maximum number of APACHE users by default is 256: This configuration is a very good default for the era of server memory or about MB, but with the sharp decline in memory costs, the server memory configuration for large sites is generally more than an order of magnitude higher than that at the time. Therefore, the hard limit of 256 processes is too wasteful for a machine with 1 GB of memory, and the soft upper limit of APACHE max_client is limited by HARD_SERVER_LIMIT. Therefore, if the memory of the WEB server is larger than 256 MB, you should increase APACHE's HARD_SERVER_LIMIT. According to my personal experience: 2560 can already meet the capacity planning of most servers with less than 2 GB of memory (for details about APACHE soft-cap planning, refer to later ).
APACHE Compilation: General Compilation options can standardize the installation process
./Configure -- prefix =/another_driver/apache/-- enable-shared = max -- enable-module = most
Explanation:
-- Prefix =/another_driver/apache/: Hard Disks are generally used for the lowest service life of a system. Therefore, completely separating service data from the system not only improves data access speed, more importantly, it greatly facilitates system upgrades, backup, and recovery.
-- Shared-module = max: using the dynamic loading method will bring about a 5% performance reduction, but it is nothing more than the benefits: for example, the module upgrade is convenient and the risk of system upgrade is reduced, installation process standardization
-- Enable-module = most: most can be used to compile unused modules. For example, the mod_expire mentioned later is not in the default common modules of apache.
If you do not want to build so, you can also 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 = setenvif "\
"-- Disable-module = status "\
"-- Disable-module = userdir "\
"-- Disable-module = cgi "\
"-- Disable-module = include "\
"-- Disable-module = auth "\
"-- Disable-module = asis"
However, the results will show that such compilation can only slightly improve the service performance (about 5%), but it will lose the flexibility of system upgrade and module upgrade in the future, all sources must be combined for both modules and APACHE upgrades.
Apache's default configuration file is generally relatively large: We can use the method of removing comments to streamline it: and then enter the specific cultivation process to allow you to quickly customize what you need.
Grep-v "#" httpd. conf. default> httpd. conf
The following general projects need to be modified:
# Service port. The default value is 8080. We recommend that you adjust the configuration of APACHE before changing the service port to the official service port.
Port 8080 => 80
# Server name: No by default
ServerName name.example.com
# Maximum number of service processes: Set Based on Service Capacity Forecast
MaxClients 256 => 800
# Number of service processes after the service is started by default: after the service is stable, you can set the number of httpd processes based on the average load.
StartServers 5 => 200
Do not modify:
Previously, it was suggested to modify:
MinSpareServers 5 = & gt; 100
MaxSpareServers 10 = & gt; 200
However, in my experience, the default value is already very optimized, and it is better to let APACHE adjust the number of processes by itself.
Special modification:
On solaris or some applications that are prone to memory leakage:
MaxRequestsPerChild 0 => 3000
Installation and configuration of application modules and tools:
Because the module dynamic loading mode is used, you can easily customize APACHE into what you need through simple configuration adjustment: it is best to clear all the modules that are not commonly used (whether in security or efficiency ).
For example, for Static Page servers: No module is loaded. For PHP applications, the PHP module is added. For JAVA applications, the RESIN module is loaded. In addition, the plug-in and plug-in of various modules are very simple.
Generally, the following modules are not required:
# LoadModule env_module libexec/mod_env.so
# LoadModule negotiation_module libexec/mod_negotiation.so
# LoadModule status_module libexec/mod_status.so
# Server side include is out of date
# LoadModule includes_module libexec/mod_include.so
# You do not need to list all files in the directory without the default index file
# LoadModule autoindex_module libexec/mod_autoindex.so
# Do not use CGI as much as possible: always the most critical issue to APACHE Security
# 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
# Access speed can be greatly improved without security verification
# LoadModule access_module libexec/mod_access.so
# LoadModule auth_module libexec/mod_auth.so
# LoadModule setenvif_module libexec/mod_setenvif.so
It is best to retain the following:
# Used to customize the log format
LoadModule config_log_module libexec/mod_log_config.so
# Used to increase the association of file applications
LoadModule mime_module libexec/mod_mime.so
# Used for default index files: index. php, etc.
LoadModule dir_module libexec/mod_dir.so
Available and optional include:
# For example, you need ~ /Username/to debug php
LoadModule userdir_module libexec/mod_userdir.so
# For example, You need to redirect the previous URL or use CGI script-alias
LoadModule alias_module libexec/mod_alias.so
Common modules:
The most commonly used wrapper is for php and java web applications. In addition, in terms of performance, mod_gzip can reduce the traffic by about 40%, thus reducing the load of machines for transmission, mod_expires can reduce the number of duplicate requests by about 10%, so that duplicate user requests are cached locally and no requests are sent to the server.
We recommend that you put the configurations of all modules in
PHP installation:
/Path/to/php_src/configure -- with-apxs =/path/to/apache/bin/apxs -- with-other-modules-you-need
Configuration to be modified:
AddType application/x-httpd-php. php. php3. any_file_in_php
Resin installation settings:
/Path/to/resin/src/configure -- with-apxs =/path/to/apache/bin/apxs
Generally, the specific resin settings are placed in another file:
<IfModule mod_caucho.c>
CauchoConfigFile/path/to/apache/conf/resin. conf
</IfModule>
Installation configuration of mod_expires:
<IfModule mod_expires.c>
ExpiresActive on
All. GIF files expire after 1 month
ExpiresByType image/gif "access plus 1 month"
# All files expire after 1 day by default
ExpiresDefault "now plus 1 day"
</IfModule>
Mod_gzip installation:
/Path/to/apache/bin/apxs-I-a-c mod_gzip.c
Configuration of mod_gzip and PHP together
<IfModule mod_gzip.c>
Mod_gzip_on Yes
Mod_gzip_minimum_file_size 1000
Mod_gzip_maximum_file_size 300000
Mod_gzip_item_include file \. htm $
Mod_gzip_item_include file \. html $
Mod_gzip_item_include file \. php $
Mod_gzip_item_include file \. php3 $
Mod_gzip_item_include mime text /.*
Mod_gzip_item_include mime httpd/unix-directory
# Do not use the same temporary directory for mod_gzip and php sessions: php_session needs to be set through php. ini session. save_path =/tmp/php_sess
Mod_gzip_temp_dir/tmp/mod_gzip
Mod_gzip_dechunk Yes
Mod_gzip_keep_workfiles No
</IfModule>
Mod_gzip and mod_php: Do not use the same temporary directory for mod_gzip and mod_php;
Mod_gzip and RESIN: Make mod_gzip LOAD after mod_caucho; otherwise, mod_gzip does not work.
... Othr modules
AddModule mod_so.c
AddModule mod_caucho.c
# Notice: mod_gzip must load after mod_caucho
AddModule mod_gzip.c
AddModule mod_expires.c
...
<IFModule mod_gzip.c>
Mod_gzip_on Yes
Mod_gzip_dechunk yes
Mod_gzip_keep_workfiles No
Mod_gzip_minimum_file_size 3000
Mod_gzip_maximum_file_size 300000
Mod_gzip_item_include file \. html $
Mod_gzip_item_include mime text /.*
Mod_gzip_item_include mime httpd/unix-directory
Mod_gzip_item_include handler 'caucho-request'
</IFModule>
Installation and Setup of cronolog: cronolog can store logs in a neat manner by day
By default, It is compiled and installed under/usr/local/bin/. You only need to change the configuration:
CustomLog "|/usr/local/sbin/cronolog/path/to/apache/logs/% w/access_log" combined
Logs are truncated by day and stored in the directory named weekday. For example, log/1 indicates Monday, log/5 indicates Friday, and log/0 indicates Sunday.
Upgrade and maintenance:
Because APACHE is installed in the standard DSO mode, the HTTPD core service of APACHE is flexible with the application modules and application modules. We recommend that you set the configurations of all independent modules
<IfModule mod_name>
CONFIGURATIONS ..
</IfModule>
In this way, it is very easy to adjust the function by shielding a module: for example:
# AddModule mod_gzip.c
Mod_gzip is blocked, and other modules do not have any influence.
Installation and maintenance process:
System installation: The System Administrator is responsible for installing the system and an APACHE that can adapt to any situation, and then COLON.
Application installation: The application Administrator is responsible for the modules required by the specific application and sets HTTPD.
System Upgrade: System Administrator: upgrade the system/Upgrade APACHE
Application upgrade: Application administrator: Upgrade application module
System Backup/recovery: If APACHE is not on the default system disk, you only need to back up the APACHE directory. In case of hardware problems in the system partition, use the pre-prepared system COLON, restore the physical disk where APACHE is located.
System Administrator: the simplest way to install apache OS + APACHE (httpd core only)
Application administrator: application module customization + so
+ Php
+ So
+ Caucho
+ Ssl
Application: Pure Static Page service:
Image.example.com
Www.example.com bbs.example.com mall.example.com
Reference:
Apache
Http://httpd.apache.org
Php
Http://www.php.net
Resin
Http://www.caucho.com
Mod_gzip
Http://www.remotecommunications.com/apache/mod_gzip/
Cronolog
Http://www.cronolog.org
Mod_expires
Http://httpd.apache.org/docs/mod/mod_expires.html