Apache learning notes

zhaozj2021-02-16  65

Keywords: apache install php resin mod_gzip mod_expire Webalizer Cronolog

abstract:

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 load (DSO) mode, any sub-application module can make a streamlined flexible configuration by simple modification of the configuration file. The installation process can begin with a simple static HTML service, a module's 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: Modify the APXS path in Makefile: then make make install tool: log Round Tool Cronolog Setting: http://www.cronolog.org Upgrade / Maintenance: See how universal and modular installation processes daily upgrade / maintenance; follow the above methods: System administrators and application administrators The responsibilities can be clearly separated, 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 number of service processes: Set 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's configuration to the configuration inside the corresponding module:

Some_module config

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

The specific RESIN settings are placed in another file: such as /Home/Resin/conf/RESIN.CONF

Cauchoconfigfile /Path/to/apache/conf/resin.conf

MOD_EXPIRES installation configuration:

Expiresactive OnexpiresBytype Image / GIF "Access Plus 1 Month"

ExpiresBytype text / CSS "now plus 1 Month"

ExpiresDefault "now plus 1 day"

Note: All .GIF files expires all files after 1 month after 1 day after expiration

MOD_GZIP installation http://www.chedong.com/tech/compress.html

Round feed of logs: Cronolog installation and setting

Cronolog can be very neatly to store the log in the default compilation to / usr / local / bin / BIN / BIN / BIN / BIN / BIN / BIN / BIN.

Customlog "| / usr / local / sbin / cronolog / home / apache / logs /% w / access_log" combined

The log will truncate and store it under the directory of the name of the name in the week: such as: log / 1 is Monday, log / 5 is Friday, log / 0 is Sunday

Compress daily logs with gzip: 30 4 * * * / usr / bin / gzip -f / home / apache / logs / `date -d yesterday % w` / access_log

Regular deletion of the log: 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 installed, Apache, Apache's HTTPD core service and application module are very flexible, it is recommended to put all independent modules all in

Configurations ..

In this way, this configuration is very easy to adjust to a module: such as: #addmodule mod_gzip.c blocks MOD_GZIP, and other modules do not have any effect.

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.com mall.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 the php separately, 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

Web acceleration based on inverting agent: Squid and MOD_PROXY can implement reverse phase agent acceleration. Based on cached agent acceleration, the speed will have an order of magnitude.

hint:

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 the reptile program (Spider) website for telling the search engine can be indexed, those can't. For details, please refer to: http://www.robotstxt.org/wc/robots.html Reference document:

Apache project http://httpd.apache.org

Phphttp://www.php.net

Resinhttp://www.caucho.com

MOD_GZIPHTTP: //SourceForge.Net/Projects/mod-gzip/

Cronologyttp://www.cronolog.org

MOD_EXPIRESHTTP: //Httpd.Apache.org/docs/mod/mod_expires.html

CMS design for search engines: http://www.chedong.com/tech/cms.html

Original source: http://www.chedong.com/tech/apache_install.html

转载请注明原文地址:https://www.9cbs.com/read-19120.html

New Post(0)