Install Apache httpd in Linux
Httpd is the main program of the Apache Hypertext Transfer Protocol (HTTP) server. It is designed as an independent background process that establishes a pool of sub-processes or threads that process requests to provide external services. Httpd supports HOST, reverse proxy, Server Load balancer, path alias, user authentication, basic, and third-party Modules Based on Virtual Hosts and HOST, IP, and PORT. This article describes how to install httpd in Linux and its basic usage.
1. httpd Installation
Demo environment and version # cat/etc/issue CentOS release 6.5 (Final) Kernel \ r on an \ m # uname-r 2.6.32-431. el6.x86 _ 64 check whether httpd is installed # rpm-qa httpd use yum to list httpd installation files. Here, the local yum source # yum list | grep httpd. x86_64 2.2.15-29. el6.centos local_server httpd-devel.i686 2.2.15-29. el6.centos local_server httpd-devel.x86_64 2.2.15-29. el6.centos local_server httpd-manual.noarch 2.2.15-29. el6.centos local_server httpd-tools.x86_64 2.2.15-29. el6.centos local_server installation and verification httpd # yum-y install httpd # rpm-qa | grep httpd httpd-tools-2.2.15-29.el6.centos.x86_64 httpd-2.2.15-29.el6.centos.x86_64 using rpm to find configuration files # rpm-qc httpd commonly used configuration files: /etc/httpd/conf. d /*. conf ### auxiliary configuration file/etc/httpd/conf/httpd. conf ### main configuration file/etc/sysconfig/httpd ### use rpm to view the installation location and generated binary file # rpm-ql httpd main program: /usr/sbin/httpd MPM mode default/usr/sbin/httpd. event/usr/sbin/httpd. worker uses rpm to view the Help file of the package # rpm-qd httpd Startup Script:/etc/rc. d/init. d/httpd log file directory:/var/log/httpd access_log: access log error_log: Error log site document directory: (site root directory)/var/www/htmlhttpd working directory: /var/www
Ii. httpd Working Mode
1. MPM: Multipath Processing Module (Multi-Channel Processing Module) prefork: multi-process model. Each process responds to a request. The stability is good, but the concurrency capability is limited. Multiple idle processes are generated in advance; since prefork is called by the select () system, the maximum concurrency cannot exceed 1024. worker: multi-process model. Each process can generate multiple threads and each thread responds to one request; multiple Idle threads are pre-generated; event: a process directly responds to n requests; multiple processes can be started at the same time; httpd-2.2: test use; ### Author: Leshami httpd-2.4: it can be used in production. ### Blog: http://blog.csdn.net/leshami2.pdf switch several workways to the prefork mode # service httpd start Starting httpd: [OK] # ps-ef | grep httpd | grep- V grep ### a master process generates eight idle processes: root 6413 1 0? 00:00:00/usr/sbin/httpd apache 6416 6413 0? 00:00:00/usr/sbin/httpd apache 6417 6413 0? 00:00:00/usr/sbin/httpd apache 6418 6413 0? 00:00:00/usr/sbin/httpd apache 6419 6413 0? 00:00:00/usr/sbin/httpd apache 6420 6413 0? 00:00:00/usr/sbin/httpd apache 6421 6413 0? 00:00:00/usr/sbin/httpd apache 6422 6413 0? 00:00:00/usr/sbin/httpd apache 6423 6413 0? 00:00:00/usr/sbin/httpd # ss-tulpn | grep httpd tcp LISTEN 0 128: 80 ::: * users :( ("httpd", 6413,4 ), ("httpd", 6416,4), ("httpd", 6417,4), ("httpd", 6418,4), ("httpd", 6419,4), ("httpd", 6420,4 ), ("httpd", 642), ("httpd", 642), ("httpd", 6423,4) # netstat-nltp | grep 80 tcp 0 ::: 80 ::: * LISTEN 6413/httpd worker working method # cat/etc/sysconfig/httpd | grep-v ^ # HTTPD =/usr/sbin/httpd. worker # service httpd restart Stopping httpd: [OK] Starting httpd: [OK] [root @ orasrv1 ~] # Ps-ef | grep httpd | grep-v grep root 2261 1 0? 00:00:00/usr/sbin/httpd. worker apache 2264 2261 0? 00:00:00/usr/sbin/httpd. worker apache 2265 2261 0? 00:00:00/usr/sbin/httpd. worker apache 2266 2261 0? 00:00:00/usr/sbin/httpd. workerevent method of work Note, although 2.2 can be set to httpd. event is not recommended in the production environment. # cat/etc/sysconfig/httpd | grep-v ^ # HTTPD =/usr/sbin/httpd. event [root @ orasrv1 ~] # Service httpd restart Stopping httpd: [OK] Starting httpd: [OK] [root @ orasrv1 ~] # Ps-ef | grep httpd | grep-v grep root 2402 1 0? 00:00:00/usr/sbin/httpd. event apache 2405 2402 0? 00:00:00/usr/sbin/httpd. event apache 2406 2402 0? 00:00:00/usr/sbin/httpd. event apache 2407 2402 0? 00:00:00/usr/sbin/httpd. event
Iii. httpd Modularization
Highly modular core + modules, DSO: Dynamic Shared Object Module Directory:/etc/httpd/modules: view httpd-M in the/usr/lib64/httpd/modules module of the symbolic link file ### view all httpd modules of the current httpd process. event-M ### view httpd of all modules in worker working mode. worker-M ### httpd for all modules in event Mode. worker-l ### example of viewing the core module in event Mode # httpd-M Loaded Modules: core_module (static) mpm_prefork_module (static) http_module (static) so_module (static) auth_basic_module (shared ).............. # httpd. event-l Compiled in modules: core. c event. dynamic Loading and unloading of c http_core.c mod_so.c Module # cp/etc/httpd/conf/httpd. conf/etc/httpd/conf/httpd. conf. bak # cat/etc/httpd/conf/httpd. conf | grep authn_alias_module LoadModule authn_alias_module modules/mod_authn_alias.so # vi/etc/httpd/conf/httpd. conf ### comment out the mod_authn_alias.so Module # cat/etc/httpd/conf/httpd. conf | grep authn_alias_module # LoadModule authn_alias_module modules/mod_authn_alias.so # service httpd restart # httpd-M ### use this method to check whether the module is loaded or uninstalled.
4. Verify the httpd service
# echo "
orasrv1.xlk.com
" >/var/www/html/index.html # curl http://192.168.21.10
orasrv1.xlk.com