APACHE installation notes

Source: Internet
Author: User
Abstract: WEB application capacity planning: WEB service planning and some simple estimation formulas are carried out based on hardware configuration and WEB application characteristics. APACHE installation process: General and simplified installation options of apache, facilitates modular configuration of future applications; modifies HARD_SERVER_LIMIT: vipathtoapache_srcsrcincludehttpd.h # defineHARD_SE Apache

Abstract:
  1. WEB application capacity planning: WEB service planning and some simple estimation formulas based on hardware configuration and WEB application features;
  2. APACHE installation process: Common simple 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
  3. Optional Application Module/tool installation: Php resin mod_gzip mod_expire and the cooperation between various modules;
    PHP installation:
    /Path/to/php_src/configure -- with-apxs =/path/to/apache/bin/apxs -- 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
  4. Upgrade/maintenance: See how the general and modular installation process simplifies the daily upgrade/maintenance work;
    According to the above method, 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/-- shared-module = 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 dynamic loading mode is used, you can easily adjust the configuration to customize APACHE: remove all modules that are not commonly used

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.

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:

CauchoConfigFile/path/to/apache/conf/resin. conf

Installation configuration of mod_expires:

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"

Mod_gzip installation:
/Path/to/apache/bin/apxs-I-a-c mod_gzip.c

Configuration of mod_gzip and PHP together

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

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
...


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'

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

CONFIGURATIONS ..

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 installation of APACHE OS + APACHE (httpd core only)
Application Administrator: Application Module customization   + So
+ Php
+ So
+ Caucho
+ Ssl
Applicable applications: 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

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.