Linux Service Installation-Web service (Apache)

Source: Internet
Author: User
Tags fully qualified domain name

Apache Web server is currently the most widely used Linux system to handle static Web pages of free Web servers.


In CentOS 6.5, the Apache Web server is installed by default.


1 Installing Apache Services


See if the HTTPD service is installed


[Email protected] ~]# Rpm-qa|grep httpd
httpd-tools-2.2.15-39.el6.centos.i686
httpd-devel-2.2.15-39.el6.centos.i686
Httpd-manual-2.2.15-39.el6.centos.noarch
httpd-2.2.15-39.el6.centos.i686

If not installed, you can use Yum to install


[email protected] ~]# Yum install-y httpd-*


Configuration directory structure for HTTPD


[Email protected] ~]# tree/etc/httpd/
/etc/httpd/
├──conf
│├──httpd.conf (the most important configuration file)
│└──magic
├──CONF.D (Storage module configuration file)
│├──manual.conf
│├──mod_dnssd.conf
│├──readme
│└──welcome.conf
├──logs. /.. /VAR/LOG/HTTPD (storing log information)
├──modules. /.. /usr/lib/httpd/modules (Storage module)
└──run. /.. /VAR/RUN/HTTPD (For information about the process ID of the master service)


Site root directory structure


[Email protected] ~]# tree-d/var/www/
/var/www/
├──cgi-bin
├──error
│└──include
├──html (Web root directory)
├──icons
│└──small
└──manual
├──developer
├──faq
├──howto
├──images
├──misc
├──mod
├──platform
├──programs
├──rewrite
├──ssl
├──style
│├──css
│├──lang
│├──latex
│└──xsl
│└──util
└──vhosts

Directories


Apache Startup user


Once the Apache installation is complete, a user named Apache will be created. This user is used to launch Apache-related subprocess.

[Email protected] ~]# CAT/ETC/PASSWD | grep Apache
Apache:x:48:48:apache:/var/www:/sbin/nologin


2 Apache Service Management


[[Email protected] ~]# service httpd
USAGE:HTTPD {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help| Configtest}


Service Common options


Start: Start the service

STOP: Stop service

Restart: Restart Service

Graceful: Restart the service after all user requests have been processed. (Do not want users to feel a sudden interruption of the site)

Graceful-stop (Apache Exclusive): Shut down the service after all user requests have been processed


Launch Apache Service


[[email protected] ~]#/etc/init.d/httpd start
Starting httpd:httpd:Could not reliably determine the server ' s fully qualified domain name, using Localhost.localdomain For ServerName
[OK]

Can be set to boot if necessary

[Email protected] ~]# chkconfig--level httpd on


After launch, enter http://localhost:80/in the browser and the first page of Apache will be displayed.


3 Apache process Management


Apache listens to TCP protocol port 80 by default;

The Apache service initiates a master process (control process) and multiple child processes by default.


View Apache-related processes

[Email protected] ~]# PS aux|grep httpd
Root 5827 0.0 0.6 11780 3428? Ss 13:16 0:00/usr/sbin/httpd
Apache 5830 0.0 0.5 11912 2816? S 13:16 0:00/usr/sbin/httpd
Apache 5831 0.0 0.5 11912 2876? S 13:16 0:00/usr/sbin/httpd
Apache 5832 0.0 0.5 11912 2832? S 13:16 0:00/usr/sbin/httpd
Apache 5833 0.0 0.5 11912 2816? S 13:16 0:00/usr/sbin/httpd
Apache 5834 0.0 0.5 11912 2832? S 13:16 0:00/usr/sbin/httpd
Apache 5835 0.0 0.4 11780 2164? S 13:16 0:00/usr/sbin/httpd
Apache 5836 0.0 0.5 11912 2832? S 13:16 0:00/usr/sbin/httpd
Apache 5837 0.0 0.4 11780 2164? S 13:16 0:00/usr/sbin/httpd


Where the master process runs as root, the child processes run as Apache, and the process ID of the main process is saved in the/etc/httpd/run/httpd.pid file.


View the ports used


[Email protected] ~]# Netstat-tupln|grep httpd
TCP 0 0::: +:::* LISTEN 5827/httpd


4 Apache DSO


Apache is a modular design service, the core only contains the main functions, the extension function through the module to achieve. Different modules can be statically compiled into the program, or can be dynamically loaded.


The dynamic loading of the module is achieved through the DSO (Share Object).


View Modules

[Email protected] ~]# httpd-m
Httpd:could not reliably determine the server ' s fully qualified domain name, using Localhost.localdomain for ServerName
Loaded Modules:
Core_module (Static)
Mpm_prefork_module (Static)//Process Management module
Http_module (Static)
So_module (static)//Load dynamic module
Auth_basic_module (Shared)
Auth_digest_module (Shared)
Authn_file_module (Shared)
Authn_alias_module (Shared)
Authn_anon_module (Shared)
Authn_dbm_module (Shared)
Authn_default_module (Shared)
Authz_host_module (Shared)
Authz_user_module (Shared)
Authz_owner_module (Shared)
Authz_groupfile_module (Shared)
Authz_dbm_module (Shared)
Authz_default_module (Shared)
Ldap_module (Shared)
Authnz_ldap_module (Shared)
Include_module (Shared)
Log_config_module (Shared)
Logio_module (Shared)
Env_module (Shared)
Ext_filter_module (Shared)
Mime_magic_module (Shared)
Expires_module (Shared)
Deflate_module (Shared)
Headers_module (Shared)
Usertrack_module (Shared)
Setenvif_module (Shared)
Mime_module (Shared)
Dav_module (Shared)
Status_module (Shared)
Autoindex_module (Shared)
Info_module (Shared)
Dav_fs_module (Shared)
Vhost_alias_module (Shared)
Negotiation_module (Shared)
Dir_module (Shared)
Actions_module (Shared)
Speling_module (Shared)
Userdir_module (Shared)
Alias_module (Shared)
Substitute_module (Shared)
Rewrite_module (Shared)
Proxy_module (Shared)
Proxy_balancer_module (Shared)
Proxy_ftp_module (Shared)
Proxy_http_module (Shared)
Proxy_ajp_module (Shared)
Proxy_connect_module (Shared)
Cache_module (Shared)
Suexec_module (Shared)
Disk_cache_module (Shared)
Cgi_module (Shared)
Version_module (Shared)
Dnssd_module (Shared)
Syntax OK


To view a module that is statically compiled into a program


[Email protected] ~]# httpd-l
Compiled in Modules:
Core.c
Prefork.c
Http_core.c
Mod_so.c


5 Apache MPM (Multi Process Modules)


MPM is mainly responsible for the implementation of network monitoring, request processing functions, MPM have a variety of, the purpose is to achieve the optimal performance and stability in different platform environment.

Platform
Mpm
Windows
Mpm_winnt
Linux
Prefork, worker

Prefork A non-threaded, pre-built process Mpm,prefork pre-launches a number of child processes, each of which can only process one request at a time and dynamically generate more child processes based on the number of concurrent requests.


Worker is a multithreaded, multi-process MPM, each process can generate multiple threads, each processing a request.


Prefork consumes more memory, is faster than a worker, and does not have to worry about thread safety, and the worker needs to consider thread safety issues.


View MPM used by the current service


[Email protected] ~]# httpd-v
Server version:apache/2.2.15 (Unix)
Server built:oct 16 2014 14:45:47
Server ' s Module Magic number:20051115:25
Server loaded:apr 1.3.9, Apr-util 1.3.9
Compiled using:apr 1.3.9, Apr-util 1.3.9
Architecture:32-bit
Server Mpm:prefork
Threaded:no
Forked:yes (variable process count)
Server compiled with ....
-D apache_mpm_dir= "Server/mpm/prefork"
-D Apr_has_sendfile
-D Apr_has_mmap
-D Apr_have_ipv6 (ipv4-mapped addresses enabled)
-D Apr_use_sysvsem_serialize
-D Apr_use_pthread_serialize
-D single_listen_unserialized_accept
-D Apr_has_other_child
-D Ap_have_reliable_piped_logs
-D dynamic_module_limit=128
-D httpd_root= "/ETC/HTTPD"
-D suexec_bin= "/usr/sbin/suexec"
-D default_pidlog= "Run/httpd.pid"
-D default_scoreboard= "Logs/apache_runtime_status"
-D default_lockfile= "Logs/accept.lock"
-D default_errorlog= "Logs/error_log"
-D ap_types_config_file= "Conf/mime.types"
-D server_config_file= "conf/httpd.conf"


Stress test for Prefork


View current Apache Current process:

[[email protected] ~]# watch-n 1 ' ps aux|grep httpd '


Use Apache bench for concurrent access

[Email protected] ~]# ab-c 32-n 30000 http://localhost/
This is apachebench, Version 2.3 < $Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus technology LTD, http://www.zeustech.net/
Licensed to the Apache software Foundation, http://www.apache.org/

Benchmarking localhost (Be patient)
Completed requests
Completed 6000 requests
Completed 9000 requests
Completed 12000 requests
Completed 15000 Requests
Completed 18000 requests
Completed 21000 requests
Completed 24000 requests
Completed 27000 requests
Completed 30000 requests
Finished 30000 requests


Server software:apache/2.2.15
Server Hostname:localhost
Server port:80

Document Path:/
Document length:4954 bytes

Concurrency level:32
Time taken for tests:13.860 seconds
Complete requests:30000
Failed requests:0
Write errors:0
Non-2xx responses:30014
Total transferred:154632128 bytes
HTML transferred:148689356 bytes
Requests per second:2164.48 [#/sec] (mean)
Time per request:14.784 [MS] (mean)
Time per request:0.462 [MS] (mean, across all concurrent requests)
Transfer rate:10895.13 [Kbytes/sec] Received

Connection Times (MS)
Min MEAN[+/-SD] Median max
Connect:2 7 3.2 6 93
Processing:4 8 2.9 7 91
Waiting:0 7 2.7 6 90
Total:9 15 4.9 13 120

Percentage of the requests served within a certain time (MS)
50% 13
66% 15
75% 16
80% 17
90% 19
95% 22
98% 27
99% 30
100% (Longest request)

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/4D/A2/wKiom1RV0rzSL9LuAALcfHfp69Q599.jpg "style=" float: none; "title=" View Apache usage progress. PNG "alt=" Wkiom1rv0rzsl9luaalcfhfp69q599.jpg "/>

Before sending a request


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/4D/A2/wKioL1RV0xyDOlndAARhzO2UBaE847.jpg "style=" float: none; "title=" View Apache usage process Scenario 2. PNG "alt=" Wkiol1rv0xydolndaarhzo2ubae847.jpg "/>

After sending the request, you can see that the number of child processes is several times higher (the child process grows by 2).


Prefork can be configured in/ect/httpd/conf/httpd.conf (you must observe the memory usage of each child process to set the appropriate parameters)


##
# # Server-pool Size Regulation (MPM specific)
##

# prefork MPM
# Startservers:number of server processes to start
# minspareservers:minimum number of server processes which is kept spare
# maxspareservers:maximum number of server processes which is kept spare
# Serverlimit:maximum value for maxclients for the lifetime of the server
# maxclients:maximum number of server processes allowed to start
# maxrequestsperchild:maximum number of requests a server process serves
<ifmodule prefork.c>
Startservers 8
Minspareservers 5
Maxspareservers 20
Serverlimit 256
MaxClients 256
Maxrequestsperchild 4000
</IfModule>

maxclients<=serverlimit;

When the process processes a request that exceeds maxrequestsperchild, the process is killed and a new process is generated.

Maxspareservers: The maximum number of idle processes, which, after the stress test, should be a sub-process of 20 for the httpd.


Observe the memory usage of each child process:

[Email protected] ~]# top-u Apache
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/4D/A3/wKiom1RV19PwXtfSAAUNjmjMWPw327.jpg "title=" View Apache usage of process memory usage. PNG "alt=" Wkiom1rv19pwxtfsaaunjmjmwpw327.jpg "/>


6 Apache master configuration file


Master configuration file in/etc/httpd/conf/httpd.conf


# The configuration directives is grouped into three basic sections:
# 1. Directives that control the operation of the Apache server process as a
# Whole (the ' Global Environment ').
# 2. Directives that define the parameters of the ' main ' or ' default ' server,
# which responds to requests this aren ' t handled by a virtual host.
# These directives also provide default values for the settings
# of all virtual hosts.
# 3. Settings for virtual hosts, which allow WEB requests to being sent to
# different IP addresses or hostnames and has them handled by the
# same Apache server process.


Linux Service Installation-Web service (Apache)

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.